Website: update build script (#6271)
* Website: update build script * update .replace() to use HTML entities
This commit is contained in:
+7
-6
@@ -200,33 +200,34 @@ module.exports = {
|
||||
// > • What about images referenced in markdown files? :: They need to be referenced using an absolute URL src-- e.g.  See also https://github.com/fleetdm/fleet/issues/706#issuecomment-884641081 for reasoning.
|
||||
// > • What about GitHub-style emojis like `:white_check_mark:`? :: Use actual unicode emojis instead. Need to revisit this? Visit https://github.com/fleetdm/fleet/pull/1380/commits/19a6e5ffc70bf41569293db44100e976f3e2bda7 for more info.
|
||||
let mdString = await sails.helpers.fs.read(pageSourcePath);
|
||||
mdString = mdString.replace(/(<call-to-action[\s\S]+[^>\n+])\n+(>)/g, '$1$2'); // « Removes any newlines that might exist before the closing `>` when the <call-to-action> compontent is added to markdown files.
|
||||
mdString = mdString.replace(/(?=\n)(\s*)(`{3,4})([a-zA-Z0-9\-]*)([\s*\n])/g, '$1$2' + '$1<!-- __LANG=%' + '$3' + '%__ -->' + '$4'); // « Based on the github-flavored markdown's language annotation, (e.g. ```js```) add a temporary marker to code blocks that can be parsed post-md-compilation when this is HTML. Note: This is an HTML comment because it is easy to over-match and "accidentally" add it underneath each code block as well (being an HTML comment ensures it doesn't show up or break anything). For more information, see https://github.com/uncletammy/doc-templater/blob/2969726b598b39aa78648c5379e4d9503b65685e/lib/compile-markdown-tree-from-remote-git-repo.js#L198-L202
|
||||
mdString = mdString.replace(/(```)([a-zA-Z0-9\-]*)(\s*\n)/g, '$1\n' + '<!-- __LANG=%' + '$2' + '%__ -->' + '$3'); // « Based on the github-flavored markdown's language annotation, (e.g. ```js```) add a temporary marker to code blocks that can be parsed post-md-compilation when this is HTML. Note: This is an HTML comment because it is easy to over-match and "accidentally" add it underneath each code block as well (being an HTML comment ensures it doesn't show up or break anything). For more information, see https://github.com/uncletammy/doc-templater/blob/2969726b598b39aa78648c5379e4d9503b65685e/lib/compile-markdown-tree-from-remote-git-repo.js#L198-L202
|
||||
mdString = mdString.replace(/(<call-to-action[\s\S]+[^>\n+])\n+(>)/g, '$1$2'); // « Removes any newlines that might exist before the closing `>` when the <call-to-action> compontent is added to markdown files.
|
||||
let htmlString = await sails.helpers.strings.toHtml(mdString);
|
||||
htmlString = (// « Add the appropriate class to the `<code>` based on the temporary "LANG" markers that were just added above
|
||||
htmlString
|
||||
.replace(// Interpret `js` as `javascript`
|
||||
// $1 $2 $3 $4
|
||||
/(<code)([^>]*)(>\s*)(\<!-- __LANG=\%js\%__ --\>)\s*/gm,
|
||||
/(<code)([^>]*)(>\s*)(\s\<!-- __LANG=\%js\%__ --\>)\s*/gm,
|
||||
'$1 class="javascript"$2$3'
|
||||
)
|
||||
.replace(// Interpret `sh` and `bash` as `bash`
|
||||
// $1 $2 $3 $4
|
||||
/(<code)([^>]*)(>\s*)(\<!-- __LANG=\%(bash|sh)\%__ --\>)\s*/gm,
|
||||
/(<code)([^>]*)(>\s*)(\s\<!-- __LANG=\%(bash|sh)\%__ --\>)\s*/gm,
|
||||
'$1 class="bash"$2$3'
|
||||
)
|
||||
.replace(// When unspecified, default to `text`
|
||||
// $1 $2 $3 $4
|
||||
/(<code)([^>]*)(>\s*)(\<!-- __LANG=\%\%__ --\>)\s*/gm,
|
||||
/(<code)([^>]*)(>\s*)(\s\<!-- __LANG=\%\%__ --\>)\s*/gm,
|
||||
'$1 class="nohighlight"$2$3'
|
||||
)
|
||||
.replace(// Nab the rest, leaving the code language as-is.
|
||||
// $1 $2 $3 $4 $5 $6
|
||||
/(<code)([^>]*)(>\s*)(\<!-- __LANG=\%)([^%]+)(\%__ --\>)\s*/gm,
|
||||
/(<code)([^>]*)(>\s*)(\s\<!-- __LANG=\%)([^%]+)(\%__ --\>)\s*/gm,
|
||||
'$1 class="$5"$2$3'
|
||||
)
|
||||
.replace(// Finally, remove any "LANG" markers that have been added inside of a nested code block
|
||||
/(```)\n\<\!\-+\s\_+LANG\=\%+\_+\s\-+\>/gm,
|
||||
/((`)+)\n\<\!\-+\s\_+LANG\=\%+\_+\s\-+\>/gm,
|
||||
'$1'
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user