omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Editorial
    3
    6
    4634
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • TWSH
      TWSH last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • peterh86
        peterh86 last edited by

        A possible workflow:

        1. A python script to remove the YAML and convert between Editorial and Pandoc Markdown.
        2. Call the action Convert markdown to HTML or Convert multimarkdown to HTML
        3. Add a custom CSS if you want.
        4. 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.

        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          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 ...

          1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by

            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 the markdown_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.

            1 Reply Last reply Reply Quote 0
            • TWSH
              TWSH last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • peterh86
                peterh86 last edited by

                Great

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors