masukomi / vim-markdown-folding

Fold markdown documents by section.
248 stars 43 forks source link

Python's metadata extension breaks vim-folding #18

Open nfarrar opened 9 years ago

nfarrar commented 9 years ago

The python markdown extension supports YAML-like frontmatter for storing meta-data in markdown documents (ref). I just encountered this with pelican, which unfortunately doesn't support YAML frontmatter (which vim-markdown-folding does seem to work with).

Having the metadata tags at the start of the document is just like YAML, but without the dashes:

Title: Dangit
slug: vim-markdown-folding-is-awesome
Date: 2015-02-10
Author: @nfarrar

## It broke
:(

Any chance it'd be possible to add support? It is the primary python markdown library. :)

EDIT: I did finally get YAML frontmatter implimented and after using it for a bit - I realized that while it doesn't completely break vim-markdown-folding, it creates a fold in the middle of the YAML front matter. For example:


---
Title:    Its Going Down
Date:     2015-02-10
Status:   Published

---

will fold to:


---
Title:    Its Going Down
Date:     2015-02-10
## Status:   Published [# lines] ---------------------------------------
nelstrom commented 9 years ago

I'd like to support front-matter with this plugin. YAML-style front-matter is on my list already, but I wasn't aware that this Python extension used an alternative format (without the dashes).

I can explain what's happening here:

---
Title:    Its Going Down
Date:     2015-02-10
Status:   Published
---

Vim sees the dashes underneath this line:

Status:   Published
---

And incorrectly guesses that the Status line is an <h2>. That explains why you see the folding that you see. Not ideal!

masukomi commented 4 years ago

And incorrectly guesses that the Status line is an <h2>. That explains why you see the folding that you see. Not ideal! - @nelstrom

The thing is, that that's not incorrect. That's totally valid markdown. See settext heading underline part of the CommonMark spec. The simple workaround is to add an extra line break above it.

I'm open to a PR that provides some way to toggle frontmatter support, BUT it's more complicated than what has been noted.

Hugo is a rather popular static blog engine that supports TOML, YAML, JSON, and ORG formats of frontmatter. As frontmatter is used primarily by static blogs it makes sense to support the formats supported by the major ones.

The TOML ones are defined by an opening and closing line of plusses +++, the YAML by hypens ---, the JSON by curly braces {...} the ORG frontmatter ends as soon as there's a line that does NOT start with #+

I'm not even sure what to call these "python" ones.

@nfarrar

masukomi commented 4 years ago

sorry @nelstrom brain fart for a moment, and forgot this all started with you. ;)

just going through old tickets.