-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Tabs are not preserved in raw output #3440
Labels
has PR
The issue has a Pull Request associated
Comments
Okay, I came up with a pretty nasty workaround. Other functions are the same, except for // This function exists strictly to eat the spaces as I go through tabs in the raw source
const advanceTabViaSpaceReplacement = (offset, raw, start, end) => {
while (start < end) {
const real = contents.charCodeAt(offset++)
const synthetic = raw.charCodeAt(start++)
if (
real === 0x09 && synthetic === 0x20 &&
raw.charCodeAt(start) === 0x20 &&
raw.charCodeAt(++start) === 0x20 &&
raw.charCodeAt(++start) === 0x20
) {
start++
}
}
return offset
}
// This function is modified from the version in the original comment
const visitList = (startOffset, parentOffset, tokens, parent) => {
for (const child of tokens) {
const nextIndex = parent.raw.indexOf(child.raw, parentOffset)
const innerStart = advanceTabViaSpaceReplacement(startOffset, parent.raw, parentOffset, nextIndex)
const outerStart = advanceTabViaSpaceReplacement(innerStart, child.raw, 0, child.raw.length)
parentOffset = nextIndex + child.raw.length
startOffset = outerStart
visit(innerStart, child)
}
return parentOffset
} |
Okay, here's the live version of what I did to resolve my issue, if you want to see. |
Should be fixed by #3438 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Marked version: v14.1.0
Describe the bug
Tabs are expanded to 4 spaces in the output.
To Reproduce
Steps to reproduce the behavior:
npx marked --tokens
against the raw version of https://github.com/MithrilJS/mithril.js/blob/7b819f354610d5102dc4c707cee2167eef7fbf47/assets/README.md1. Open `assets/logo.svg` in Inkscape.
)Expected behavior
Tabs should be present inside the nested bulleted list's raw output in raw form.
I was attempting to get proper column counting of offsets in a repo that (mostly) uses tabs for indentation (mainly for historical reasons), and this throws that off. The end goal is to try to get line numbers to catch docs issues better. My walker is inspired by discussion in #2134 and looks roughly like this:
It's that delta calculation in the third line that's tripping me up. I could work around it by rolling a delta adjustment function that considers source tabs as equal to 4 spaces in the output, but it'd be very awkward to write and rather long for what's already a pretty lengthy file to begin with.
Of course,
walkTokens
won't work directly, as I need to actually work with the structure itself to make deltas work properly.The text was updated successfully, but these errors were encountered: