diff --git a/lua/markview/renderers/markdown/tostring.lua b/lua/markview/renderers/markdown/tostring.lua index b51a6fa..fa9dece 100644 --- a/lua/markview/renderers/markdown/tostring.lua +++ b/lua/markview/renderers/markdown/tostring.lua @@ -168,7 +168,7 @@ md_str.bold = function (match) removed = string.gsub(match, "^%_%_", ""):gsub("%_%_$", ""); end - return removed; + return md_str.tostring(md_str.buffer, removed, false); ---|fE end @@ -192,7 +192,8 @@ md_str.bold_italic = function (match) r = math.min(be and #be or 0, af and #af or 0); end - return vim.fn.strpart(match, r, vim.fn.strchars(match) - (r + r)); + local removed = vim.fn.strpart(match, r, vim.fn.strchars(match) - (r + r)); + return md_str.tostring(md_str.buffer, removed, false); ---|fE end @@ -339,7 +340,7 @@ md_str.italic = function (match) removed = string.gsub(match, "^%_", ""):gsub("%_$", ""); end - return removed; + return md_str.tostring(md_str.buffer, removed, false); ---|fE end diff --git a/test/tostring_recursion.md b/test/tostring_recursion.md new file mode 100644 index 0000000..69d521c --- /dev/null +++ b/test/tostring_recursion.md @@ -0,0 +1,32 @@ +; Bold/italic wrapping inline elements — tostring recursion + +### Bold + link + +| Kind | Short | Long | +|------|-------|------| +| 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)** | +| 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)* | +| 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)*** | + +### Bold + image + +| Kind | Short | Long | +|------|-------|------| +| Bold + image | **![icon](https://example.com/i.svg)** | **![a]( https://raw.githubusercontent.com/nvim-treesitter/playground/master/assets/screenshot.png)** | +| Italic + image | *![icon](https://example.com/i.svg)* | *![a](https://raw.githubusercontent.com/nvim-treesitter/playground/master/assets/screenshot.png)* | + +### Bold + code + +| Kind | Short | Long | +|------|-------|------| +| Bold + code | **`short`** | **`vim.api.nvim_buf_set_extmark(buffer, ns, row, col, opts)`** | +| Italic + code | *`short`* | *`vim.api.nvim_buf_set_extmark(buffer, ns, row, col, opts)`* | + +### Mixed nesting + +| Description | Content | +|-------------|---------| +| Bold wrapping link + code | **[link](https://example.com) and `code`** | +| Plain bold (no nesting) | **just bold text** | +| Plain italic | *just italic text* | +| No emphasis | [link](https://example.com) then `code` |