Repository navigation
Fix(tui): keep code literal in the Glamour preview - #40
Merged
Merged
Conversation
The preview rewrote wikilinks, embeds, task states and callouts inside code, so `[[Note|alias]]` displayed as its alias. Links in code could be followed and a task in a fence could be toggled. Code regions now come from goldmark, the parser Glamour uses, so they hold in quotes, list items and indented blocks. splitBlocks follows the CommonMark fence rules, so a fence nested in a longer one stays whole. Inline code loses its padding in the default style, which has no background to fill. Pipes in a table's code spans no longer split cells.
Each block is parsed alone, so content indented under a list item after a blank line read as code and lost its links, embed card, math or task. List blocks now hold that content, past blank lines and through fences. An embed, video link or math line stays its own block and keeps its card. An item's paragraphs stay on separate rows, since Glamour runs them together, and links anywhere in an item are offered on its row. A code line that looked like a list item shifted the rows after it, so x could toggle the wrong task. Items now skip code, and a guard keeps such a row from passing for an item. Guards come off last in mapRows, so later row steps can't touch code. Links are scanned on the source text and dropped if they start or end in code. Code pipes hold in any table goldmark finds. Fence indents are up to three spaces. vault.CodeMask is gone, as nothing needs it now.
Merging a list into one block mapped a paragraph under an item to the item's first row: Enter there said "No link on this row", and the link only worked from the item. Each paragraph line now carries a guard through rendering, so its row leads to its own source line and offers its own links. x on such a row still toggles the item's task. i and a click in split mode landed one line above a row, on main too, since GotoLine counts from one and srcLine from zero. A blank line before a quote under an item keeps its blank row.
…th (#39) Mermaid text diagrams were cut off at the pane's edge, and the library's text layout also dropped edge labels and edges back to earlier nodes. zn keeps the library's parser and now draws flowcharts and state diagrams itself: a row of boxes when one fits, otherwise a column with wrapped labels. Any edge not drawn between neighbouring boxes is listed under its source. A statement the parser cannot read in full shows the block's source with a note, so nothing goes missing without saying so. IDs in any script, comments, entities and the common edge spellings are read. Tables in the reading view also change. Aliased links keep columns in line, and a wrapped alias shows no token brackets. In the zen style an alias stays in one cell, wide cells wrap, and tables with no outer pipes render.
Note text now shows as text and does not act on the terminal. The filter lives in internal/termsafe and runs on every TUI frame and, when stdout or stderr is a terminal, on CLI output. Pipes and files keep every byte. The editor, both reading views and the views that list note text draw a control rune as a one-cell picture such as a visible ESC, so the cursor stays on its rune and a note's own colours stay out of the terminal. Opening a note with bytes that are not valid UTF-8, or with CRLF line ends, no longer marks it changed, so quitting leaves the file as it is until a real edit. Very long words are broken before Glamour, whose word wrap is quadratic in a word's length.
…#41) Sequence, class and ER diagrams came from the library's text renderer, which clipped long messages and dropped relationships even when the diagram fit. A sequence diagram is now drawn with every message whole, or shows its source with a note when it cannot be, and a class or ER diagram shows its source with a note rather than a drawing that loses part of it.
…6e' into HEAD # Conflicts: # internal/tui/previewglamour.go
1 task
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The default Glamour preview rewrites Markdown before rendering, and those rewrites ran inside code. Inline code holding
[[Bookmarks|bookmarks]]displayed asbookmarkswith stray spaces. Fences had the same problem, and more:⟦x⟧lost its brackets.- [ ]inside a fence could be toggled, which would have edited the code.splitBlocksclosed a fence on any fence line, so a four-backtick block holding a three-backtick fence broke apart and its contents rendered as normal text.Fix
[`name`](url), keeps its label and target.splitBlocksfollows the CommonMark fence rules: a closer matches its opener, a one-line```inline```is not a fence, and a fence indent is up to three spaces, no tab.xthere still toggles the item's task.xtoggles the task on that row.iand a click in split mode now land on the row's own line. They landed one line above it, onmaintoo, sinceGotoLinecounts from one andsrcLinefrom zero.For review
|inside code in a table no longer splits the cell, so`[[Note|alias]]`stays whole. From its code, the desktop protects pipes in math only and looks like it would still split this; I did not run it.stripCodeContent: this follows what Glamour renders, not the desktop's link scan, so preview and desktop scan can disagree on these shapes:\`[[R|r]]\`is a live link here.internal/vaultis not touched by this PR, sowikiCodeMaskand renames behave as before.#tag. The text stays exact, and blocks that are only code are not affected.xon a code row inside a task item toggles that item, like any of its other rows.mainhas one. A quote keeps its blank row.*,_,~, a bare URL orwww.carries no row marker, because one would change how it reads. Its links show on the row before it, and that row leads to the earlier line.main.The
zenpreview style is a separate renderer and is not changed here.Testing
internal/tui/previewcode_test.go. They failed before the fix.go test ./...andgo vet ./...pass.89f5f31in a scratch worktree, using the resolution below, passesgo vetandgo test ./internal/tui/. Earlier commits on this PR also passed pairwise with PR 42 ata6a0a9aand PR 43 at4262240; those two have not been re-run on this head, and all the PRs merged together has not been run here.xtoggled the right task in the saved file. On this change: item paragraphs stayed apart, Enter on an ordered item's paragraph row (See alias) opened its link,xon a paragraph row under a task checked that task, andion that row landed on its own line.Merging with PR 39 and 41
previewglamour.goconflicts in four hunks. CallguardCodebeforetokenHiderinprepareMarkdown, and keepunguardRowlast inmapRows, afterfinishTokensandpostStyleTableRow, because those two strip⟦⟧and code's are still guarded at that point. BothmapRowshunks take this PR's side.