How to preserve leading spaces in code sample paste?

This forum is for all Flare issues related to styles, stylesheets and XML.
Post Reply
keuler
Propeller Head
Posts: 63
Joined: Sun Sep 20, 2009 2:54 pm

How to preserve leading spaces in code sample paste?

Post by keuler »

Hi. I'd appreciate advice on how to preserve the indenting spaces when copying code samples from a text file to a Flare topic. My experience is that they disappear, and the result is that all lines in the target are flush left.

At least one other thread from a while back has suggested copying the text into a "pre" formatted paragraph. This doesn't work for me: The text is copied, but the style for each paragraph switches to the base "p" tag.

The labor intensive workaround that I'd like to avoid is

Thanks in advance.
SteveS
Senior Propellus Maximus
Posts: 2090
Joined: Tue Mar 07, 2006 5:06 pm
Location: Adelaide, far side of the world ( 34°56'0.78\"S 138°46'44.28\"E).
Contact:

Re: How to preserve leading spaces in code sample paste?

Post by SteveS »

In 'normal' HTML (XML etc) any necessary spaces are ignored. So spaces at the beginning of an elements content, the end, two spaces and so on are ignored. That's good, until you want to retain the space. As you've discovered...

The pre tag, or pre-formatted, overcomes this.

You should be able to cut and paste into a pre tag, retaining additional spaces.

If you are not getting what you expect, open the topic in the text editor rather than the XML editor. You should be able to see the opening and closing tags and identify its working correctly.

For example:

Code: Select all

<pre xml:space="preserve"><p> text with a leading space</p></pre>
I didn't at the space preserve stuff, that was added by Flare when the pre style was applied from the styles pane.

HTH
Image
Steve
Life's too short for bad coffee, bad chocolate, and bad red wine.
kwag_myers
Propellus Maximus
Posts: 810
Joined: Wed Jul 25, 2012 11:36 am
Location: Ann Arbor, MI

Re: How to preserve leading spaces in code sample paste?

Post by kwag_myers »

If I understand the issue, you must preserve both the spaces and the paragraph styles (which pre doesn't do), correct? The only way I can see to do this is to replace all spaces with  :

1. Paste the code into NotePad and open the Find and Replace dialog (Ctrl+H).
2. Type a space in the Find what field and   in Replace with. If you want to preserve the spaces within the text, type two spaces and replace with   .
3. Select all (Ctrl+A), Cut (Ctrl+X) and Paste (Ctrl+V) into the Text Editor of your topic.
"I'm tryin' to think, but nothin' happens!" - Curly Joe Howard
Nita Beck
Senior Propellus Maximus
Posts: 3672
Joined: Thu Feb 02, 2006 9:57 am
Location: Pittsford, NY

Re: How to preserve leading spaces in code sample paste?

Post by Nita Beck »

I copy code samples into Flare within a pre tag and by pasting as inline. That'll preserve the spaces. I would not use hard spaces.

To paste something as inline, do the paste, and then look for the little clipboard icon below and to the right of what you just pasted. Click that icon and select Paste Inline.

Sorry so brief... HTH anyways.

EDIT: Here's another forum post where code samples are discussed: viewtopic.php?f=6&t=20603
Nita
Image
RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
keuler
Propeller Head
Posts: 63
Joined: Sun Sep 20, 2009 2:54 pm

Re: How to preserve leading spaces in code sample paste?

Post by keuler »

Thanks all for the comments.

I experimented with the pre tag per Nita's comments, and got the hang of it.

One thing I noticed: the pre-tags don't like to be grouped into a div by means of the Tab key. They're simply deleted. I'll file a bug.

-Kurt
Dana Ellingen
Jr. Propeller Head
Posts: 5
Joined: Mon Oct 06, 2014 6:34 pm
Location: Saratoga, CA

Re: How to preserve leading spaces in code sample paste?

Post by Dana Ellingen »

As always, Nita's solution saves the day. As do the MadCap Software Forums. This is probably in the manual, but I couldn't find it.

Thanks, Nita!

--Dana
Post Reply