Skip to content

Commit c9e055a

Browse files
authored
Merge pull request #289 from qiaogaojian/fix/pre_post
fix: {pre} {post} {label} etc are not working begin with ‘run-’
2 parents adf40f3 + 162f06e commit c9e055a

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ data.json
2020

2121
# Exclude macOS Finder (System Explorer) View States
2222
.DS_Store
23+
*.log

src/transforms/TransformCode.ts

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

0 commit comments

Comments
 (0)