helper code for rendering examples
This commit is contained in:
parent
a3f9651982
commit
9338217743
2 changed files with 26 additions and 33 deletions
19
build.js
19
build.js
|
|
@ -10,12 +10,29 @@ function getCurrentId() {
|
|||
return id;
|
||||
}
|
||||
|
||||
function example(code) {
|
||||
const magicBrackets = /\[\[(.*)\]\]/g;
|
||||
const inline = code.replace(magicBrackets, "$1");
|
||||
const escaped = code
|
||||
.replace(magicBrackets, "")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">");
|
||||
|
||||
return `<div class="example">
|
||||
${inline}
|
||||
<details>
|
||||
<summary>Show code</summary>
|
||||
<pre><code>${escaped}</code></pre>
|
||||
</details>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function buildDocs() {
|
||||
const template = fs.readFileSync("./docs/index.html.ejs", "utf-8");
|
||||
|
||||
fs.writeFileSync(
|
||||
"./docs/index.html",
|
||||
ejs.render(template, { getNewId, getCurrentId })
|
||||
ejs.render(template, { getNewId, getCurrentId, example })
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue