inserting code blocks into a topic

This forum is for all Flare issues related to styles, stylesheets and XML.
Post Reply
sanjsrik
Sr. Propeller Head
Posts: 103
Joined: Wed Nov 03, 2010 12:57 pm

inserting code blocks into a topic

Post by sanjsrik »

Hi,

i can't be the first one to come across this need. I need to insert a LOT of code blocks that show off javascript in our application as sample code. However, I can't figure out for the life of me how to format and retain the formatting of the sample code IN a topic.

I tried a text box and inserted the code in there, but it didn't keep the javascript formatting. Is there a setting for code blocks to indicate that they are javscript so I won't lose the syntax formatting in the code when copy/paste it into a topic in Flare?

Thank you in advance.

I searched both the application help and the forums but seem to keep coming up with topics that have nothing to do with my question.
Nita Beck
Senior Propellus Maximus
Posts: 3672
Joined: Thu Feb 02, 2006 9:57 am
Location: Pittsford, NY

Re: inserting code blocks into a topic

Post by Nita Beck »

You are absolutely not the only Flare author who needs to show code samples.

Two-step process:
1. Create a new block and assign the <pre> style to it. That means it will preserve the formatting as set, including any spaces and line breaks.
2. Copy and paste the code into that <pre> block. Flare will insert the code as a bunch of <p> blocks but DON'T PANIC. Immediately look for the little Paste icon that will appear directly beneath and to the right of the last block added. Click that icon to open a little drop-down menu and select Paste Inline Text. Now all the pasted code should be within the <pre> block and the formatting should look right.

HTH
Nita
Image
RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
sanjsrik
Sr. Propeller Head
Posts: 103
Joined: Wed Nov 03, 2010 12:57 pm

Re: inserting code blocks into a topic

Post by sanjsrik »

Hi,

Thank you for the detailed instructions. Just a question for clarification...

When you say "insert a block" what do you mean exactly? Are you saying insert a text box and format that with the <pre> tag? I did that and copied the code in and the text was all left-aligned.

Thank you in advance.
Nita Beck
Senior Propellus Maximus
Posts: 3672
Joined: Thu Feb 02, 2006 9:57 am
Location: Pittsford, NY

Re: inserting code blocks into a topic

Post by Nita Beck »

Sorry for the confusion. I always work with structure bars and span bars showing, so I tend to think in terms of "blocks".

I mean, just start a new blank paragraph and then style it with the <pre> style, which will be listed at the very bottom of the Style window.
Nita
Image
RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
sanjsrik
Sr. Propeller Head
Posts: 103
Joined: Wed Nov 03, 2010 12:57 pm

Re: inserting code blocks into a topic

Post by sanjsrik »

Now, I'm REALLY confused...

I pressed the enter key for about 3 lines, formatted them as <pre> copied and pasted the code and everything was left justified. The code is only 3 lines long but I'm testing this as a first pass. If this won't work, then I don't know how to do this for code samples that are more than 40-50 lines with lots of code indentations.

When I did copy/paste the code into the blocks, everything pasted with a <p> tag and pushed the <pre> tag down below it. By that point, the code is reformatted with all left-justified.

I too work with the block view showing.

Is there anything in the help that spells out how to do this? I searched and the problem is I'd refer to them as code snippets but the vernacular in Flare is used for other types of text as reusable for snippets.

Okay, I figured it out. Like in Word, you have to choose the options for when you paste in the text to paste "inline text" which keeps the formatting. This isn't obvious and you have to actually figure out to do this. I created a text box with a gray background set to <pre> and it still needed to have the text indicated after pasting as "inline" text.

There's no topic that specifically talks about choosing "inline text" as opposed to how if you simply copy/paste, the text will reformat as <p> and push the <pre> tag down.

*sigh* this really can't be the first time someone put a code block in the text.

NOW, if only they supported language syntax highlighting. Which I'm guessing Flare doesn't.

How DOES someone who has to represent a lot of code blocks do this programatically?
Nita Beck
Senior Propellus Maximus
Posts: 3672
Joined: Thu Feb 02, 2006 9:57 am
Location: Pittsford, NY

