-
Notifications
You must be signed in to change notification settings - Fork 0
feat: extract tviewmd markdown renderer and wire into tui2 #183
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f0d3285
feat: extract tviewmd markdown renderer and wire into tui2
buchenberg dfb1cc8
feat: extract tviewmd markdown renderer and wire into tui2
buchenberg af44831
Merge branch 'feat/tviewmd' of https://github.com/buchenberg/yaah int…
buchenberg e94bbd6
fix: address PR review — dynamic markdown width, stale docs, plan cle…
buchenberg 2067788
docs(architecture): add deep-dive review of tui2 internals
buchenberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,32 @@ | ||
| package tui2 | ||
|
|
||
| import ( | ||
| "strings" | ||
| "sync" | ||
|
|
||
| "charm.land/glamour/v2" | ||
| "github.com/buchenberg/tviewmd" | ||
| "github.com/rivo/tview" | ||
| ) | ||
|
|
||
| var ( | ||
| rendererOnce sync.Once | ||
| renderer *glamour.TermRenderer | ||
| ) | ||
|
|
||
| // initRenderer lazily creates a glamour renderer on first use. We use | ||
| // terminal256 formatting; the ANSI output is translated to tview color | ||
| // tags via tview.TranslateANSI at render time. | ||
| func initRenderer() { | ||
| rendererOnce.Do(func() { | ||
| r, err := glamour.NewTermRenderer( | ||
| glamour.WithStandardStyle("dark"), | ||
| glamour.WithWordWrap(80), | ||
| glamour.WithEmoji(), | ||
| glamour.WithChromaFormatter("terminal256"), | ||
| glamour.WithPreservedNewLines(), | ||
| ) | ||
| if err == nil { | ||
| renderer = r | ||
| } | ||
| }) | ||
| // renderMarkdown converts markdown to tview color-tagged text using the | ||
| // tviewmd native renderer (goldmark parser + tview tag backend). The | ||
| // output is suitable for a tview.TextView with SetWrap(true). | ||
| func renderMarkdown(md string, width int) string { | ||
| if md == "" { | ||
| return "" | ||
| } | ||
| if width <= 0 { | ||
| width = 80 | ||
| } | ||
| return tviewmd.Render(md, tviewmd.Options{Width: width}) | ||
| } | ||
|
|
||
| // renderMarkdown converts markdown to tview color-tagged text using | ||
| // glamour for formatting and tview.TranslateANSI to convert the ANSI | ||
| // output into tview's native color tags. Falls back to the raw text if | ||
| // the renderer is unavailable. | ||
| func renderMarkdown(md string) string { | ||
| initRenderer() | ||
| if renderer == nil { | ||
| return md | ||
| // messageWidth returns a usable width for markdown rendering from the | ||
| // messages pane, defaulting to 80 if the pane hasn't been laid out yet. | ||
| func messageWidth(tv *tview.TextView) int { | ||
| if tv == nil { | ||
| return 80 | ||
| } | ||
| out, err := renderer.Render(md) | ||
| if err != nil { | ||
| return md | ||
| _, _, w, _ := tv.GetInnerRect() | ||
| if w <= 0 { | ||
| return 80 | ||
| } | ||
| out = strings.TrimSpace(out) | ||
| return tview.TranslateANSI(out) | ||
| return w | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major
Fix table sizing in the width-aware renderer.
renderMarkdownpasseswidthtotviewmd, buttviewmdv0.1.0 calculates table columns from cell contents and does not useOptions.Width. Wide tables are therefore wrapped byTextView, which breaks row alignment. (raw.githubusercontent.com)This is the same unresolved issue from the previous review. Patch or upgrade the dependency, and add a narrow-width table regression test.
Verification script
This assessment uses the pinned
tviewmd v0.1.0implementation and the previous review finding.🤖 Prompt for AI Agents