Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lua/markview/renderers/markdown/tostring.lua
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,21 @@ md_str.escape = function (match)
return char;
end

---@param match string
---@return string
md_str.strikethrough = function (match)
---|fS

if string.match(match, "%s+%~%~$") then
return match;
end

local removed = string.gsub(match, "^%~%~", ""):gsub("%~%~$", "");
return removed;

---|fE
end

---@param match string
---@return string
md_str.italic = function (match)
Expand Down Expand Up @@ -777,11 +792,14 @@ local emoji = lpeg.C( lpeg.P(":") * emoji_char^1 * lpeg.P(":") ) / md_str.emoji;
local hl_content = lpeg.P("\\=") + ( 1 - lpeg.P("=") );
local hl = lpeg.C( lpeg.P("==") * hl_content^1 * lpeg.P("==") ) / md_str.highlight;

local strike_content = lpeg.P("\\~") + ( 1 - lpeg.P("~") );
local strike = lpeg.C( lpeg.P("~~") * strike_content^1 * lpeg.P("~~") ) / md_str.strikethrough;

local any = lpeg.P(1);

local token = escape +
emoji + entity +
hl + block_ref + embed + internal +
hl + strike + block_ref + embed + internal +
email + auto +
footnote + img + hyperlink +
code +
Expand Down
34 changes: 34 additions & 0 deletions test/tostring_strikethrough_width.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
; Strikethrough markers in tables — tostring column width
Strikethrough delimiters (`~~text~~`) are concealed by the renderer, so the
column-width calculation in `renderers/markdown/tostring.lua` must strip them
too. If it doesn't, each `~~` pair adds 2 characters (4 per `~~text~~` span) to
the computed width, so the calculated width is larger than what is drawn and the
right border drifts to the right.
Open this file and check that every right border lines up. The strikethrough
rows should align exactly with the plain control rows below them.
### Single strikethrough span
| Case | Example |
|--------------------------|----------------------|
| Strikethrough word | ~~gone~~ text |
| Strikethrough phrase | ~~all of this~~ here |
| Plain (control, same len)| xxxxxxx text |
| Plain (control) | just normal text |
### Multiple spans in one cell
| Case | Example |
|-------------------------|----------------------------|
| Two spans | ~~one~~ and ~~two~~ done |
| Span at end of cell | keep ~~this dropped~~ |
| Plain (control) | one and two done |
### Strikethrough mixed with other emphasis
| Case | Example |
|----------------------------|--------------------------|
| Strike + bold | ~~old~~ **new** |
| Strike + italic | ~~old~~ *new* |
| Strike + code | ~~old~~ `new()` |
| Plain (control) | old new |
### Escaped tildes stay literal (not strikethrough)
| Case | Example |
|-----------------------|--------------------|
| Escaped tilde pair | a \~\~literal\~\~ b |
| Single tilde (approx) | about ~5 items |
| Plain (control) | just normal text |
Loading