refactor(markdown): Replace using with try-finally
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user