Code Snippets

This forum is for all Flare issues not related to any of the other categories.
Post Reply
Vibeke B
Propeller Head
Posts: 73
Joined: Thu Mar 15, 2018 7:14 am
Location: Denmark

Code Snippets

Post 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
bunnycat
Propeller Head
Posts: 70
Joined: Tue Nov 03, 2015 6:44 am

Re: Code Snippets

Post 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
paul_collins
Propeller Head
Posts: 22
Joined: Thu May 22, 2014 7:25 am

Re: Code Snippets

Post 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.
Vibeke B
Propeller Head
Posts: 73
Joined: Thu Mar 15, 2018 7:14 am
Location: Denmark

Re: Code Snippets

Post 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?
bgo
Jr. Propeller Head
Posts: 6
Joined: Mon Sep 09, 2019 8:39 am

Re: Code Snippets

Post 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.
amarchant
Jr. Propeller Head
Posts: 6
Joined: Mon Apr 02, 2012 10:44 am

Re: Code Snippets

Post 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.
bunnycat
Propeller Head
Posts: 70
Joined: Tue Nov 03, 2015 6:44 am

Re: Code Snippets

Post by bunnycat »

Looks like Flare 2021 fixed the code indent issue (hurray!) so that XML and such indents look much better.
Dafra08
Propeller Head
Posts: 45
Joined: Fri Aug 16, 2019 1:02 am

Re: Code Snippets

Post 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.
RStreets
Propeller Head
Posts: 63
Joined: Wed Apr 19, 2017 8:37 am
Location: Cambridge, UK

Re: Code Snippets

Post 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]
Rae Streets (Flare user since 2017, now on Flare 2023; Central user from 2020)
Post Reply