mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
Merge branch 'mermaid-front-matter-support' of https://github.com/takac/hugo-theme-relearn into takac-mermaid-front-matter-support
This commit is contained in:
commit
59428415f2
1 changed files with 13 additions and 0 deletions
|
@ -171,9 +171,22 @@ function initMermaid( update, attrs ) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var serializeGraph = function( graph ){
|
var serializeGraph = function( graph ){
|
||||||
|
// See https://github.com/mermaid-js/mermaid/blob/9a080bb975b03b2b1d4ef6b7927d09e6b6b62760/packages/mermaid/src/diagram-api/frontmatter.ts#L10
|
||||||
|
// for reference on the regex originally taken from jekyll
|
||||||
|
const frontMatterRegex = /^-{3}\s*[\n\r](.*?)[\n\r]-{3}\s*[\n\r]+/s;
|
||||||
|
const matches = graph.content.match(frontMatterRegex);
|
||||||
|
// if we find front matter, we need to put this before the `%%{init` directive.
|
||||||
|
if (matches) {
|
||||||
|
const ymlFrontMatter = graph.content.substring(0, matches[0].length);
|
||||||
|
const graphContent = graph.content.slice(matches[0].length);
|
||||||
|
var s = ymlFrontMatter + '\n%%{init: ' + JSON.stringify( graph.dir ) + '}%%\n';
|
||||||
|
s += graphContent;
|
||||||
|
return s;
|
||||||
|
} else {
|
||||||
var s = '%%{init: ' + JSON.stringify( graph.dir ) + '}%%\n';
|
var s = '%%{init: ' + JSON.stringify( graph.dir ) + '}%%\n';
|
||||||
s += graph.content;
|
s += graph.content;
|
||||||
return s;
|
return s;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var init_func = function( attrs ){
|
var init_func = function( attrs ){
|
||||||
|
|
Loading…
Reference in a new issue