Page 1 of 1

Code Snippets

Posted: Fri Jan 15, 2021 12:24 am
by Vibeke B
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

Re: Code Snippets

Posted: Fri Jan 15, 2021 8:57 am
by bunnycat
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

Re: Code Snippets

Posted: Mon Jan 18, 2021 10:07 am
by paul_collins
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.

Re: Code Snippets

Posted: Wed Jan 20, 2021 3:16 am
by Vibeke B
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?

Re: Code Snippets

Posted: Mon Feb 01, 2021 7:46 am
by bgo
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.
For JSON, choose Javascript as the language. Then it appears to format correctly.

Re: Code Snippets

Posted: Tue Apr 13, 2021 3:14 pm
by amarchant
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

Posted: Tue Apr 27, 2021 11:43 am
by bunnycat
Looks like Flare 2021 fixed the code indent issue (hurray!) so that XML and such indents look much better.

Re: Code Snippets

Posted: Fri May 07, 2021 7:53 am
by Dafra08
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

Posted: Tue Feb 07, 2023 8:18 am
by RStreets
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 :cry: ]. 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]