Skip to content

Commit

Permalink
Preprocessor fixes for broken embeds
Browse files Browse the repository at this point in the history
  • Loading branch information
wilwade committed Sep 19, 2024
1 parent eca77ab commit 9a148bf
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions docs/preprocessor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ function replaceButtonLinks(chapter) {
}

function swaggerEmbed(chapter) {
const regex = /{{#swagger-embed\s(.+?)}}/;
const match = chapter.content.match(regex);
if (match) {
const regex = /{{#swagger-embed\s(.+?)}}/g;
const matches = [...chapter.content.matchAll(regex)];
matches.forEach((match) => {
const swaggerFile = match[1];
const output = runNpxCommand('openapi-to-md', [swaggerFile]);
const replaceWith = output
Expand All @@ -61,7 +61,7 @@ function swaggerEmbed(chapter) {
.map((line) => (line.startsWith('#') ? line + '{}' : line))
.join('\n');
chapter.content = chapter.content.replace(match[0], replaceWith);
}
});
if (chapter.sub_items) {
chapter.sub_items.forEach((section) => {
section.Chapter && swaggerEmbed(section.Chapter);
Expand All @@ -70,14 +70,14 @@ function swaggerEmbed(chapter) {
}

function markdownEmbed(chapter) {
const regex = /{{#markdown-embed\s(.+?)\s(.+?)}}/;
const match = chapter.content.match(regex);
if (match) {
const regex = /{{#markdown-embed\s(.+?)\s(.+?)}}/g;
const matches = [...chapter.content.matchAll(regex)];
matches.forEach((match) => {
const markdownFile = match[1];
const output = readFileSync(markdownFile, 'utf8');
const replaceWith = output.split('\n').slice(match[2]).join('\n');
chapter.content = chapter.content.replace(match[0], replaceWith);
}
});
if (chapter.sub_items) {
chapter.sub_items.forEach((section) => {
section.Chapter && markdownEmbed(section.Chapter);
Expand All @@ -86,15 +86,15 @@ function markdownEmbed(chapter) {
}

function svgEmbed(chapter) {
const regex = /{{#svg-embed\s(.+?)\s(.+?)}}/;
const match = chapter.content.match(regex);
if (match) {
const regex = /{{#svg-embed\s(.+?)\s(.+?)}}/g;
const matches = [...chapter.content.matchAll(regex)];
matches.forEach((match) => {
const svgFile = match[1];
const titleTag = match[2];
const output = readFileSync(svgFile, 'utf8');
const replaceWith = `<div class="svg-embed" title="${titleTag}">${output}</div>`;
chapter.content = chapter.content.replace(match[0], replaceWith);
}
});
if (chapter.sub_items) {
chapter.sub_items.forEach((section) => {
section.Chapter && svgEmbed(section.Chapter);
Expand Down

0 comments on commit 9a148bf

Please sign in to comment.