Skip to content

Commit

Permalink
fix(@lexical/markdown): markdown import code block with prefix (#5780)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelint authored Apr 23, 2024
1 parent ddbadb9 commit 4a318ee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/lexical-markdown/src/MarkdownImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {IS_APPLE_WEBKIT, IS_IOS, IS_SAFARI} from 'shared/environment';
import {PUNCTUATION_OR_SPACE, transformersByType} from './utils';

const MARKDOWN_EMPTY_LINE_REG_EXP = /^\s{0,3}$/;
const CODE_BLOCK_REG_EXP = /^```(\w{1,10})?\s?$/;
const CODE_BLOCK_REG_EXP = /^[ \t]*```(\w{1,10})?\s?$/;
type TextFormatTransformersIndex = Readonly<{
fullMatchRegExpByTag: Readonly<Record<string, RegExp>>;
openTagsRegExp: RegExp;
Expand Down
2 changes: 1 addition & 1 deletion packages/lexical-markdown/src/MarkdownTransformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export const CODE: ElementTransformer = {
'```'
);
},
regExp: /^```(\w{1,10})?\s/,
regExp: /^[ \t]*```(\w{1,10})?\s/,
replace: createBlockNode((match) => {
return $createCodeNode(match ? match[1] : undefined);
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ describe('Markdown', () => {
html: '<pre spellcheck="false"><span style="white-space: pre-wrap;">Code</span></pre>',
md: '```\nCode\n```',
},
{
// Import only: prefix tabs will be removed for export
html: '<pre spellcheck="false"><span style="white-space: pre-wrap;">Code</span></pre>',
md: '\t```\nCode\n```',
skipExport: true,
},
{
// Import only: prefix spaces will be removed for export
html: '<pre spellcheck="false"><span style="white-space: pre-wrap;">Code</span></pre>',
md: ' ```\nCode\n```',
skipExport: true,
},
{
// Import only: extra empty lines will be removed for export
html: '<p><span style="white-space: pre-wrap;">Hello</span></p><p><span style="white-space: pre-wrap;">world</span></p>',
Expand Down

0 comments on commit 4a318ee

Please sign in to comment.