Compiling into GitHub Flavored Markdown

pa
pakirby
Posts: 2
Joined: Sat Jul 01, 2017 10:11 am
Platform: Mac

Thu Dec 07, 2017 1:35 pm Post

I am using Scrivener 2.8.1.2 on MacOS High Sierra 10.12.6

Compiling into multimarkdown includes inline code backticks but not triple backticks for code blocks.
I use the code paragraph style to mark sections of my code. When I compile to native Multimarkdown it does not include the triple backticks that Github Flavored Markdown uses to format code blocks. Does Scrivener provide a native GFM compiler which will include code blocks.

I did define a new inline code style from the default Code style (without the paragraph properties) and those elements were created as backticks when I compiled.

Online
User avatar
AmberV
Posts: 21050
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Santiago de Compostela, Galiza
Contact:

Thu Dec 07, 2017 4:24 pm Post

Does Git not use tab-indented code block nomenclature? That’s the method Scrivener will use if you are mapping a style to the Code Block function in the MultiMarkdown Options compile format pane.

While we don’t support every flavour of Markdown out there, the system is designed to be expandable. It is relatively simple to roll your own dialects—especially if you are already using the style system to mark blocks:
  1. If you haven’t already created a format, right-click on the Basic Multimarkdown format and “Duplicate & Edit”.
  2. In the Multimarkdown Options format pane, set Code blocks style to “None”. We want to use our own syntax instead of MMD.
  3. In the Styles pane, select the “Code Block” style (which I presume you are using—if not either rename that one or create one) and in the Prefix and Suffix fields, type in your "```" syntax.
    Take care to insert a carriage return after the code in the prefix, and before the code in the suffix, so that they do not fall within the first and last lines of the code block. To insert those into the field use Opt-Return (or copy and paste of course).
In the attached example project, I’ve also shown how you could have a Ruby code block as well as a generic code block.

A GitHub compile format might not be a bad idea though. Hmm. :)
Attachments
markdown_fencequotes_example.zip
(108.42 KiB) Downloaded 16 times
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

pa
pakirby
Posts: 2
Joined: Sat Jul 01, 2017 10:11 am
Platform: Mac

Sun Dec 17, 2017 11:42 am Post

Your sample project is Scrivener 3 not Scrivener 2.8.1.2. So I cannot open your document.

How would I do the following in Scrivener 2.8.1.2 as your steps are vague...

If you haven’t already created a format, right-click on the Basic Multimarkdown format and “Duplicate & Edit”.

How do I do this? right-click what item?


In the Multimarkdown Options format pane, set Code blocks style to “None”. We want to use our own syntax instead of MMD.

How do I display this format pane? which menu item?


In the Styles pane, select the “Code Block” style (which I presume you are using—if not either rename that one or create one) and in the Prefix and Suffix fields, type in your "```" syntax.
Take care to insert a carriage return after the code in the prefix, and before the code in the suffix, so that they do not fall within the first and last lines of the code block. To insert those into the field use Opt-Return (or copy and paste of course).

How do I display the styles pane? which menu item?

User avatar
nontroppo
Posts: 900
Joined: Mon Mar 05, 2007 5:22 pm
Platform: Mac
Location: Airstrip One

Sun Dec 17, 2017 1:15 pm Post

AmberV's method does not work with Scrivener 2. The simplest solution is to put the ``` in the text directly. I use Pandoc dialect which for Scrivener 2 I just put things like syntax highlighted code blocks directly, and used formatting presets just to visualise the text in the editor...

Screen Shot 2017-12-17 at 21.10.27_SML.png
Screen Shot 2017-12-17 at 21.10.27_SML.png (17.27 KiB) Viewed 250 times


Scrivener 3 is much more powerful, as AmberV suggested, as paragraph styles can be converted into custom markup, so you could make "Ruby code Block", or "Python Code Block" styles and these would be translated into ```{.ruby} ... ``` and ```{.python} ... ``` for you. Pandoc can convert from MMD (or any other dialect) to GFM if you wanted, but in your case it shouldn't be necessary...