Skip to content

Commit 79d0de4

Browse files
refactor: move complex rendering into own modules
## Details There are a few elements we render that have many options and whose implementations are getting too long to keep piling them into a single file. This is the case for: - headings - code blocks - pipe tables Copy all the rendering logic for these with minimal changes into their own Lua modules. A couple of things made this easier, the most important one being sharing a single collection of `marks` which implements the `add` method. By passing this instance everywhere we're able to add together all the `marks` without doing a lot of `vim.list_extend` which gets pretty hard to manage. The Parser logic previously added for code blocks and pipe tables has been moved into the new render modules to keep everything tightly coupled. This is more practical now since the parsers would previously be living in the top level `markdown` handler growing it to 1000+ lines. There's nothing technically wrong with a particularly long file but I like the ability to keep only necessary things together without having it live amoung all the other random logic. I might take this to its conclusion and separate everything into its own module. Should have no visible impact to users.
1 parent 631e03e commit 79d0de4

File tree

13 files changed

+922
-848
lines changed

13 files changed

+922
-848
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
- tables indented and no spaces in cells [#142](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/142)
88
[a3617d6](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/a3617d61fcf4cec623ee6acb48570589d7ddcb03)
9+
- skip tables with errors [c5f25ef](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/c5f25ef19ed9bb3da4e7d947c5119cf8a6191beb)
10+
- render table border below delimiter when no rows [631e03e](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/631e03e2cfc153c38327c9cc995f4e7c2bbd9b24)
911

1012
## 6.2.0 (2024-08-21)
1113

lua/render-markdown/context.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local util = require('render-markdown.util')
88
---@field private bottom integer
99
---@field private conceal? table<integer, [integer, integer][]>
1010
---@field private links table<integer, [integer, integer, integer][]>
11+
---@field last_heading integer
1112
local Context = {}
1213
Context.__index = Context
1314

@@ -24,6 +25,7 @@ function Context.new(buf, win, offset)
2425
self.bottom = self:compute_bottom(top, offset)
2526
self.conceal = nil
2627
self.links = {}
28+
self.last_heading = -1
2729
return self
2830
end
2931

lua/render-markdown/handler/latex.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ function M.parse(root, buf)
4343
return { { expression, latex.highlight } }
4444
end, expressions)
4545

46-
local marks = {}
47-
list.add_mark(marks, false, info.start_row, info.start_col, {
46+
local marks = list.new_marks()
47+
marks:add(false, info.start_row, info.start_col, {
4848
end_row = info.end_row,
4949
end_col = info.end_col,
5050
virt_lines = latex_lines,
5151
virt_lines_above = true,
5252
})
53-
return marks
53+
return marks:get()
5454
end
5555

5656
return M

0 commit comments

Comments
 (0)