Last active
March 6, 2026 12:40
-
-
Save flying-sheep/40c8f353548563df0b2b5205657a6f89 to your computer and use it in GitHub Desktop.
Reproducer for https://github.com/bearcove/arborium/issues/166: `pnpm i; pnpm start`
This file contains hidden or 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
| /node_modules/ |
This file contains hidden or 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
| { | |
| "type": "module", | |
| "scripts": { | |
| "start": "node repro.js" | |
| }, | |
| "dependencies": { | |
| "@arborium/arborium": "2.14.0", | |
| "@arborium/xml": "2.14.0" | |
| }, | |
| "packageManager": "pnpm@10.30.3" | |
| } |
This file contains hidden or 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
| lockfileVersion: '9.0' | |
| settings: | |
| autoInstallPeers: true | |
| excludeLinksFromLockfile: false | |
| importers: | |
| .: | |
| dependencies: | |
| '@arborium/arborium': | |
| specifier: 2.14.0 | |
| version: 2.14.0 | |
| '@arborium/xml': | |
| specifier: 2.14.0 | |
| version: 2.14.0 | |
| packages: | |
| '@arborium/arborium@2.14.0': | |
| resolution: {integrity: sha512-XiPV9e1qSIRXmzQH1w0dXegBdkOkNsOEGZaxqMRgYMB06zdH6mHF5HXF3ZE0tOg3fq1HohSrdwgjcP/ZwgESHQ==} | |
| '@arborium/xml@2.14.0': | |
| resolution: {integrity: sha512-smtG+jJe5LLCN7NeDksT36izLcGIotm6m09mZkr8flkH4xEBQArN2FoLObqwPG/ADvV0bBMwdd4knhC+dphSdg==} | |
| engines: {node: '>=18'} | |
| snapshots: | |
| '@arborium/arborium@2.14.0': {} | |
| '@arborium/xml@2.14.0': {} |
This file contains hidden or 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
| import { loadGrammar } from "@arborium/arborium" | |
| import fs from "node:fs/promises" | |
| function resolveJs({ language, path }) { | |
| return import(`@arborium/${language}/${path}`) | |
| } | |
| function resolveWasm({ language, path }) { | |
| const wasmUrl = new URL(import.meta.resolve(`@arborium/${language}/${path}`)) | |
| return fs.readFile(wasmUrl.pathname) | |
| } | |
| const config = { | |
| resolveJs, | |
| resolveWasm, | |
| resolveHostJs: resolveJs, | |
| resolveHostWasm: resolveWasm, | |
| } | |
| export default async function highlightCode(code, lang) { | |
| const grammar = await loadGrammar(lang, config) | |
| if (!grammar) throw new Error(`Unknown language: ${lang}`) | |
| return grammar.parse(code) | |
| } | |
| const code = `<?xml version="1.0"?> | |
| <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> | |
| <fontconfig/>` | |
| console.log(await highlightCode(code, "xml")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment