-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from remcohaszing/browser-support
Add browser support
- Loading branch information
Showing
67 changed files
with
1,580 additions
and
499 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"100": true, | ||
"include": ["index.ts"], | ||
"reporter": ["html", "lcov", "text"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
extends: | ||
- remcohaszing | ||
rules: | ||
no-param-reassign: off | ||
'@typescript-eslint/consistent-type-imports': | ||
- error | ||
- prefer: type-imports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
coverage/ | ||
dist/ | ||
node_modules/ | ||
test-results/ | ||
*.d.ts | ||
*.js | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
__fixtures__/*/output.md | ||
__snapshots__/ | ||
**/*-snapshots/* | ||
coverage/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { fromDom } from 'hast-util-from-dom'; | ||
import { type Code, type Parent, type Root } from 'mdast'; | ||
import mermaid from 'mermaid'; | ||
import { type Plugin } from 'unified'; | ||
import { visit } from 'unist-util-visit'; | ||
|
||
// eslint-disable-next-line jsdoc/require-jsdoc | ||
function transformer(ast: Root): void { | ||
const instances: [string, number, Parent][] = []; | ||
|
||
visit(ast, { type: 'code', lang: 'mermaid' }, (node: Code, index, parent: Parent) => { | ||
instances.push([node.value, index, parent]); | ||
}); | ||
|
||
// Nothing to do. No need to start puppeteer in this case. | ||
if (!instances.length) { | ||
return; | ||
} | ||
|
||
const results = instances.map(([code], index) => | ||
// @ts-expect-error The mermaid types are wrong. | ||
mermaid.render(`remark-mermaid-${index}`, code), | ||
); | ||
|
||
const wrapper = document.createElement('div'); | ||
for (const [i, [, index, parent]] of instances.entries()) { | ||
const value = results[i]; | ||
wrapper.innerHTML = value; | ||
parent.children.splice(index, 1, { | ||
type: 'paragraph', | ||
children: [{ type: 'html', value }], | ||
data: { hChildren: [fromDom(wrapper.firstChild!)] }, | ||
}); | ||
} | ||
} | ||
|
||
const remarkMermaid: Plugin<[], Root> = () => transformer; | ||
|
||
export default remarkMermaid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.