Hello everyone!
I have just discovered that Flare has a Code Snippet feature. I have used a pre styling with a monospace font and colored background for code until now but I think I want to go ahead and change our code examples to the snippet. But before I do so, I just wanted to hear if anyone is experiencing problems with this feature? Is it mature enough to embark on? Any teething problems? We have a lot of code examples, so I have a bit job ahead of me, but I hope it will be worth it in the end.
Kind regards,
Vibeke
Code Snippets
Re: Code Snippets
It basically works.
Output displays nicely on HTML5 output and has the added benefit of the "copy to clipboard" functionality.
In PDF output, it does the syntax highlighting nicely - which is sorely missing if you are using a different <pre> tag solution (or code syntax highlighting solution such as Prettify or PrismJS)
However, I feel it is still lacking in some language support. Common ones are there, but it feels like it's missing things like JSON and command line.
For some reason, it appears that previous releases (2020 plain, R2) handled code indents better. 2020 R3 seems to not indent code snippets properly when the target is built, even though you see your indents in the dialog box for code snippets.
If your code snippets are lengthy, line numbering on the left side tend to display weirdly, probably because of margins and such in the code snippet divs and classes baked into the functionality.
Hope this helps.
-CAT
Output displays nicely on HTML5 output and has the added benefit of the "copy to clipboard" functionality.
In PDF output, it does the syntax highlighting nicely - which is sorely missing if you are using a different <pre> tag solution (or code syntax highlighting solution such as Prettify or PrismJS)
However, I feel it is still lacking in some language support. Common ones are there, but it feels like it's missing things like JSON and command line.
For some reason, it appears that previous releases (2020 plain, R2) handled code indents better. 2020 R3 seems to not indent code snippets properly when the target is built, even though you see your indents in the dialog box for code snippets.
If your code snippets are lengthy, line numbering on the left side tend to display weirdly, probably because of margins and such in the code snippet divs and classes baked into the functionality.
Hope this helps.
-CAT
-
- Propeller Head
- Posts: 22
- Joined: Thu May 22, 2014 7:25 am
Re: Code Snippets
A minor point is that the generated output converts any leading space characters to a character, which might not be desirable in some situations. It does this for every language type, including PlainText.
This specific issue caused a problem fur us with the jinja templating language, although using tabs instead worked fine.
This specific issue caused a problem fur us with the jinja templating language, although using tabs instead worked fine.
Re: Code Snippets
I can see what you mean about the indents. I am playing with an XML code, and the indents (tabs) display nicely in the Code Editor, but are not there when I click OK and close the Editor, nor do they display in the PDF or the online output. Also, the indents are still not there when you use the Copy function in the online output.
Is there a fix, or should this be reported to MadCap?
Is there a fix, or should this be reported to MadCap?
Re: Code Snippets
For JSON, choose Javascript as the language. Then it appears to format correctly.bunnycat wrote: However, I feel it is still lacking in some language support. Common ones are there, but it feels like it's missing things like JSON and command line.
Re: Code Snippets
Choosing JavaScript as the language to highlight JSON doesn't work for me. In order for this feature to be useful for my company, it would have to support JSON highlighting.
Re: Code Snippets
Looks like Flare 2021 fixed the code indent issue (hurray!) so that XML and such indents look much better.
Re: Code Snippets
I think it works quite well, but I have fairly simple code examples. I do miss the possibility to highlight parts of the code with, say yellow background, to point out that ”this needs to be changed to your server name” or whatever.
Re: Code Snippets
Flare 2022 r2
I paste in some JSON which happens to have been formatted with leading spaces. It displays fine in the code snippet editor (using JavaScript as the selected language, or even leaving it with no language selected). The published code has all but one of the leading spaces in each row converted to non-breaking spaces [the fix referred to upthread seems not to be fixed ]. These code snippets do not paste as valid code in a code editor.
I convert the spaces into tabs, paste into the code snippet editor. The tabs disappear.
I may have to go back to hand-crafted snippets and no Copy button. (And raising a bug with MadCap.)
[edited for missing verb]
I paste in some JSON which happens to have been formatted with leading spaces. It displays fine in the code snippet editor (using JavaScript as the selected language, or even leaving it with no language selected). The published code has all but one of the leading spaces in each row converted to non-breaking spaces [the fix referred to upthread seems not to be fixed ]. These code snippets do not paste as valid code in a code editor.
I convert the spaces into tabs, paste into the code snippet editor. The tabs disappear.
I may have to go back to hand-crafted snippets and no Copy button. (And raising a bug with MadCap.)
[edited for missing verb]
Rae Streets (Flare user since 2017, now on Flare 2023; Central user from 2020)