Skip to content

Commit

Permalink
Use a global id counter in the browser
Browse files Browse the repository at this point in the history
Closes #13
  • Loading branch information
remcohaszing committed Dec 5, 2022
1 parent cefeaf4 commit 058de3c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { type RemarkMermaid } from 'remark-mermaidjs';

import { extractCodeBlocks, replaceCodeBlocks } from './shared.js';

let counter = 0;
const remarkMermaid: RemarkMermaid = (options) => (ast, file) => {
const instances = extractCodeBlocks(ast);

Expand All @@ -12,12 +13,14 @@ const remarkMermaid: RemarkMermaid = (options) => (ast, file) => {
return;
}

const results = instances.map(([node], index) => {
const results = instances.map(([node]) => {
try {
// @ts-expect-error The mermaid types are wrong.
const result = mermaid.render(`remark-mermaid-${counter}`, node.value);
counter += 1;
return {
success: true,
// @ts-expect-error The mermaid types are wrong.
result: mermaid.render(`remark-mermaid-${index}`, node.value),
result,
};
} catch (error) {
return {
Expand Down

0 comments on commit 058de3c

Please sign in to comment.