refactor(markdown): Make module CLI-importable
Drop the mermaid import from the markdown module. The extension only emits <pre class="mermaid">, so initialize mermaid in the app entry instead. Use explicit .js specifiers plus a bundler extensionAlias so both the NodeNext CLI build and the web build resolve the sources.
This commit is contained in:
@@ -18,6 +18,13 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
rspack: {
|
rspack: {
|
||||||
|
resolve: {
|
||||||
|
// Allow TypeScript sources to use explicit `.js` specifiers (required
|
||||||
|
// by the CLI's NodeNext build) while the bundler resolves them to .ts.
|
||||||
|
extensionAlias: {
|
||||||
|
".js": [".ts", ".tsx", ".js"],
|
||||||
|
},
|
||||||
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import { render } from "solid-js/web";
|
import { render } from "solid-js/web";
|
||||||
import { Router, Route } from "@solidjs/router";
|
import { Router, Route } from "@solidjs/router";
|
||||||
|
import mermaid from "mermaid";
|
||||||
import App from "./App";
|
import App from "./App";
|
||||||
import "./styles.css";
|
import "./styles.css";
|
||||||
|
|
||||||
|
// Mermaid is a runtime concern; the markdown module only emits
|
||||||
|
// <pre class="mermaid"> placeholders. Initialize before any `mermaid.run()`.
|
||||||
|
mermaid.initialize({ theme: "dark" });
|
||||||
|
|
||||||
const root = document.getElementById("root");
|
const root = document.getElementById("root");
|
||||||
|
|
||||||
if (root) {
|
if (root) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { MarkedExtension } from "marked";
|
import type { MarkedExtension } from "marked";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import { parseBlockAttrs } from "./block-attrs";
|
import { parseBlockAttrs } from "./block-attrs.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* YAML-defined tag blocks:
|
* YAML-defined tag blocks:
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Marked, type MarkedExtension } from "marked";
|
import { Marked, type MarkedExtension } from "marked";
|
||||||
import { createDirectives, presetDirectiveConfigs } from "marked-directive";
|
import { createDirectives, presetDirectiveConfigs } from "marked-directive";
|
||||||
import markedAlert from "marked-alert";
|
import markedAlert from "marked-alert";
|
||||||
import markedMermaid from "./mermaid";
|
import markedMermaid from "./mermaid.js";
|
||||||
import { gfmHeadingId } from "marked-gfm-heading-id";
|
import { gfmHeadingId } from "marked-gfm-heading-id";
|
||||||
import markedColumns from "./columns";
|
import markedColumns from "./columns.js";
|
||||||
import markedCodeBlockYamlTag from "./code-block-yaml-tag";
|
import markedCodeBlockYamlTag from "./code-block-yaml-tag.js";
|
||||||
import { iconDirective, setIconBase } from "./icon";
|
import { iconDirective, setIconBase } from "./icon.js";
|
||||||
import { cmdDirective } from "./cmd";
|
import { cmdDirective } from "./cmd.js";
|
||||||
|
|
||||||
// 使用 marked-directive 来支持指令语法
|
// 使用 marked-directive 来支持指令语法
|
||||||
const marked = new Marked()
|
const marked = new Marked()
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
import type {MarkedExtension} from "marked";
|
import type {MarkedExtension} from "marked";
|
||||||
import mermaid from "mermaid";
|
|
||||||
|
|
||||||
mermaid.initialize({
|
|
||||||
theme: 'dark'
|
|
||||||
});
|
|
||||||
|
|
||||||
export default function markedMermaid(): MarkedExtension {
|
export default function markedMermaid(): MarkedExtension {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user