Skip to content

feat: Add code block indentation token support#324

Draft
jahvon wants to merge 1 commit intocharmbracelet:masterfrom
jahvon:patch2
Draft

feat: Add code block indentation token support#324
jahvon wants to merge 1 commit intocharmbracelet:masterfrom
jahvon:patch2

Conversation

@jahvon
Copy link
Contributor

@jahvon jahvon commented Aug 3, 2024

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 #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 #101
Depends on #334

@jahvon
Copy link
Contributor Author

jahvon commented Aug 3, 2024

🤔 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
Copy link
Contributor Author

jahvon commented Aug 3, 2024

🤔 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

@bashbunni bashbunni self-assigned this Aug 5, 2024
@bashbunni
Copy link
Contributor

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

@jahvon
Copy link
Contributor Author

jahvon commented Aug 5, 2024

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.

@bashbunni
Copy link
Contributor

@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
Copy link
Contributor

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

@jahvon
Copy link
Contributor Author

jahvon commented Aug 7, 2024

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 #334 first. That fix isolates another change needed to get this working.

@jahvon jahvon marked this pull request as draft September 10, 2024 02:09
@jahvon jahvon changed the title Add code block indentation token support feat: Add code block indentation token support Sep 10, 2024
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
charmbracelet#299
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

block_quote does not display margin correctly

2 participants