Single space when cut-and-pasted to text editor

This forum is for all Flare issues related to styles, stylesheets and XML.
Post Reply
TomTatham
Jr. Propeller Head
Posts: 9
Joined: Sat Jul 21, 2007 12:28 pm

Single space when cut-and-pasted to text editor

Post by TomTatham »

I would appreciate help on figuring out how to do something seemingly simple. I am creating HTMLHelp and want to embed code samples in my topics and I want the code samples to be single spaced when copied from the help file into a text editor. The problem I am having is that an empty LF/CR is inserted after each line when I cut-and-paste into the text editor. I have been unable to create a paragraph style that achieves this. Here is an example of what I would like to have cut and pasted into a text editor:

Begin
A:=1;
B:2;
End;

Any help would be appreciated!
LTinker68
Master Propellus Maximus
Posts: 7247
Joined: Thu Feb 16, 2006 9:38 pm

Re: Single space when cut-and-pasted to text editor

Post by LTinker68 »

I just tried copying a list from one of my topics into Notepad and it pasted without the bullets but with the text for each bullet on its own line and without extra spacing between the lines, even though I have my <li> tag set to apply spacing after each bullet item.

So... Try creating a custom <ul> tag or a custom <li> tag with the list-type set to "none" (that way in the online output you won't see any bullet icons). Enter each line of code as a separate item in that custom list. Then build the output, and try cutting-and-pasting into a text editor.
Image

Lisa
Eagles may soar, but weasels aren't sucked into jet engines.
Warning! Loose nut behind the keyboard.
NorthEast
Master Propellus Maximus
Posts: 6426
Joined: Mon Mar 05, 2007 8:33 am

Re: Single space when cut-and-pasted to text editor

Post by NorthEast »

You could use a pre tag so that it doesn't include the CR/LF.

For example, stick this in a topic.

Code: Select all

<pre xml:space="preserve">Begin
A:=1;
B:2;
End;</pre>
Copy that text from your help and paste it into notepad - it'll have no blank lines.
KevinDAmery
Propellus Maximus
Posts: 1985
Joined: Tue Jan 23, 2007 8:18 am
Location: Darn, I knew I was around here somewhere...

Re: Single space when cut-and-pasted to text editor

Post by KevinDAmery »

Actually, I thought this was the sort of thing that the Pre tag was for. Put your code samples inside a Pre tag block and it should appear in the help exactly as it appears in the code. Your users should similarly be able to copy / paste it without any changes occuring.
Until next time....
Image
Kevin Amery
Certified MAD for Flare
LTinker68
Master Propellus Maximus
Posts: 7247
Joined: Thu Feb 16, 2006 9:38 pm

Re: Single space when cut-and-pasted to text editor

Post by LTinker68 »

I thought the Pre tag was to display text without parsing it, which I guess makes sense as to why it doesn't include blank lines when you paste into a text editor. We don't display code in our help so I've never used the tag.

Go with their suggestion, Tom.
Image

Lisa
Eagles may soar, but weasels aren't sucked into jet engines.
Warning! Loose nut behind the keyboard.
TomTatham
Jr. Propeller Head
Posts: 9
Joined: Sat Jul 21, 2007 12:28 pm

Re: Single space when cut-and-pasted to text editor

Post by TomTatham »

Thanks -- the Pre tag seems to be the easiest solution to my problem. I really appreciate the help -- it would have taken me a very long time to figure this out on my own.
WayneC
Propeller Head
Posts: 17
Joined: Wed Jun 18, 2008 7:40 pm

Re: Single space when cut-and-pasted to text editor

Post by WayneC »

We have the same requirement to embed code within the help files and I'm having the same problems as the original poster. I tried the Pre tag but that seems to remove all line breaks in the copy and pasted code.

So bascially, either I end up with a double line break or no line breaks...
KevinDAmery
Propellus Maximus
Posts: 1985
Joined: Tue Jan 23, 2007 8:18 am
Location: Darn, I knew I was around here somewhere...

Re: Single space when cut-and-pasted to text editor

Post by KevinDAmery »

That's odd. The Pre tag is a standard HTML tag that tells the browser to render anything between those tags exactly the way it's formatted in the code. Here's a description of it:

http://www.w3schools.com/TAGS/tag_pre.asp

If you look at the topic in a text editor, how does the code look between the pre tags? Whatever you see in a text editor is what you're final output will look like.
Until next time....
Image
Kevin Amery
Certified MAD for Flare
TomTatham
Jr. Propeller Head
Posts: 9
Joined: Sat Jul 21, 2007 12:28 pm

Re: Single space when cut-and-pasted to text editor

Post by TomTatham »

I have rethought my approach to code examples. The problem with the pre tag is that long lines don't get wrapped when the output is viewed. I now favor the following:
1. A standard <p> tag. Use of a monospace font (e.g., Courier New) is a very good idea.
2. When entering a code sample, I press shift-enter rather than enter, which prevents a hard paragraph break. If I need spaces, I use shift-space.
Code samples entered in this manner do cut-and-paste into text editors without the double spacing problem and lines wrap during onscreen display (but not when pasted into a text editor).

This approach works less well if your code samples already exist in a text file. Simply cutting and pasting into the XML editor will result in creating a paragraph per line of code. I may write a little filter program to take text files and append a <br /> to the end of every line and to replace leading spaces with " ". The output from the program could then be pasted between <p> </p> in the Flare Internal Text Editor.

Considering how many customers must be creating computer code documentation, it is surprising that there is neither built-in support for code examples nor documentation on how to approach code examples. Unless I find out that I have missed something here, I will send a suggestion to Madcap about this.
NorthEast
Master Propellus Maximus
Posts: 6426
Joined: Mon Mar 05, 2007 8:33 am

Re: Single space when cut-and-pasted to text editor

Post by NorthEast »

TomTatham wrote:The problem with the pre tag is that long lines don't get wrapped when the output is viewed.
By default text in a pre tag isn't wrapped, you need to set some CSS properties for it to wrap text.

Try this:
pre.code
{
font-family: monospace, ' sans-serif';
white-space: pre-wrap;
word-wrap: break-word;
}
TomTatham wrote:Considering how many customers must be creating computer code documentation, it is surprising that there is neither built-in support for code examples nor documentation on how to approach code examples. Unless I find out that I have missed something here, I will send a suggestion to Madcap about this.

Flare doesn't include any specific help for CSS or (X)HTML in general, both of which you really need to know to make your own stylesheets and template. I got by using http://www.w3schools.com and Google.
RamonS
Senior Propellus Maximus
Posts: 4293
Joined: Thu Feb 02, 2006 9:29 am
Location: The Electric City

Re: Single space when cut-and-pasted to text editor

Post by RamonS »

TomTatham wrote:Considering how many customers must be creating computer code documentation, it is surprising that there is neither built-in support for code examples nor documentation on how to approach code examples. Unless I find out that I have missed something here, I will send a suggestion to Madcap about this.
Typically, the technical documentation of this kind is to be created by the developer writing the code, not the tech writers documenting the applications. I don't know the circumstances of your setting, but I'd take great exception when the developers would ask me to do their job. I think the majority of Flare uses do not write code documentation, but many other types of documentation in a wide array of fields. Each could benefit from some specialized automation, but I don't think that adding that all into Flare is the right way to go about it.
As Dave pointed out, there are ways and means to do the things your are asking for. The problem is that CSS has gazillion settings and it is hard to be a master of it all.
WayneC
Propeller Head
Posts: 17
Joined: Wed Jun 18, 2008 7:40 pm

Re: Single space when cut-and-pasted to text editor

Post by WayneC »

One problem with throwing everything between one set of pre tags is the issue of indentation. Currently, I'm using 5 p "code" styles with different indents so that the code is readable.

This forum has the ability to handle code snippets well. It would be nice for Flare to be able to handle it the same way. With even the ability to select all the code so that it can be pasted into a text editor.

PS: Played around with pre settings for each of the "code" styles but still get a double paragrahs when I paste.
RamonS
Senior Propellus Maximus
Posts: 4293
Joined: Thu Feb 02, 2006 9:29 am
Location: The Electric City

Re: Single space when cut-and-pasted to text editor

Post by RamonS »

What you could do is try this forum and paste the code in here using the Code function. You could then take a look at the page source and see how it is done. From the reference in the page source you can find the location of the style sheet and that should get you the details that you need to mimic it in Flare.
Post Reply