-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #380 from pattern-lab/dev
Pattern Lab Node 2.1.0
- Loading branch information
Showing
13 changed files
with
374 additions
and
329 deletions.
There are no files selected for viewing
This file contains 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 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 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,53 @@ | ||
"use strict"; | ||
|
||
var md = require('markdown-it')(); | ||
|
||
var markdown_parser = function () { | ||
|
||
function parseMarkdownBlock(block) { | ||
var returnObject = {}; | ||
|
||
try { | ||
//for each block process the yaml frontmatter and markdown | ||
var frontmatterRE = /---\r?\n{1}([\s\S]*)---\r?\n{1}([\s\S]*)+/gm; | ||
var chunks = frontmatterRE.exec(block); | ||
if (chunks && chunks[1] && chunks[2]) { | ||
|
||
//convert each yaml frontmatter key / value into an object key | ||
var frontmatter = chunks[1]; | ||
var frontmatterLines = frontmatter.split(/\n/gm); | ||
for (var j = 0; j < frontmatterLines.length; j++) { | ||
|
||
var frontmatterLine = frontmatterLines[j]; | ||
if (frontmatterLine.length > 0) { | ||
|
||
var frontmatterLineChunks = frontmatterLine.split(':'); //test this | ||
var frontmatterKey = frontmatterLineChunks[0].toLowerCase().trim(); | ||
var frontmatterValueString = frontmatterLineChunks[1].trim(); | ||
|
||
returnObject[frontmatterKey] = frontmatterValueString.substring(1, frontmatterValueString.length - 1); | ||
} | ||
|
||
} | ||
|
||
//parse the actual markdown | ||
returnObject.markdown = md.render(chunks[2]); | ||
} | ||
} catch (ex) { | ||
console.log(ex); | ||
console.log('error parsing markdown block', block); | ||
} | ||
|
||
//return the frontmatter keys and markdown for a consumer to decide what to do with | ||
return returnObject; | ||
} | ||
|
||
return { | ||
parse: function (block) { | ||
return parseMarkdownBlock(block); | ||
} | ||
}; | ||
|
||
}; | ||
|
||
module.exports = markdown_parser; |
This file contains 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 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 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 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 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 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
Oops, something went wrong.