Re: inserting code blocks into a topic

Post by Nita Beck »

Sounds like you didn't completely follow my instructions. You need to have only one block styled as <pre>. Put your cursor on that line and paste. Don't worry for now how the stuff looks once pasted, but immediately look for and click the little Paste icon that will appear directly below and to the right of the last bit of pasted stuff. That'll show you a little menu. Select Paste Inline Text. Now your three lines of code should all be within that single <pre> block.
PasteInlineText.png
code_sample_after_paste_inilne_text.png
And no you're not the only one pasting code samples. Many of us do this, regularly.
You do not have the required permissions to view the files attached to this post.
Nita
Image
RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
sanjsrik
Sr. Propeller Head
Posts: 103
Joined: Wed Nov 03, 2010 12:57 pm

Re: inserting code blocks into a topic

Post by sanjsrik »

I found this article that addresses an older version of Flare. You'd think they'd actually document this somewhere...

https://kungfuwit.wordpress.com/2009/05 ... o-a-topic/
sanjsrik
Sr. Propeller Head
Posts: 103
Joined: Wed Nov 03, 2010 12:57 pm

Re: inserting code blocks into a topic

Post by sanjsrik »

So, I also found a js that can be included that can do syntax highlighting, if anyone needs it...

http://alexgorbatchev.com/SyntaxHighlighter/

Thank you for your help.
Nita Beck
Senior Propellus Maximus
Posts: 3672
Joined: Thu Feb 02, 2006 9:57 am
Location: Pittsford, NY

Re: inserting code blocks into a topic

Post by Nita Beck »

sanjsrik wrote:So, I also found a js that can be included that can do syntax highlighting, if anyone needs it...
Thanks for paying it forward. I'm actually in need of something handle that myself.
Nita
Image
RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
sanjsrik
Sr. Propeller Head
Posts: 103
Joined: Wed Nov 03, 2010 12:57 pm

Re: inserting code blocks into a topic

Post by sanjsrik »

Nita Beck wrote:
sanjsrik wrote:So, I also found a js that can be included that can do syntax highlighting, if anyone needs it...
Thanks for paying it forward. I'm actually in need of something handle that myself.
If you get this to work, please please please write it up or post instructions as to how you did it. I'm a bit lost as to how to incorporate this scheme into the flare project I'm working on at the moment.
BrianBAtCeres
Propeller Head
Posts: 13
Joined: Fri Jun 12, 2015 1:57 pm
Location: Thousand Oaks, CA
Contact:

Re: inserting code blocks into a topic

Post by BrianBAtCeres »

Sorry for the necromancy but I’ve been searching for instructions about how to simulate code in Flare for days. I tried searching for “MadCap Flare computer code style” and similar strings both here and on Google but nothing relevant turned up. It wasn’t until I tried “MadCap Flare pre style” that I found this thread.
Nita Beck wrote:Two-step process:
1. Create a new block and assign the <pre> style to it. That means it will preserve the formatting as set, including any spaces and line breaks.
2. Copy and paste the code into that <pre> block. Flare will insert the code as a bunch of <p> blocks but DON'T PANIC. Immediately look for the little Paste icon that will appear directly beneath and to the right of the last block added. Click that icon to open a little drop-down menu and select Paste Inline Text. Now all the pasted code should be within the <pre> block and the formatting should look right.
Thank you! My only suggestion would be to change the first sentence of Step 2 to
Copy and paste the code into that <pre> block. Flare will insert the code as a bunch of <p> blocks for no apparent reason but DON'T PANIC AND DON’T DO ANYTHING YET!
:D
I don’t know how many times I got those <p> tag blocks and assumed that this was an impossible task using the XML Editor.
sanjsrik wrote:I found this article that addresses an older version of Flare. You'd think they'd actually document this somewhere...

https://kungfuwit.wordpress.com/2009/05 ... o-a-topic/
+1

I think MadCap should write an article or FAQ since this is such a common task for tech writers.

Thanks,
Brian
:flare: MadCap Flare v11, :capture: MadCap Capture v7
Post Reply