mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
parent
66c8fcade1
commit
c41edc86e1
1 changed files with 8 additions and 8 deletions
|
@ -164,13 +164,13 @@ function initMermaid( update, attrs ) {
|
|||
var YAML=1;
|
||||
var INIT=2;
|
||||
var GRAPH=3;
|
||||
var d = /^(?:\s*[\n\r])*(-{3}\s*[\n\r](?:.*?)[\n\r]-{3}(?:\s*[\n\r]+)+)?(?:\s*(?:%%\s*\{\s*\w+\s*:([^%]*?)%%\s*[\n\r]?))?(.*)$/s
|
||||
var d = /^(?:\s*[\n\r])*(?:-{3}(\s*[\n\r](?:.*?)[\n\r])-{3}(?:\s*[\n\r]+)+)?(?:\s*(?:%%\s*\{\s*\w+\s*:([^%]*?)%%\s*[\n\r]?))?(.*)$/s
|
||||
var m = d.exec( graph );
|
||||
var yaml = {};
|
||||
var dir = {};
|
||||
var content = graph;
|
||||
if( m && m.length == 4 ){
|
||||
yaml = m[YAML] ? jsyaml.load(m[YAML].replaceAll("---", "")) : yaml;
|
||||
yaml = m[YAML] ? jsyaml.load( m[YAML] ) : yaml;
|
||||
dir = m[INIT] ? JSON.parse( '{ "init": ' + m[INIT] ).init : dir;
|
||||
content = m[GRAPH] ? m[GRAPH] : content;
|
||||
}
|
||||
|
@ -179,14 +179,14 @@ function initMermaid( update, attrs ) {
|
|||
};
|
||||
|
||||
var serializeGraph = function( graph ){
|
||||
yamlPart = '';
|
||||
dirPart = '';
|
||||
if (JSON.stringify(graph.dir) !== '{}') {
|
||||
dirPart = '%%{init: ' + JSON.stringify(graph.dir) + '}%%\n';
|
||||
}
|
||||
if (JSON.stringify(graph.yaml) !== '{}') {
|
||||
var yamlPart = '';
|
||||
if( Object.keys( graph.yaml ).length ){
|
||||
yamlPart = '---\n' + jsyaml.dump( graph.yaml ) + '---\n';
|
||||
}
|
||||
var dirPart = '';
|
||||
if( Object.keys( graph.dir ).length ){
|
||||
dirPart = '%%{init: ' + JSON.stringify( graph.dir ) + '}%%\n';
|
||||
}
|
||||
return yamlPart + dirPart + graph.content;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue