masukomi / vim-markdown-folding

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

ENH: Add foldlevel=7 for horizontal rules. #5

Closed inkarkat closed 10 years ago

inkarkat commented 11 years ago

According to John Gruber's spec and the Stack Overflow implementation, horizontal rules are defined by three or more hyphens, asterisks, or underscores (optionally separated by spaces) on a line.

Since horizontal rules are a (weak kind of) structuring mechanism, include them as foldlevel 7, after all possible headings.

nelstrom commented 10 years ago

This seems a little bit strange to me. It fits ok when using the flat folding style (where everything is effectively foldlevel 1), but it feels awkward when using the nested folding style. With this as a sample text:

# One A

Lorem ipsum...

## Two A

Lorem ipsum...

---

## Two B

Lorem ipsum...

If I place my cursor on the --- horizontal rule and press zo, it increments the fold level from 2 to 3, but doesn't open the fold. If I press zo again, the foldlevel goes from 3 to 4, and still doesn't open the fold. Repeat zo again and again, and eventually when it reaches 7, the fold opens.

I feel uneasy about this. In general, I try to make my headers spell out a table of contents for the document. An <h3> can follow an <h2> (parent) or another <h3> (sibling), but an <h3> should not come after an <h1> (grandparent). Treating <hr> as an <h7> feels like a violation of this guideline.

inkarkat commented 10 years ago

I'm afraid that's the best one can do with Vim's sequential fold levels.

If you have the foldcolumn visible, you'll notice the deep nesting and then use zO instead of zo (which due to its required repetition is indeed close to useless).

Despite its quirks, I still find this useful overall. Not all documents are neatly hierarchically structured...

nelstrom commented 10 years ago

I'm still not convinced that this is worth adding. Also, this test would need reviewing, as it breaks with this patch.

nelstrom commented 10 years ago

Another thing: issues 3 and 8 have both requested adding support for YAML frontmatter, as used by some static site generators. I think that's worthwhile adding. I'd want proper tests in place, since the frontmatter blocks and horizontal rules both use ---, which could lead to conflicts.

inkarkat commented 10 years ago

Well, it's your call. Feel free to close this issue; I can always keep using this in my private fork. If others find this useful, they can add their comments here and re-open an issue.

nelstrom commented 10 years ago

Ok, let's close this for now. We can re-open it later if necessary.