If a Markdown file contains Front Matter with a title, then replace the Front Matter with a matching heading
This commit is contained in:
parent
553b5b1df8
commit
e992a55ef3
2 changed files with 14 additions and 6 deletions
|
|
@ -4,9 +4,6 @@ title: About JavaScript Machines
|
||||||
permalink: /docs/about/
|
permalink: /docs/about/
|
||||||
---
|
---
|
||||||
|
|
||||||
About JavaScript Machines
|
|
||||||
---
|
|
||||||
|
|
||||||
The JavaScript Machines Project (originally at [jsmachines.net](http://jsmachines.net/)) is a collection of computer
|
The JavaScript Machines Project (originally at [jsmachines.net](http://jsmachines.net/)) is a collection of computer
|
||||||
simulations written in JavaScript. It has now been released on [GitHub](https://github.com/) as the
|
simulations written in JavaScript. It has now been released on [GitHub](https://github.com/) as the
|
||||||
[PCjs Project](https://github.com/jeffpar/pcjs), a copy of which is hosted here at [pcjs.org](http://www.pcjs.org/).
|
[PCjs Project](https://github.com/jeffpar/pcjs), a copy of which is hosted here at [pcjs.org](http://www.pcjs.org/).
|
||||||
|
|
|
||||||
|
|
@ -308,6 +308,7 @@ MarkOut.aHTMLEntities = {
|
||||||
*/
|
*/
|
||||||
MarkOut.prototype.convertMD = function(sIndent)
|
MarkOut.prototype.convertMD = function(sIndent)
|
||||||
{
|
{
|
||||||
|
var aMatch;
|
||||||
var sMD = this.sMD;
|
var sMD = this.sMD;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -349,9 +350,20 @@ MarkOut.prototype.convertMD = function(sIndent)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the Markdown begins with a triple-dash, we assume there's a "Front Matter" header at the
|
* If the Markdown begins with a triple-dash, we assume there's a "Front Matter" header at the
|
||||||
* top of the file that we don't want to output, either.
|
* top of the file that we don't want to output, either. One wrinkle: we assume that if a
|
||||||
|
* "title" element exists in the Front Matter, then we should auto-generate a top-level heading
|
||||||
|
* with the same value.
|
||||||
*/
|
*/
|
||||||
sMD = sMD.replace(/^---[\s\S]*?---[ \t]*\n*/, "");
|
if (sMD.substr(0, 3) == "---") {
|
||||||
|
aMatch = sMD.match(/^---([\s\S]*?)---[ \t]*\n*/);
|
||||||
|
if (aMatch) {
|
||||||
|
sMD = sMD.replace(aMatch[0], "");
|
||||||
|
aMatch = aMatch[1].match(/title:\s*(.*?)\s*?\n/);
|
||||||
|
if (aMatch) {
|
||||||
|
sMD = aMatch[1] + "\n---\n\n" + sMD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert all lone series of three or more hyphens/underscores/asterisks into horizontal rules.
|
* Convert all lone series of three or more hyphens/underscores/asterisks into horizontal rules.
|
||||||
|
|
@ -394,7 +406,6 @@ MarkOut.prototype.convertMD = function(sIndent)
|
||||||
* you want the second paragraph to appear as a code block, it must be indented TWICE (by 8 spaces
|
* you want the second paragraph to appear as a code block, it must be indented TWICE (by 8 spaces
|
||||||
* or 2 tabs). That behavior should fall out of this hack as well.
|
* or 2 tabs). That behavior should fall out of this hack as well.
|
||||||
*/
|
*/
|
||||||
var aMatch;
|
|
||||||
var re = /(^|\n)( ? ?)([\*+-]|[0-9]+\.)([^\n]*\n)([ \t]+[^\n]*\n|\n)+([ \t]+[^\n]+)/g;
|
var re = /(^|\n)( ? ?)([\*+-]|[0-9]+\.)([^\n]*\n)([ \t]+[^\n]*\n|\n)+([ \t]+[^\n]+)/g;
|
||||||
//noinspection UnnecessaryLocalVariableJS
|
//noinspection UnnecessaryLocalVariableJS
|
||||||
var sMDOrig = sMD;
|
var sMDOrig = sMD;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue