inserting code blocks into a topic
inserting code blocks into a topic
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.
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
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
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

RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
Re: inserting code blocks into a topic
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.
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
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.
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

RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
Re: inserting code blocks into a topic
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?
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
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.
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

RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
Re: inserting code blocks into a topic
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/
https://kungfuwit.wordpress.com/2009/05 ... o-a-topic/
Re: inserting code blocks into a topic
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.
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
Thanks for paying it forward. I'm actually in need of something handle that myself.sanjsrik wrote:So, I also found a js that can be included that can do syntax highlighting, if anyone needs it...
Nita

RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
Re: inserting code blocks into a topic
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.Nita Beck wrote:Thanks for paying it forward. I'm actually in need of something handle that myself.sanjsrik wrote:So, I also found a js that can be included that can do syntax highlighting, if anyone needs it...
-
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
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.
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.
I think MadCap should write an article or FAQ since this is such a common task for tech writers.
Thanks,
Brian
Thank you! My only suggestion would be to change the first sentence of Step 2 toNita 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.
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!
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.
+1sanjsrik 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/
I think MadCap should write an article or FAQ since this is such a common task for tech writers.
Thanks,
Brian