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;
|
let globalIconPrefix: string | undefined = undefined;
|
||||||
function overrideIconPrefix(path?: string) {
|
function overrideIconPrefix(path?: string) {
|
||||||
globalIconPrefix = path;
|
globalIconPrefix = path;
|
||||||
return {
|
return () => {
|
||||||
[Symbol.dispose]() {
|
|
||||||
globalIconPrefix = undefined;
|
globalIconPrefix = undefined;
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,8 +94,12 @@ const marked = new Marked()
|
||||||
);
|
);
|
||||||
|
|
||||||
export function parseMarkdown(content: string, iconPrefix?: string): string {
|
export function parseMarkdown(content: string, iconPrefix?: string): string {
|
||||||
using prefix = overrideIconPrefix(iconPrefix);
|
const restore = overrideIconPrefix(iconPrefix);
|
||||||
|
try {
|
||||||
return marked.parse(content.trimStart()) as string;
|
return marked.parse(content.trimStart()) as string;
|
||||||
|
} finally {
|
||||||
|
restore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { marked };
|
export { marked };
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"rootDir": "./src",
|
"rootDir": "./src",
|
||||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||||
"types": ["node", "jest"]
|
"types": ["node", "jest"],
|
||||||
},
|
},
|
||||||
"include": ["src/**/*"],
|
"include": ["src/**/*"],
|
||||||
"exclude": ["node_modules", "dist"]
|
"exclude": ["node_modules", "dist"],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue