Skip to content

Commit

Permalink
boo
Browse files Browse the repository at this point in the history
  • Loading branch information
pngwn committed Aug 15, 2024
1 parent a1e4959 commit 37c26e0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/mdsvex/src/transformers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Transformer } from 'unified';
import type { Text, Code, HTML } from 'mdast';
import type { Element, Root } from 'hast';
import type { VFileMessage } from 'vfile-message';
import { createRequire } from 'module';

import Message from 'vfile-message';
//@ts-ignore
Expand Down Expand Up @@ -29,6 +30,8 @@ import type {
LayoutMeta,
} from '../types';

const _require = import.meta.url ? createRequire(import.meta.url) : require;

// this needs a big old cleanup

const newline = '\n';
Expand Down Expand Up @@ -488,11 +491,9 @@ interface Meta {
}

function load_language_metadata() {
const {
meta,
...languages
}: Record<string, PrismLanguage> &
Meta = require('prismjs/components.json').languages;
const { meta, ...languages }: Record<string, PrismLanguage> & Meta = _require(
'prismjs/components.json'
).languages;

for (const lang in languages) {
const [lang_info, aliases] = get_lang_info(
Expand Down Expand Up @@ -523,7 +524,7 @@ function load_language(lang: string) {

langs[lang].deps.forEach((name) => load_language(name));

require(langs[lang].path);
_require(langs[lang].path);
}

export function highlight_blocks({
Expand Down Expand Up @@ -580,7 +581,7 @@ export const code_highlight: Highlighter = (code, lang) => {

let _lang = !!normalised_lang && langs[normalised_lang];

if (!Prism) Prism = require('prismjs');
if (!Prism) Prism = _require('prismjs');

if (_lang && !Prism.languages[_lang.name]) {
load_language(_lang.name);
Expand Down

0 comments on commit 37c26e0

Please sign in to comment.