Skip to content

Commit 1861f95

Browse files
authored
Merge pull request #485 from ImmanuelHaffner/fix/tostring-bold-italic-recursion
fix(tostring): recurse into nested inline elements inside bold/italic
2 parents 0509437 + 75f9a32 commit 1861f95

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

lua/markview/renderers/markdown/tostring.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ md_str.bold = function (match)
169169
removed = string.gsub(match, "^%_%_", ""):gsub("%_%_$", "");
170170
end
171171

172-
return removed;
172+
return md_str.tostring(md_str.buffer, removed, false);
173173

174174
---|fE
175175
end
@@ -193,7 +193,8 @@ md_str.bold_italic = function (match)
193193
r = math.min(be and #be or 0, af and #af or 0);
194194
end
195195

196-
return vim.fn.strpart(match, r, vim.fn.strchars(match) - (r + r));
196+
local removed = vim.fn.strpart(match, r, vim.fn.strchars(match) - (r + r));
197+
return md_str.tostring(md_str.buffer, removed, false);
197198

198199
---|fE
199200
end
@@ -380,7 +381,7 @@ md_str.italic = function (match)
380381
removed = string.gsub(match, "^%_", ""):gsub("%_$", "");
381382
end
382383

383-
return removed;
384+
return md_str.tostring(md_str.buffer, removed, false);
384385

385386
---|fE
386387
end

test/tostring_recursion.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; Bold/italic wrapping inline elements — tostring recursion
2+
3+
### Bold + link
4+
5+
| Kind | Short | Long |
6+
|------|-------|------|
7+
| Bold + link | **[bold link](https://example.com)** | **[bold link with long URL](https://spec.commonmark.org/0.31.2/#emphasis-and-strong-emphasis-combined-with-links-and-images)** |
8+
| Italic + link | *[italic link](https://example.com)* | *[italic link with long URL](https://spec.commonmark.org/0.31.2/#emphasis-and-strong-emphasis-combined-with-links-and-images)* |
9+
| Bold-italic + link | ***[both](https://example.com)*** | ***[both with long URL](https://spec.commonmark.org/0.31.2/#emphasis-and-strong-emphasis-combined-with-links-and-images)*** |
10+
11+
### Bold + image
12+
13+
| Kind | Short | Long |
14+
|------|-------|------|
15+
| Bold + image | **![icon](https://example.com/i.svg)** | **![a]( https://raw.githubusercontent.com/nvim-treesitter/playground/master/assets/screenshot.png)** |
16+
| Italic + image | *![icon](https://example.com/i.svg)* | *![a](https://raw.githubusercontent.com/nvim-treesitter/playground/master/assets/screenshot.png)* |
17+
18+
### Bold + code
19+
20+
| Kind | Short | Long |
21+
|------|-------|------|
22+
| Bold + code | **`short`** | **`vim.api.nvim_buf_set_extmark(buffer, ns, row, col, opts)`** |
23+
| Italic + code | *`short`* | *`vim.api.nvim_buf_set_extmark(buffer, ns, row, col, opts)`* |
24+
25+
### Mixed nesting
26+
27+
| Description | Content |
28+
|-------------|---------|
29+
| Bold wrapping link + code | **[link](https://example.com) and `code`** |
30+
| Plain bold (no nesting) | **just bold text** |
31+
| Plain italic | *just italic text* |
32+
| No emphasis | [link](https://example.com) then `code` |

0 commit comments

Comments
 (0)