Skip to content

Commit 65b6410

Browse files
committed
fix: {pre} {post} {label} etc are not working when language annotation begin with ‘run-’
1 parent 80666cb commit 65b6410

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/transforms/TransformCode.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,19 @@ export function transformMagicCommands(app: App, srcCode: string) {
5656
* @returns The language of the code block.
5757
*/
5858
export function getCodeBlockLanguage(firstLineOfCode: string) {
59-
return getLanguageAlias(firstLineOfCode.split("```")[1].trim().split(" ")[0].split("{")[0])
59+
let currentLanguage: string = firstLineOfCode.split("```")[1].trim().split(" ")[0].split("{")[0];
60+
if (isStringNotEmpty(currentLanguage) && currentLanguage.startsWith("run-")) {
61+
currentLanguage = currentLanguage.replace("run-", "");
62+
}
63+
return getLanguageAlias(currentLanguage);
64+
}
65+
66+
/**
67+
* Check if a string is not empty
68+
*
69+
* @param str Input string
70+
* @returns True when string not empty, False when the string is Empty
71+
*/
72+
export function isStringNotEmpty(str: string): boolean {
73+
return !!str && str.trim().length > 0;
6074
}

0 commit comments

Comments
 (0)