Skip to content

Commit

Permalink
feat: #999 调整对单行长文本的判定逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Dec 17, 2024
1 parent e30e7ee commit 511b751
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import NestedError, { $expectTarget, $expectInherit, $expectInstance } from './u
import CryptoJS from 'crypto-js';
import SyntaxBase from './core/SyntaxBase';
import ParagraphBase from './core/ParagraphBase';
import { PUNCTUATION, longTextReg, imgBase64Reg, imgDrawioXmlReg } from './utils/regexp';
import { PUNCTUATION, longTextReg, base64Reg, imgBase64Reg, imgDrawioXmlReg } from './utils/regexp';
import { escapeHTMLSpecialChar } from './utils/sanitize';
import Logger from './Logger';
import { configureMathJax } from './utils/mathjax';
Expand Down Expand Up @@ -252,6 +252,11 @@ export default class Engine {
this.cachedBigData[cacheKey] = m2;
return `${m1}${cacheKey}}`;
});
$md = $md.replace(base64Reg, (whole, m1, m2) => {
const cacheKey = `bigDataBegin${this.hash(m2)}bigDataEnd`;
this.cachedBigData[cacheKey] = m2;
return `${m1}${cacheKey}}`;
});
$md = $md.replace(longTextReg, (whole, m1, m2) => {
const cacheKey = `bigDataBegin${this.hash(m2)}bigDataEnd`;
this.cachedBigData[cacheKey] = m2;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export const imgBase64Reg = /(\[[^\n]*?\]\(data:image\/[a-z]{1,10};base64,)([^)]
export const base64Reg = /(data:image\/[a-z]{1,10};base64,)([0-9a-zA-Z+/]+)/g;

// 匹配内容非常多的单行文本
export const longTextReg = /([^\n]{100})([^\n]{500,})/g;
export const longTextReg = /([^\n]{100})([^\n]{5900,})/g;

// 匹配图片{}里的data-xml属性
export const imgDrawioXmlReg = /(!\[[^\n]*?\]\([^)]+\)\{[^}]* data-xml=)([^}]+)\}/g;
Expand Down

0 comments on commit 511b751

Please sign in to comment.