Closed zommuter closed 5 years ago
This seems a little bit difficult to solve.
Abricotine supports Github-Flavored Markdown and ---
can be used for horizontal rules.
I think the best way to do this would be to fork CodeMirror markdown mode to add an option modeCfg.yamlHeader
. By using states, we can set a new CodeMirror.innerMode
using YAML mode which would be triggered when the document starts with ---
(and closed with another ---
). Then maybe it could be interesting to merge this back to the CodeMirror repo.
This is a huge work, though. I personally would enjoy doing it but I'm not familiar with CodeMirror modes. Maybe later if I get enough time.
@darahak So does pandoc. From a few tests, it seems pandoc does some checks (I tried to regex it, but it's not perfect).
I guess ---
is only interpreted as the start (or end) of a YAML-block, if it doesn't make sense as horizontal rule, i.e. when it's not followed by empty lines. Ok, as one can easily check here in the preview, Github-MD doesn't require an empty paragraph after a horizontal rule, so either pandoc does some more checking for a matching YAML-ending (or even whether the potential block contains valid YAML) or it simply requires horizontal rules to be followed by empty paragraphs...
But at least ---
at the beginning of a file won't make sense as horizontal ruler, so something like ^(?=-{3,}\n)([\W\w]*?)(?=([-\.])\2{2,})
should do the trick for that (most likely) case.
@zommuter CodeMirror parser is working line by line so multiline regex won't work. IMO the correct way to do this is definitely to patch markdown mode. I think any other solution would be very tricky, at least in term of performance.
Front matter YAML block coud appear only at the beginning of the markdown file so it's pretty simple to cut if off from markdown parsing by checking if the file starts with ---
and if so, skip anything until next ---
line.
I mean it should be possible to pass only the remaining part of the file (pure markdown) to CodeMirror (is it used by Abricotine?) and have a separate view (out of the main editor) for showing/editing meta stuff. It could be some form or even just a textarea
for now
In windows, my YAML front matter is not skipped.
@chris2fr What does that mean exactly? Can you describe the issue please.
Since I'm using pandoc, my files usually start with a YAML-block such as
This confuses Abricotine's parser, and if I use YAML-comments (starting with
#
) on a single line, they are interpreted as section headers and thus both confuses the TOC and renders it rather huge. Instead, YAML-headers should be ignored, maybe rendered like comments.