feat: Add code block indentation token support
This change incorporates the specified indentation token when rendering code blocks. It includes fixes to how the margin and indentation tokens are rendered globally. When both are specified, the margin is rendered first as an empty space.
This PR is another attempt at adding the functionality from https://github.com/charmbracelet/glamour/pull/299
Code block with a margin & indent token
Code block with just an indent token
Fixes https://github.com/charmbracelet/glamour/issues/101 Depends on https://github.com/charmbracelet/glamour/pull/334
🤔 I don't understand the test failures here. The before/after looks the same in most cases. Is the spacing token I'm using different than the one used previously?
🤔 I don't understand the test failures here. The before/after looks the same in most cases. Is the spacing token I'm using different than the one used previously?
I fixed a bug related to this. The visible diff now is expected since the codeblock is being rendered with the MarginWriter that includes padding that wasn't there before. Would appreciate some help on figuring out how to updating the golden files to reflect this change if it sound reasonable
Hey @jahvon do you mind providing steps to repro? I've tried adding IndentToken: stringPtr("│ "), to the dark style and running $ cat ../README.md | go run ./stdin-stdout-custom-styles from the examples dir, but not seeing the indent token being rendered
Hey @jahvon do you mind providing steps to repro? I've tried adding
IndentToken: stringPtr("│ "),to the dark style and running$ cat ../README.md | go run ./stdin-stdout-custom-stylesfrom theexamplesdir, but not seeing the indent token being rendered
I've done something similar when testing this out. You'll also need to add Indent: uintPtr(1) to the style in order to get the token to show up. That brings up an interesting case though, should Indent default to 1 whenever IndentToken is set (without an explicit indent value)? Right now the indent token doesn't show up unless both fields are set.
@jahvon ah I see, thank you! We should probably clean that up at some point, but for now that's okay, we'll just have to include that in the docs.
I believe this PR also adds an extra space to the end of codeblocks. Ideally, we can sort that out so it doesn't cause any inconsistency for background colours.
If it's helpful for debugging, you can generate new golden files with go test ./... -update and you'll be able to see in the diff that there's some additional whitespace in the ansi sequences
Hey @bashbunni, I've done some refactoring to get spacing for code blocks to work a bit more like a block element. I think I got it to a decent state but would love to get the fix I'm proposing in https://github.com/charmbracelet/glamour/pull/334 first. That fix isolates another change needed to get this working.