Feature request: support YAML front matter
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start at the nextjournal.markdown/parse entry point and inspect how it configures commonmark-java. Read the YamlFrontMatterExtension and YamlFrontMatterVisitor references, then decide whether front matter is excluded or exposed as metadata. Done means the sample no longer parses front matter as regular Markdown and the chosen behavior preserves the actual heading and metadata.
Written by the indexing model from the issue text.
Description
Summary
YAML front matter (delimited by ---) is widely used in static site generators (Hugo, Jekyll, etc.) and documentation tools. Currently, nextjournal/markdown parses front matter as regular markdown content, producing incorrect results.
Current behavior
(require '[nextjournal.markdown :as md])
(md/parse "---
title: My Post
date: 2024-01-01
---
## Actual Heading")
Produces:
- A
:rulernode (from the opening---) - An h2 heading with text "title: My Post" (incorrectly parsed as markdown heading)
- A paragraph with "date: 2024-01-01"
- Another
:rulernode (from the closing---) - The actual h2 heading
Expected behavior
Front matter should be:
- Recognized and excluded from markdown parsing, OR
- Parsed and included as a separate
:front-matternode with the YAML content
Example of option 2:
{:type :doc
:front-matter {:title "My Post" :date "2024-01-01"}
:content [{:type :heading :heading-level 2 :content [...]}]}
Workaround
Users currently need to strip front matter before calling parse, which is error-prone and loses the metadata.
Implementation note
The underlying commonmark-java library already has a YamlFrontMatterExtension in the commonmark-ext-yaml-front-matter artifact with YamlFrontMatterVisitor for extracting metadata. Using this extension at the commonmark-java level (rather than preprocessing the string) would have the advantage that other features like source line numbers (#64) would work correctly for free, since the parser would know where the actual content starts.
References:
- Dominant language
- Clojure
- Stars
- 100
- Forks
- 11
- Avg merge
- 2h 3m
- Merged PRs (30d)
- 2
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nextjournal/markdown
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
nextjournal/markdown#77 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 87/100
nextjournal/markdown#76 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
nextjournal/markdown#64 · 7 comments · 1 reaction ·
All issues in nextjournal/markdown
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
nextjournal/clerk#830 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
IOP tokens release blocker team qa team qa autotests WG adoption
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
penpot/penpot#13540 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
izhangzhihao/intellij-rainbow-brackets#2903 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100