Skip to content

Commit

Permalink
fix: correct parsing of \n in inline code (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
d3m1d0v authored Oct 9, 2023
1 parent 7fd74af commit ebf37d7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/core/markdown/MarkdownParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ export class MarkdownParser implements Parser {

if (tokenSpec.noCloseToken) {
this.openMark(schemaSpec.create(attrs));
this.addText(withoutTrailingNewline(yfmToken.content));
let {content} = yfmToken;
if (!tokenSpec.code) content = withoutTrailingNewline(content);
this.addText(content);
this.closeMark(schemaSpec);

return;
Expand Down
1 change: 1 addition & 0 deletions src/core/types/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ParserToken {
// То есть контент лежит в поле content токена, а не между открывающим и закрывающим токенами.
noCloseToken?: boolean;
ignore?: boolean;
code?: boolean;
/** only for tokens with type=block */
prepareContent?: (content: string) => string;
}
4 changes: 4 additions & 0 deletions src/extensions/markdown/Code/Code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ describe('Code extension', () => {
it('should parse html - code tag', () => {
parseDOM(schema, '<code>code inline</code>', doc(p(c('code inline'))));
});

it('should parse new line in code', () => {
same('`\\n`', doc(p(c('\\n'))));
});
});
2 changes: 1 addition & 1 deletion src/extensions/markdown/Code/CodeSpecs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const CodeSpecs: ExtensionAuto = (builder) => {
escape: false,
},
fromYfm: {
tokenSpec: {name: codeMarkName, type: 'mark', noCloseToken: true},
tokenSpec: {name: codeMarkName, type: 'mark', code: true, noCloseToken: true},
tokenName: 'code_inline',
},
}),
Expand Down

0 comments on commit ebf37d7

Please sign in to comment.