return prefix size of Indented code in gfm
See original GitHub issueSubject 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:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
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.
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 matchesdoc.slice(code.position.start.offset, code.position.start.offset + 6)
, it’s fenced code c) search for the substring you want to warn about indoc.slice(code.position.start.offset, code.position.end.offset)
to infer the location