glamour icon indicating copy to clipboard operation
glamour copied to clipboard

feat: Add code block indentation token support

Open jahvon opened this issue 1 year ago • 7 comments

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 Screenshot 2024-08-03 at 12 17 05 AM

Code block with just an indent token Screenshot 2024-08-03 at 12 17 34 AM

Fixes https://github.com/charmbracelet/glamour/issues/101 Depends on https://github.com/charmbracelet/glamour/pull/334

jahvon avatar Aug 03 '24 12:08 jahvon

🤔 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?

jahvon avatar Aug 03 '24 13:08 jahvon

🤔 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

jahvon avatar Aug 03 '24 14:08 jahvon

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

bashbunni avatar Aug 05 '24 18:08 bashbunni

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

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 avatar Aug 05 '24 19:08 jahvon

@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. image

bashbunni avatar Aug 05 '24 19:08 bashbunni

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

bashbunni avatar Aug 05 '24 19:08 bashbunni

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.

jahvon avatar Aug 07 '24 01:08 jahvon