-
-
Notifications
You must be signed in to change notification settings - Fork 489
feat: Support frontmatter in docs #344
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
Open
thompson-tomo
wants to merge
30
commits into
thlorenz:master
Choose a base branch
from
thompson-tomo:feat/#279_frontMatter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
d844081
Scaffold #279
thompson-tomo 599d5c2
Add tests for front matter
thompson-tomo 330c033
add new line at the end
thompson-tomo 0feafb1
Add safeguards for not enough content.
thompson-tomo eec04c4
Update transform.js
thompson-tomo 4eefc39
Update transform.js
thompson-tomo a79acc1
Update transform.js
thompson-tomo e43be0a
Add more tests
thompson-tomo c6dff5c
update test fixtures
thompson-tomo f4ae29a
fix filename
thompson-tomo 774e0ea
test fix
thompson-tomo 3549694
fix all test
thompson-tomo 811c26a
Update readme-frontmatter-existing.md
thompson-tomo 8e2da05
Update transform.js
thompson-tomo 2583873
Update transform.js
thompson-tomo 655a610
Update transform.js
thompson-tomo ee25bb1
Update transform.js
thompson-tomo 343fb32
Update transform.js
thompson-tomo 5a1d07b
Merge branch 'thlorenz:master' into feat/#279_frontMatter
thompson-tomo 47313e8
Update transform.js
thompson-tomo f54826e
Update transform.js
thompson-tomo 6f2cff9
Update transform.js
thompson-tomo 408b826
Update transform.js
thompson-tomo ba80026
Merge branch 'thlorenz:master' into feat/#279_frontMatter
thompson-tomo c9d6e77
Use defined eol character
thompson-tomo 49b8b3f
Merge branch 'master' into feat/#279_frontMatter
thompson-tomo fba8690
Merge branch 'master' into feat/#279_frontMatter
thompson-tomo ce64fbb
Improve test to cater for TOC not always first
thompson-tomo e9e8b17
Bump markdown parser
thompson-tomo a5e8498
Merge branch 'master' into feat/#279_frontMatter
thompson-tomo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| --- | ||
| title: Yaml Front Matter | ||
| --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --- | ||
| title: Yaml Front Matter | ||
| --- | ||
|
|
||
| # Title | ||
|
|
||
| <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
| <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
| **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* | ||
|
|
||
| - [Title](#title) | ||
| <!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
|
||
| ## Heading | ||
|
|
||
| Your regular Markdown content follows... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| +++ | ||
| title: Invalid Front Matter | ||
| ||| | ||
|
|
||
| # Heading | ||
|
|
||
| Your regular Markdown content follows... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ;;; | ||
| title: JSON Front Matter | ||
| ;;; | ||
|
|
||
| # Heading | ||
|
|
||
| Your regular Markdown content follows... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| +++ | ||
| title: TOML Front Matter | ||
| +++ | ||
|
|
||
| # Heading | ||
|
|
||
| Your regular Markdown content follows... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| title: Yaml Front Matter | ||
| --- | ||
|
|
||
| # Heading | ||
|
|
||
| Your regular Markdown content follows... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| 'use strict'; | ||
| /*jshint asi: true */ | ||
|
|
||
| var test = require('tap').test | ||
| , transform = require('../lib/transform') | ||
|
|
||
| test('\ngiven a file that includes Json frontmatter', function (t) { | ||
| var content = require('fs').readFileSync(__dirname + '/fixtures/readme-frontmatter-json.md', 'utf8'); | ||
| var res = transform(content); | ||
|
|
||
| t.same( | ||
| res.data | ||
| , [ ';;;', | ||
| 'title: JSON Front Matter', | ||
| ';;; ', | ||
| '', | ||
| '<!-- START doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '<!-- DON\'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->', | ||
| '**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*', | ||
| '', | ||
| '- [Heading](#heading)', | ||
| '', | ||
| '<!-- END doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '', | ||
| '# Heading', | ||
| '', | ||
| 'Your regular Markdown content follows...', | ||
| '' ].join('\n') | ||
| , 'generates correct toc for file with Json frontmatter' | ||
| ) | ||
|
|
||
| t.end() | ||
| }) | ||
|
|
||
| test('\ngiven a file that includes Toml frontmatter', function (t) { | ||
| var content = require('fs').readFileSync(__dirname + '/fixtures/readme-frontmatter-toml.md', 'utf8'); | ||
| var res = transform(content); | ||
|
|
||
| t.same( | ||
| res.data | ||
| , [ '+++', | ||
| 'title: TOML Front Matter', | ||
| '+++ ', | ||
| '', | ||
| '<!-- START doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '<!-- DON\'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->', | ||
| '**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*', | ||
| '', | ||
| '- [Heading](#heading)', | ||
| '', | ||
| '<!-- END doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '', | ||
| '# Heading', | ||
| '', | ||
| 'Your regular Markdown content follows...', | ||
| '' ].join('\n') | ||
| , 'generates correct toc for file with Toml frontmatter' | ||
| ) | ||
|
|
||
| t.end() | ||
| }) | ||
|
|
||
| test('\ngiven a file that includes yaml frontmatter', function (t) { | ||
| var content = require('fs').readFileSync(__dirname + '/fixtures/readme-frontmatter-yaml.md', 'utf8'); | ||
| var res = transform(content); | ||
|
|
||
| t.same( | ||
| res.data | ||
| , [ '---', | ||
| 'title: Yaml Front Matter', | ||
| '---', | ||
| '', | ||
| '<!-- START doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '<!-- DON\'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->', | ||
| '**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*', | ||
| '', | ||
| '- [Heading](#heading)', | ||
| '', | ||
| '<!-- END doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '', | ||
| '# Heading', | ||
| '', | ||
| 'Your regular Markdown content follows...', | ||
| '' ].join('\n') | ||
| , 'generates correct toc for file with yaml frontmatter' | ||
| ) | ||
|
|
||
| t.end() | ||
| }) | ||
|
|
||
| test('\ngiven a file that includes invalid frontmatter', function (t) { | ||
| var content = require('fs').readFileSync(__dirname + '/fixtures/readme-frontmatter-invalid.md', 'utf8'); | ||
| var res = transform(content); | ||
|
|
||
| t.same( | ||
| res.data | ||
| , [ '<!-- START doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '<!-- DON\'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->', | ||
| '**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*', | ||
| '', | ||
| '- [Heading](#heading)', | ||
| '', | ||
| '<!-- END doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '', | ||
| '+++', | ||
| 'title: Invalid Front Matter', | ||
| '|||', | ||
| '', | ||
| '# Heading', | ||
| '', | ||
| 'Your regular Markdown content follows...', | ||
| '' ].join('\n') | ||
| , 'generates correct toc for file with invalid frontmatter' | ||
| ) | ||
|
|
||
| t.end() | ||
| }) | ||
|
|
||
| test('\ngiven a file that has only yaml frontmatter and empty line', function (t) { | ||
| var content = require('fs').readFileSync(__dirname + '/fixtures/readme-frontmatter-blank.md', 'utf8'); | ||
| var res = transform(content.trim() + '\n'); | ||
|
|
||
| t.same( | ||
| res.data | ||
| , [ '---', | ||
| 'title: Yaml Front Matter', | ||
| '---', | ||
| '', | ||
| '<!-- START doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '<!-- DON\'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->', | ||
| '<!-- END doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '' ].join('\n') | ||
| , 'generates correct toc for file with only yaml frontmatter' | ||
| ) | ||
|
|
||
| t.end() | ||
| }) | ||
|
|
||
| test('\ngiven a file that has only yaml frontmatter and no trailing whitespace', function (t) { | ||
| var content = require('fs').readFileSync(__dirname + '/fixtures/readme-frontmatter-blank.md', 'utf8'); | ||
| var res = transform(content.trim()); | ||
|
|
||
| t.same( | ||
| res.data | ||
| , [ '---', | ||
| 'title: Yaml Front Matter', | ||
| '---', | ||
| '', | ||
| '<!-- START doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '<!-- DON\'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->', | ||
| '<!-- END doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '' ].join('\n') | ||
| , 'generates correct toc for file with only yaml frontmatter' | ||
| ) | ||
|
|
||
| t.end() | ||
| }) | ||
|
|
||
| test('\ngiven a file that includes yaml frontmatter and process all', function (t) { | ||
| var content = require('fs').readFileSync(__dirname + '/fixtures/readme-frontmatter-existing.md', 'utf8'); | ||
| var res = transform(content, undefined, undefined, undefined, undefined, undefined, undefined, undefined, true); | ||
|
|
||
| t.same( | ||
|
thompson-tomo marked this conversation as resolved.
|
||
| res.data | ||
| , [ '---', | ||
| 'title: Yaml Front Matter', | ||
| '---', | ||
| '', | ||
| '# Title', | ||
| '', | ||
| '<!-- START doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '<!-- DON\'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->', | ||
| '**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*', | ||
| '', | ||
| '- [Title](#title)', | ||
| ' - [Heading](#heading)', | ||
| '', | ||
| '<!-- END doctoc generated TOC please keep comment here to allow auto update -->', | ||
| '', | ||
| '## Heading', | ||
| '', | ||
| 'Your regular Markdown content follows...', | ||
| '' ].join('\n') | ||
| , 'generates correct toc for file with yaml frontmatter' | ||
| ) | ||
|
|
||
| t.end() | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.