Skip to content

Commit e6b5aa4

Browse files
committed
Fixed unnecessary space issue in code blocks
1 parent b5288cb commit e6b5aa4

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"typescript": "^3.9.7"
4646
},
4747
"dependencies": {
48-
"highlight.js": "^10.2.0",
48+
"highlight.js": "^10.4.1",
4949
"minimist": "^1.2.5",
5050
"uuid": "^8.3.0"
5151
}

src/parser/components/CodeBlock.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,22 @@ export default abstract class CodeBlock {
1818
return spottedSeqs;
1919
}
2020

21-
public static extract(opening: t_spottedSeq, closing: t_spottedSeq, context: string): Element {
21+
public static extract(opening: t_spottedSeq, closing: t_spottedSeq, context: string, baseindent: number): Element {
2222
let str: string = Utils.getBetween(opening, closing, context);
23-
let strArr: string[] = str.split('\n');
23+
24+
let strArr: string[] = str
25+
.split('\n')
26+
.map((line: string) => line.substring(baseindent, line.length));
27+
2428
let lang: Language | undefined = hljs.getLanguage(strArr[0]);
29+
2530
strArr.shift();
2631

2732
let code: string = strArr.join('\n');
2833

29-
let hlcode: string = lang && lang.aliases ? hljs.highlight(lang.aliases[0], code).value :
30-
hljs.highlightAuto(code).value;
34+
let hlcode: string = lang && lang.aliases ?
35+
hljs.highlight(lang.aliases[0], code).value :
36+
hljs.highlightAuto(code).value;
3137

3238
let pre: Element = new Element('pre', [ { key: 'class', value: 'ld-pre hljs' } ]);
3339
let codeel: Element = new Element('code', [], hlcode);

src/parser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ export default class Parser {
359359
let matchRes: t_spottedSeq[] | false = CodeBlock.match(this.idx, this.input);
360360
if (!matchRes) return false;
361361

362-
let extractRes: Element = CodeBlock.extract(matchRes[0], matchRes[1], this.input);
362+
let extractRes: Element = CodeBlock.extract(matchRes[0], matchRes[1], this.input, this.baseindent);
363363

364364
let sectionStr: string = Utils.getBetween(matchRes[0], matchRes[1], this.input);
365365

0 commit comments

Comments
 (0)