Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Pandoc flavoured markdown preview
-
I write a lot in Pandoc-flavoured Markdown. Using Sublime Text 3 and Marked I can get a preview by using Pandoc as a custom processor in Marked. Is there a way to do something similar in Editorial? The most important thing for me would be hiding the YAML metadata block I have at the start of my documents e.g.:
--- title: Foo author: Bar date: 16 February 2015 ...
I'm not sure how to do that by editing a template, or even if it's possible. A workflow solution would be nice, but I would like to be able to use it offline. So something that goes through Docverter won't do.
There are some differences between ordinary Markdown and Pandoc-flavoured that it would be nice to deal with too.
Does anybody have any suggestions?
-
A possible workflow:
- A python script to remove the YAML and convert between Editorial and Pandoc Markdown.
- Call the action
Convert markdown to HTML
orConvert multimarkdown to HTML
- Add a custom CSS if you want.
- Call the action
Show HTML
to see the preview.
It all happens within Editorial, offline. However I don't know Pandoc markdown, and this might be too simple for what you want. Another however, if you asked then perhaps writing Python is not what you want to do.
-
If you could provide a more complete example of the source doc and the desired destination doc then I could try to write the Python code for step 1. Does the YAML block really start with '---' and end with '...'?
Edit: According to http://johnmacfarlane.net/pandoc/demo/example9/pandocs-markdown.html
[...] the YAML file begins with --- and ends with --- or ...
-
def whack_the_yaml(text): if not text.strip(): return text start_index = end_index = -1 # impossible indexes lines = text.splitlines() for i, line in enumerate(lines): if start_index == -1: if line.strip() == '---': start_index = i else: if line.strip() in ('...', '---'): end_index = i+1 break if start_index == -1 or end_index == -1: console.hud_alert('No yaml block was found.', 'error') return text else: console.hud_alert('Removing {} lines of yaml.'.format(end_index-start_index)) return '\n'.join(lines[:start_index] + lines[end_index:])
Note: This only removes the first YAML block if there are multiple YAML blocks.
So... On to the second issue, conversion of Pandoc markdown to standard markdown. According to the first paragraph of http://johnmacfarlane.net/pandoc/demo/example9/pandocs-markdown.html you could use the
markdown_strict
format to suppress all differences between Pandoc markdown and John Gruber’s markdown syntax. If there were Pandoc features that you required then you could turn them on individually with themarkdown_strict+EXTENSION
format. It would be far easier to create code to do the Pandoc markdown to standard markdown conversion if it only had to deal with one or two extensions rather that all 49 extensions mentioned in the link above. -
Thank-you peterh and ccc. I'm happy writing simple Python, but this was my first Editorial Workflow. I've put one together along the lines you suggested.
-
Great