Skip to content

Commit

Permalink
refactor: block-level formulas will be treated as inline when surroun…
Browse files Browse the repository at this point in the history
…ded by text(#712)
  • Loading branch information
imzbf committed Nov 15, 2024
1 parent 9709ce2 commit 5c9911a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/MdEditor/layouts/Content/markdownIt/katex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { mergeAttrs } from '~/utils/md-it';

const math_inline: ParserInline.RuleInline = (state, silent) => {
const delimiters = [
{ open: '$$', close: '$$' },
{ open: '$', close: '$' },
{ open: '\\[', close: '\\]' },
{ open: '\\(', close: '\\)' }
];
let match, token, pos;
Expand All @@ -25,7 +27,7 @@ const math_inline: ParserInline.RuleInline = (state, silent) => {
while (state.src[pos] === '\\') {
pos -= 1;
}
if ((match - pos) % 2 == 1) {
if ((match - pos) % 2 === 1) {
break;
}
match += delim.close.length;
Expand All @@ -48,9 +50,12 @@ const math_inline: ParserInline.RuleInline = (state, silent) => {
}

if (!silent) {
const inlineContent = state.src.slice(start, match);

// 创建数学公式 token
token = state.push('math_inline', 'math', 0);
token.markup = delim.open;
token.content = state.src.slice(start, match);
token.content = inlineContent;
}

state.pos = match + delim.close.length;
Expand Down

0 comments on commit 5c9911a

Please sign in to comment.