Danon
September 20, 2022, 7:47am
1
I think markdown parser in code mirror incorrectly parses strike through.
Given these values:
~~word~~
~~ word~~
~~word ~~
~~ word ~~
Only the first one (without any surrounding spaces) should be striked-through, according to markdown. But in codemirror, they all are.
marijn
September 20, 2022, 8:19am
2
Markdown has no strike-through, and the GFM spec is entirely silent on this. Which definition are you working from?
Danon
September 20, 2022, 10:39am
3
I used this as an extension
import {defineLanguageFacet, Language} from '@codemirror/language';
import {commonmarkLanguage, markdown} from '@codemirror/lang-markdown';
import {Strikethrough, Table} from '@lezer/markdown';
function language(parser) {
const facet = defineLanguageFacet({block: {open: "<!--", close: "-->"}});
const documentType = parser.nodeSet.types.find(type => type.name === "Document");
return new Language(facet, parser, documentType);
}
const elements = [Table, Strikethrough];
const flavouredParser = commonmarkLanguage.parser.configure(elements);
export default [
markdown({
base: language(flavouredParser),
codeLanguages: [],
}),
];
And it appears it treats ~~ word~~
as strike throught I think.
marijn
September 20, 2022, 11:27am
4
No I mean do you know where the behavior you’re looking for is specified?
Danon
September 20, 2022, 11:30am
5
I’m sorry, unfortunately I don’t know
I just noticed that’s how JetBrains IDE render ~~
, and also CommonMark library in PHP, and also Github.
So I would start looking under “CommonMark specification” or “Extended markdown specification”
I would expect that ~~
should work very similarly to **
, which means **text**
is treated as bold, but **text **
/** text**
aren’t.
marijn
September 20, 2022, 12:31pm
6
CommonMark does not define strikethrough, and GFM, the ‘spec’ that Github created for their extensions (and which I linked before) doesn’t say anything about in which situations these markers should be ignored.
This patch adds logic similar to what emphasis marks use.
committed 12:30PM - 20 Sep 22 UTC
FIX: In the stikethrough extension, ignore opening marks with a space after and
… closing marks with a space before them.
See https://discuss.codemirror.net/t/improper-parsing-of-strike-through/5035
Danon
September 20, 2022, 1:28pm
7
Cool, thank you very much!
Is it released, so that I can start using it immediately?
marijn
September 21, 2022, 7:51am
8
I’ve tagged @lezer /markdown 1.0.2 with this fix.