-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(refactor): finish moving main markdown logic into individual co…
…mponent renderers
- Loading branch information
1 parent
91ce0b5
commit d3a565e
Showing
7 changed files
with
103 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
local Base = require('render-markdown.render.base') | ||
local str = require('render-markdown.core.str') | ||
|
||
---@class render.md.render.Checkbox: render.md.Renderer | ||
---@field private checkbox render.md.CheckboxComponent | ||
---@field private inline boolean | ||
local Render = setmetatable({}, Base) | ||
Render.__index = Render | ||
|
||
---@param marks render.md.Marks | ||
---@param config render.md.buffer.Config | ||
---@param context render.md.Context | ||
---@param info render.md.NodeInfo | ||
---@return render.md.Renderer | ||
function Render:new(marks, config, context, info) | ||
return Base.new(self, marks, config, context, info) | ||
end | ||
|
||
---@return boolean | ||
function Render:setup() | ||
local checkbox = self.config.checkbox | ||
if not checkbox.enabled then | ||
return false | ||
end | ||
|
||
local type_mapping = { | ||
task_list_marker_unchecked = checkbox.unchecked, | ||
task_list_marker_checked = checkbox.checked, | ||
} | ||
self.checkbox = type_mapping[self.info.type] | ||
if self.checkbox == nil then | ||
return false | ||
end | ||
|
||
self.inline = checkbox.position == 'inline' | ||
|
||
return true | ||
end | ||
|
||
function Render:render() | ||
local icon = self.checkbox.icon | ||
local text = self.inline and icon or str.pad_to(self.info.text, icon) .. icon | ||
self.marks:add(true, self.info.start_row, self.info.start_col, { | ||
end_row = self.info.end_row, | ||
end_col = self.info.end_col, | ||
virt_text = { { text, self.checkbox.highlight } }, | ||
virt_text_pos = self.inline and 'inline' or 'overlay', | ||
conceal = self.inline and '' or nil, | ||
}) | ||
end | ||
|
||
return Render |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
local Base = require('render-markdown.render.base') | ||
|
||
---@class render.md.render.Dash: render.md.Renderer | ||
---@field private dash render.md.Dash | ||
local Render = setmetatable({}, Base) | ||
Render.__index = Render | ||
|
||
---@param marks render.md.Marks | ||
---@param config render.md.buffer.Config | ||
---@param context render.md.Context | ||
---@param info render.md.NodeInfo | ||
---@return render.md.Renderer | ||
function Render:new(marks, config, context, info) | ||
return Base.new(self, marks, config, context, info) | ||
end | ||
|
||
---@return boolean | ||
function Render:setup() | ||
self.dash = self.config.dash | ||
if not self.dash.enabled then | ||
return false | ||
end | ||
return true | ||
end | ||
|
||
function Render:render() | ||
local width = self.dash.width | ||
width = type(width) == 'number' and width or self.context:get_width() | ||
|
||
self.marks:add(true, self.info.start_row, 0, { | ||
virt_text = { { self.dash.icon:rep(width), self.dash.highlight } }, | ||
virt_text_pos = 'overlay', | ||
}) | ||
end | ||
|
||
return Render |