Skip to content

Commit

Permalink
feat(#177): enable understanding of front matter
Browse files Browse the repository at this point in the history
**Why:**

Some users add metadata to their Markdown files in the form of
YAML-style front matter and it currently gets treated as regular
content, which looks a bit odd when rendered on the page.

Instead, we would like to be able to identify front matter and not
render it to the page. Ideally we would like to make the metadata
available and/or optionally render it to the page in some way, but this
would require some reworking of the current setup.

**What:**

* Install `markdown-it-front-matter`[^1], which enables `markdown-it` to
  parse YAML-style front matter.
* Enable `markdown-it-front-matter` via `MarkdownIt.use()` like we do
  with other plugins.
  * **Note:** This doesn’t actually do anything other than enable
    `markdown-it` to recognise front matter and not treat it as regular
    content.

[^1]: https://github.com/ParkSB/markdown-it-front-matter

---

#177
  • Loading branch information
bingocaller committed Nov 11, 2024
1 parent 2ecdad6 commit 1ee005b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"markdown-it-deflist": "^3.0.0",
"markdown-it-emoji": "^3.0.0",
"markdown-it-footnote": "^4.0.0",
"markdown-it-front-matter": "^0.2.4",
"markdown-it-github-alerts": "^0.3.0",
"markdown-it-inject-linenumbers": "^0.3.0",
"markdown-it-mark": "^4.0.0",
Expand Down
4 changes: 4 additions & 0 deletions src/parser/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import MarkdownIt from 'markdown-it';
import anchor from 'markdown-it-anchor';
import frontMatter from 'markdown-it-front-matter';
import highlight from './highlight.js';
import graphviz from './dot.js';
import mermaid from './mermaid.js';
Expand Down Expand Up @@ -59,6 +60,9 @@ mdit.use(toc, config.tocOptions);

// MARK: untyped plugins done

// markdown-it-front-matter requires a callback function but we aren’t doing
// anything with it, so we just pass in a noop.
mdit.use(frontMatter, () => {});
// anchor has to be added after attribute plugin for ids to work
mdit.use(anchor, {
permalink: anchor.permalink.ariaHidden({
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,11 @@ markdown-it-footnote@^4.0.0:
resolved "https://registry.yarnpkg.com/markdown-it-footnote/-/markdown-it-footnote-4.0.0.tgz#02ede0cb68a42d7e7774c3abdc72d77aaa24c531"
integrity sha512-WYJ7urf+khJYl3DqofQpYfEYkZKbmXmwxQV8c8mO/hGIhgZ1wOe7R4HLFNwqx7TjILbnC98fuyeSsin19JdFcQ==

markdown-it-front-matter@^0.2.4:
version "0.2.4"
resolved "https://registry.yarnpkg.com/markdown-it-front-matter/-/markdown-it-front-matter-0.2.4.tgz#cf29bc8222149b53575699357b1ece697bf39507"
integrity sha512-25GUs0yjS2hLl8zAemVndeEzThB1p42yxuDEKbd4JlL3jiz+jsm6e56Ya8B0VREOkNxLYB4TTwaoPJ3ElMmW+w==

markdown-it-github-alerts@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/markdown-it-github-alerts/-/markdown-it-github-alerts-0.3.0.tgz#acab7db57f4e204c8d1c987403c367738d7026b0"
Expand Down

0 comments on commit 1ee005b

Please sign in to comment.