Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/pat/syntax-highlight/syntax-highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ class Pattern extends BasePattern {
theme = this.options.theme;
}

import(`highlight.js/styles/${theme}.css`);
// Map both spellings to one stylesheet so Webpack emits it once.
const theme_name = String(theme).replace(/\.min$/, "");
import(
/* webpackExclude: /\.min\.css$/ */
`highlight.js/styles/${theme_name}.css`
);
const hljs = (await import("highlight.js/lib/core")).default;

// Get the language
Expand Down Expand Up @@ -69,7 +74,10 @@ class Pattern extends BasePattern {
};
const lang_file = import_path_mapping[language] || language;
const hljs_language = (
await import(`highlight.js/lib/languages/${lang_file}`)
await import(
/* webpackExclude: /\.js\.js$/ */
`highlight.js/lib/languages/${lang_file}`
)
).default;
hljs.registerLanguage(language, hljs_language);
high = hljs.highlight(value, { language: language }).value;
Expand Down
28 changes: 14 additions & 14 deletions style/patterns.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ module.exports = () => {

config.output.path = path.resolve(__dirname, "../dist/");

// Webpack resolves dynamic import contexts as directories before applying
// highlight.js's per-file exports (webpack/webpack#13865).
const highlight_path = path.dirname(require.resolve("highlight.js/package.json"));
config.resolve.alias["highlight.js/lib/languages$"] = path.join(
highlight_path,
"es/languages"
);
config.resolve.alias["highlight.js/styles$"] = path.join(highlight_path, "styles");

// Module federation
config.plugins.push(
mf_config({
Expand Down