New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown header issue. #2143
Comments
See #839 2014/1/15 Lukas Oppermann notifications@github.com
|
But this does not fix it, does it? |
Nope, lookahead beyond the current line is still unimplemented. |
Is there an option to disable this kind of headline? |
As a workaround, you can style the previous lines with this snippet in your own code. I'm not sure if there would be an appropriate place to include this as part of the built-in markdown mode. function updateSectionHeaderStyles(cm, change) {
var lines = cm.lineCount();
for (var i = Math.max(0, change.from.line-1); i <= Math.min(change.to.line+1, lines-1); i++) {
var line = cm.getLineHandle(i);
cm.removeLineClass(line, 'text', 'cm-header');
cm.removeLineClass(line, 'text', 'cm-header-1');
cm.removeLineClass(line, 'text', 'cm-header-2');
var lineTokens = cm.getLineTokens(i);
var tok = lineTokens[0];
if (!tok || !tok.type || tok.type.indexOf('header') === -1) {
// first token could be some spaces, try 2nd
tok = lineTokens[1];
}
if (tok && tok.type && tok.type.indexOf('header') !== -1
&& tok.string !== '#') { // not ATX header style, which starts with #
var classes = tok.type.
split(' ').
filter(function(cls) { return cls.indexOf('header') === 0; }).
map(function (cls) { return 'cm-' + cls; }).
join(' ');
var prev_line = cm.getLineHandle(i-1);
cm.addLineClass(prev_line, 'text', classes);
}
}
}
myCodeMirror.on("change", updateSectionHeaderStyles);
updateSectionHeaderStyles(myCodeMirror, {from: {line: 0}, to: {line: myCodeMirror.lineCount()}}); |
Any possibility of this issue getting reopened as a feature request? It would be very nice if the workaround posted by brondsem wasn't necessary. |
Made a quick naive fix in this branch over here. It's still not 100% CM-compliant, but it fixes styling for the line immediately before the Also not sure if it doesn't have some major performance implications. Do we have some perf benchmarks we could run on this? |
Hey,
I think I found a "bug" in markdown.
When I type the following, only the
=====
gets classes for being a header, and the textHeader
does not. I think either both should get this class or none of the two, or maybe the======
could get an additionally class, if neither of the above work. Otherwise it makes it hard to style correctly. Thanks.The text was updated successfully, but these errors were encountered: