Skip to content

Commit

Permalink
fix: 修复为支持引用嵌套导致页面报错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Sep 23, 2024
1 parent 52f01c9 commit e930143
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,15 @@ export default class Engine {
$md = this.$beforeMakeHtml($md);
$md = this.$dealParagraph($md);
$md = this.$afterMakeHtml($md);
this.$fireHookAction($md, 'paragraph', '$cleanCache');
$md = this.$deCacheBigData($md);
return $md;
}

makeHtmlForBlockquote(md) {
let $md = md;
$md = this.$dealParagraph($md);
$md = this.$afterMakeHtml($md);
$md = this.$fireHookAction($md, 'paragraph', 'afterMakeHtml');
return $md;
}

Expand Down
11 changes: 9 additions & 2 deletions src/core/hooks/Blockquote.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,22 @@ export default class Blockquote extends ParagraphBase {
return this.getCacheWithSpace(testHasCache, match);
}
let handledHtml = `<blockquote data-sign="${sign}_${lineCount}" data-lines="${lineCount}">`;
const $content = content.replace(/^([ \t]*>)/gm, '');
const htmlDomTest = content.split(/\n</);
// 如果引用内容后面有html dom结构,就认为这不是引用内容
let after = '';
if (htmlDomTest.length > 1) {
after = `\n<${htmlDomTest.slice(1).join('\n<')}`;
}
const $content = htmlDomTest[0].replace(/^([ \t]*>)/gm, '');
handledHtml += this.$engine.makeHtmlForBlockquote($content);
// 标签闭合
handledHtml += '</blockquote>';
return this.getCacheWithSpace(this.pushCache(handledHtml, sign, lineCount), match);
return `${this.getCacheWithSpace(this.pushCache(handledHtml, sign, lineCount), match)}${after}`;
});
}

makeHtml(str, sentenceMakeFunc) {
// return str;
return this.handleMatch(str, sentenceMakeFunc);
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/hooks/Footnote.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class Footnote extends ParagraphBase {
afterMakeHtml(str) {
const footNotes = this.getFootNote();
const $str = str.replace(/\0~fn#([0-9]+)#\0/g, (match, num) => footNotes[num].fn);
this.$cleanCache();
// this.$cleanCache();
return $str;
}

Expand Down
5 changes: 4 additions & 1 deletion src/core/hooks/InlineCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ export default class InlineCode extends ParagraphBase {
let $str = str;
if (Object.keys(CodeBlock.inlineCodeCache).length > 0) {
$str = $str.replace(/~~CODE([0-9a-zA-Z]+)\$/g, (match, sign) => CodeBlock.inlineCodeCache[sign]);
CodeBlock.inlineCodeCache = {};
}
return $str;
}

$cleanCache() {
CodeBlock.inlineCodeCache = {};
}

rule() {
const ret = { begin: '(`+)[ ]*', end: '[ ]*\\1', content: '(.+?(?:\\n.+?)*?)' };
ret.reg = compileRegExp(ret, 'g');
Expand Down
17 changes: 10 additions & 7 deletions src/sass/markdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,23 @@
overflow-x: auto;
}

blockquote {
color: $quoteColor;
padding: 10px 15px;
border-left: 10px solid $quoteBorderColor;
background: $quoteBackground;
}

p,
pre,
blockquote,
table {
margin: 0 0 $elementGap;
}

blockquote {
color: $quoteColor;
padding: 10px 15px;
border-left: 10px solid $quoteBorderColor;
background: $quoteBackground;
p, blockquote, table, pre, ul, ol{
margin: 0;
}
}

pre {
padding: 16px;
overflow: auto;
Expand Down

0 comments on commit e930143

Please sign in to comment.