Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Ignore YAML-Header #142

Closed
zommuter opened this issue Jan 5, 2017 · 7 comments
Closed

Ignore YAML-Header #142

zommuter opened this issue Jan 5, 2017 · 7 comments

Comments

@zommuter
Copy link

zommuter commented Jan 5, 2017

Since I'm using pandoc, my files usually start with a YAML-block such as

---
# Here's the document title
title: Document title
---

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.

@darahak
Copy link
Contributor

darahak commented Jan 5, 2017

This seems a little bit difficult to solve.
Abricotine supports Github-Flavored Markdown and --- can be used for horizontal rules.

@brrd
Copy link
Owner

brrd commented Jan 6, 2017

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.

@zommuter
Copy link
Author

zommuter commented Jan 6, 2017

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

@brrd
Copy link
Owner

brrd commented Jan 6, 2017

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

@dskopa-softdev
Copy link

dskopa-softdev commented May 18, 2018

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

@chris2fr
Copy link

In windows, my YAML front matter is not skipped.

@brrd
Copy link
Owner

brrd commented May 21, 2020

@chris2fr What does that mean exactly? Can you describe the issue please.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

5 participants