question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Line Highlighting on Code Fences

See original GitHub issue

I like to add line highlights to my code fences using the syntax described here.

This breaks the highlighter with language-markdown. I’ve solved it by replacing the code fence “begin” regex in grammars/language-markdown.json. e.g. for JavaScript:

         {
-         "begin": "^\\s*([`~]{3,})\\s*(\\{?)((?:\\.?)(?:javascript|js|jsx))(?=( |$))\\s*([^`\\}]*)(\\}?)$",
+         "begin": "^\\s*([`~]{3,})\\s*(\\{?)((?:\\.?)(?:javascript|js|jsx)(?:\\{[0-9,\\-\\s]*\\})?)(?=( |$))\\s*([^`\\}]*)(\\}?)$",
          "beginCaptures": {
            "1": {
              "name": "punctuation.md"
            },
            "2": {
              "name": "punctuation.md"
            },
            "3": {
              "name": "language.constant.md"
            },
            "5": {
              "patterns": [
                {
                  "include": "#special-attribute-elements"
                }
              ]
            },
            "6": {
              "name": "punctuation.md"
            }
          },

Is this the best way to handle this? If so, I can submit a PR with these regexes if you have any interest in supporting this line highlights syntax. It’s not really part of any markdown standard, and I’m not sure how widespread this practice is, so I understand if it’s more trouble than it’s worth!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
burodepepercommented, May 30, 2016

@eloquently See the commit above. This fixes your issue, but I’ve chosen not to apply any scopes to the line-numbers per se. I think it’s rather premature and as of yet unnecessary to make a decision in that area. I’m still working on a few other changes in the dev branch, but expect this change to be part of the next update to the package. I’m marking this as closed, because I think this solution is at least good enough.

0reactions
burodepepercommented, May 23, 2016

@zpao Thanks for your input!

I think your last remark about allowing anything in the info-string is what I’m probably going for. I saw some interesting ideas about the {key=value} attribute syntax on talk.commonmark.org (wasn’t aware of that, thanks) too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding Line Highlights to Markdown Code Fences
One thing I needed recently was an unobtrusive way to highlight lines of code, while keeping it readable (and of course, inside Markdown)....
Read more >
Provide hl_lines option in code fences - support - HUGO
I'm aware that Hugo allows the hl_lines option to be passed to Pygments using this syntax: {{< highlight js "linenos=inline,hl_lines=2 3" > ...
Read more >
Extended Syntax - Markdown Guide
Many Markdown processors support syntax highlighting for fenced code blocks. This feature allows you to add color highlighting for whatever language your code...
Read more >
Markdown fences / code blocks background highlighting in VS ...
In Sublime Text, the extension MarkdownEditing has an option to Set Syntax: Markdown GFM . This causes the markdown code fences to have...
Read more >
Code with line numbers | Just the Docs - GitHub Pages
1 or earlier) for line numbers from highlighted code – both when using Kramdown code fences and when using Liquid highlight tags. To...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found