Skip to content
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

Closed
lukasoppermann opened this issue Jan 15, 2014 · 7 comments
Closed

Markdown header issue. #2143

lukasoppermann opened this issue Jan 15, 2014 · 7 comments

Comments

@lukasoppermann
Copy link

Hey,

I think I found a "bug" in markdown.

When I type the following, only the ===== gets classes for being a header, and the text Header 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.

Header
======
@cben
Copy link
Contributor

cben commented Jan 15, 2014

See #839

2014/1/15 Lukas Oppermann notifications@github.com

Hey,

I think I found a "bug" in markdown.

When I type the following, only the ===== gets classes for being a
header, and the text Header 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.

Header


Reply to this email directly or view it on GitHubhttps://github.com//issues/2143
.

@lukasoppermann
Copy link
Author

But this does not fix it, does it?

@marijnh
Copy link
Member

marijnh commented Oct 20, 2014

Nope, lookahead beyond the current line is still unimplemented.

@marijnh marijnh closed this as completed Oct 20, 2014
@lukasoppermann
Copy link
Author

Is there an option to disable this kind of headline?

@brondsem
Copy link
Contributor

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()}});

@tobloef
Copy link

tobloef commented Nov 10, 2016

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.

@dwelle
Copy link
Contributor

dwelle commented Jul 21, 2017

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 ------ setext line.

Also not sure if it doesn't have some major performance implications. Do we have some perf benchmarks we could run on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants