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.

return prefix size of Indented code in gfm

See original GitHub issue

Subject of the feature

return prefix size of Indented code in gfm

Problem

Currently there is no way to know that code blocks were generating from ``` or indented. While we are trying to add some custom text linting in code block, and found that might causing some problem if we need to calculating the column position of text.

For example we’ll get same column position of below both two code syntax:

# heading
```
code
```
# heading
    code

If in second syntax, there is anyway to get the length of line prefix. or any flag to know that code block was indented. It’ll make calculating correct column position easier.

Expected behavior

    code

will return something like linePrefix: 4 in position object while parsing code that Indented.

Alternatives

currently we patch how micromark handling codeIndented to adding line prefix length into codeIndented token then get it in compiler.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
TimWeicommented, Apr 2, 2021

we currently work around is to adding linePrefix(which should be first token of indented code) token length into code ast if it exists. and thinking that it might be a useful information to anyone who need to locating code text position.

but yeah. this is over perspective of what ast should do.

thanks for your quick reply and time. really appreciate it.

1reaction
wooormcommented, Apr 2, 2021

Thanks for clarifying. The code you post is working as expected from the perspective of this project.

For solutions to your problem, here are some ideas:

a) put the location of the warnings you want to show at the code level, perhaps that’s specific enough b) detect the style of a code block with /^[ ]{0,3}([~`])\1{2}/: if this regex matches doc.slice(code.position.start.offset, code.position.start.offset + 6), it’s fenced code c) search for the substring you want to warn about in doc.slice(code.position.start.offset, code.position.end.offset) to infer the location

Read more comments on GitHub >

github_iconTop Results From Across the Web

micromark extension to support GFM footnotes - GitHub
Function that can be called to get an HTML extension for micromark (passed in htmlExtensions ). htmlOptions. Configuration (optional). htmlOptions.clobberPrefix.
Read more >
micromark-extension-gfm-footnote - npm
A function that can be called to get an extension to compile them to HTML (can be passed in htmlExtensions ). htmlOptions.clobberPrefix. Prefix...
Read more >
Read Guide to Markdown Mode for Emacs - Leanpub
Introduction. Markdown Mode Screenshot. This Guide describes how to install, use, and customize Markdown Mode, a major mode for editing Markdown-formatted ...
Read more >
Formatting Guide - Reddit Help
The first is by indenting the entire block of code four spaces. Written: hashOut.data = hashes + SSL_MD5_DIGEST_LEN; hashOut.length = ...
Read more >
Markdown Mode for Emacs - Jason Blevins
When installed this way, the major modes markdown-mode and gfm-mode will be ... Prefix this command by C-u C-u to increase the indentation...
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