Skip to content

Commit

Permalink
Markdown: Added support for YAML front matter (#2634)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Nov 25, 2020
1 parent 8fa8dd2 commit 5cf9cfb
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@
"markdown": {
"title": "Markdown",
"require": "markup",
"optional": "yaml",
"alias": "md",
"owner": "Golmote"
},
Expand Down
13 changes: 13 additions & 0 deletions components/prism-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@

Prism.languages.markdown = Prism.languages.extend('markup', {});
Prism.languages.insertBefore('markdown', 'prolog', {
'front-matter-block': {
pattern: /(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,
lookbehind: true,
greedy: true,
inside: {
'punctuation': /^---|---$/,
'font-matter': {
pattern: /\S+(?:\s+\S+)*/,
alias: ['yaml', 'language-yaml'],
inside: Prism.languages.yaml
}
}
},
'blockquote': {
// > ...
pattern: /^>(?:[\t ]*>)*/m,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-markdown.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions tests/languages/markdown/front-matter-block_empty_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
---

# Title

---
normal paragraph

---

----------------------------------------------------

[
["front-matter-block", [
["punctuation", "---"],
["punctuation", "---"]
]],

["title", [
["punctuation", "#"],
" Title"
]],

["hr", "---"],
"\r\nnormal paragraph\r\n\r\n",

["hr", "---"]
]
31 changes: 31 additions & 0 deletions tests/languages/markdown/front-matter-block_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
layout: post
title: Blogging Like a Hacker
---

# Title

---
normal paragraph

---

----------------------------------------------------

[
["front-matter-block", [
["punctuation", "---"],
["font-matter", "layout: post\r\ntitle: Blogging Like a Hacker"],
["punctuation", "---"]
]],

["title", [
["punctuation", "#"],
" Title"
]],

["hr", "---"],
"\r\nnormal paragraph\r\n\r\n",

["hr", "---"]
]
24 changes: 24 additions & 0 deletions tests/languages/yaml+markdown/front-matter_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
layout: post
title: Blogging Like a Hacker
---

# Title

----------------------------------------------------

[
["front-matter-block", [
["punctuation", "---"],
["font-matter", [
["key", "layout"], ["punctuation", ":"], " post\n",
["key", "title"], ["punctuation", ":"], " Blogging Like a Hacker"
]],
["punctuation", "---"]
]],

["title", [
["punctuation", "#"],
" Title"
]]
]

0 comments on commit 5cf9cfb

Please sign in to comment.