Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create alternative syntax for frontmatter #2145

Merged
merged 9 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ packages/core/test/unit/**/*.js
packages/core/src/lib/markdown-it/patches/*
packages/core/src/lib/markdown-it/plugins/*
!packages/core/src/lib/markdown-it/plugins/markdown-it-icons.ts
!packages/core/src/lib/markdown-it/plugins/markdown-it-alt-frontmatter.ts

# --- packages/core end ---

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ packages/core/src/lib/nunjucks-extensions/*.js
packages/core/src/lib/markdown-it/index.js
packages/core/src/lib/markdown-it/highlight/*.js
packages/core/src/lib/markdown-it/plugins/markdown-it-icons.js
packages/core/src/lib/markdown-it/plugins/markdown-it-alt-frontmatter.js
packages/core/src/lib/markdown-it/utils/*.js
packages/core/src/Page/*.js
packages/core/src/plugins/**/*.js
Expand Down
28 changes: 28 additions & 0 deletions docs/_markbind/boilerplates/codeHorizontal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- This boilerplate shows MarkBind code block side by side -->
<!-- Supports 5 variables. -->
<!-- `highlightStyle` (optional) - Defines the syntax coloring for the code block-->
<!-- `headingLeft` - Heading of the left code block -->
<!-- `headingRight` - Heading of the right code block -->
<!-- `codeLeft` - The MarkBind code content in this variable will appear in a code block on LHS -->
<!-- `codeRight` - The MarkBind code content in this variable will appear in a code block on RHS -->

<table style="width: 100%;">
<tr>
<th style="width: 45%; padding-right: 5%">{{ headingLeft }}</th>
<th style="width: 45%; padding-left: 5%;">{{ headingRight }}</th>
</tr>
<tr>
<td style="padding-right: 5%">

```{{ highlightStyle | safe }}
{{ codeLeft | safe | trim }}
```
</td>
<td style="padding-left: 5%;">

```{{ highlightStyle | safe }}
{{ codeRight | safe | trim }}
```
</td>
</tr>
</table>
40 changes: 34 additions & 6 deletions docs/userGuide/syntax/frontmatter.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,49 @@
## Frontmatter

**You can use a _frontmatter_ section to specify page properties such as the title and keywords of the page.** To specify frontmatter for a page, insert a `<frontmatter>` tag in the following format at the beginning of the page.

```html
**You can use a _frontmatter_ section to specify page properties such as the title and keywords of the page.**
To specify frontmatter for a page, insert a `<frontmatter>` tag in the following format at the beginning of the page.<br>
You can use YAML-style frontmatter syntax `---` as well.
<div class="indented">
<include src="codeHorizontal.md" boilerplate >
<variable name="highlightStyle">html</variable>
<variable name="headingLeft">Frontmatter</variable>
<variable name="headingRight">YAML-style Frontmatter Syntax</variable>
<variable name="codeLeft">
<frontmatter>
property1: value1
property2: value2
</frontmatter>
```
</variable>
<variable name="codeRight">
---
property1: value1
property2: value2
---
</variable>
</include>
</div>



<div class="indented">

{{ icon_example }} Here, we set the page `title` attribute as `Binary Search Tree`.
```html

<include src="codeHorizontal.md" boilerplate >
<variable name="highlightStyle">html</variable>
<variable name="headingLeft">Frontmatter</variable>
<variable name="headingRight">YAML-style Frontmatter Syntax</variable>
<variable name="codeLeft">
<frontmatter>
title: Binary Search Tree
</frontmatter>
```
</variable>
<variable name="codeRight">
---
title: Binary Search Tree
---
</variable>
</include>
</div>

<box type="warning" seamless>
Expand Down
36 changes: 36 additions & 0 deletions packages/cli/test/functional/test_site/expected/siteData.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,36 @@
"headings": {},
"headingKeywords": {}
},
{
"src": "testEmptyAltFrontMatter.md",
"title": "Hello World",
"headings": {},
"headingKeywords": {}
},
{
"src": "testLayoutsOverrideWithAltFrontmatter.md",
"title": "Hello World",
"headings": {},
"headingKeywords": {}
},
{
"src": "testAltFrontMatterInvalidKeyValue.md",
"title": "Hello World",
"headings": {},
"headingKeywords": {}
},
{
"src": "testSingleAltFrontMatter.md",
"title": "Hello World",
"headings": {},
"headingKeywords": {}
},
{
"src": "testAltFrontMatterParsing.md",
"title": "new title",
"headings": {},
"headingKeywords": {}
},
{
"src": "testExternalScripts.md",
"title": "Hello World",
Expand All @@ -122,6 +152,12 @@
"headings": {},
"headingKeywords": {}
},
{
"src": "testLayoutsWithAltFrontMatter.md",
"title": "Test nunjucks path resolving",
"headings": {},
"headingKeywords": {}
},
{
"src": "testNunjucksPathResolving.md",
"title": "Hello World",
Expand Down
Loading