refactor(markdown): Replace `using` with try-finally

This commit is contained in:
hyper 2026-06-25 20:33:08 +08:00
parent 1a4ae417fe
commit f19c7ff77c
2 changed files with 10 additions and 8 deletions

View File

@ -10,10 +10,8 @@ import markedCodeBlockYamlTag from "./code-block-yaml-tag";
let globalIconPrefix: string | undefined = undefined;
function overrideIconPrefix(path?: string) {
globalIconPrefix = path;
return {
[Symbol.dispose]() {
globalIconPrefix = undefined;
},
return () => {
globalIconPrefix = undefined;
};
}
@ -96,8 +94,12 @@ const marked = new Marked()
);
export function parseMarkdown(content: string, iconPrefix?: string): string {
using prefix = overrideIconPrefix(iconPrefix);
return marked.parse(content.trimStart()) as string;
const restore = overrideIconPrefix(iconPrefix);
try {
return marked.parse(content.trimStart()) as string;
} finally {
restore();
}
}
export { marked };

View File

@ -15,8 +15,8 @@
"outDir": "./dist",
"rootDir": "./src",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"types": ["node", "jest"]
"types": ["node", "jest"],
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
"exclude": ["node_modules", "dist"],
}