refactor(markdown): Replace `using` with try-finally
This commit is contained in:
parent
1a4ae417fe
commit
f19c7ff77c
|
|
@ -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]() {
|
||||
return () => {
|
||||
globalIconPrefix = undefined;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -96,8 +94,12 @@ const marked = new Marked()
|
|||
);
|
||||
|
||||
export function parseMarkdown(content: string, iconPrefix?: string): string {
|
||||
using prefix = overrideIconPrefix(iconPrefix);
|
||||
const restore = overrideIconPrefix(iconPrefix);
|
||||
try {
|
||||
return marked.parse(content.trimStart()) as string;
|
||||
} finally {
|
||||
restore();
|
||||
}
|
||||
}
|
||||
|
||||
export { marked };
|
||||
|
|
|
|||
|
|
@ -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"],
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue