@@ -2,6 +2,7 @@ local Context = require('render-markdown.context')
22local NodeInfo = require (' render-markdown.node_info' )
33local RenderCode = require (' render-markdown.render.code' )
44local RenderHeading = require (' render-markdown.render.heading' )
5+ local RenderQuote = require (' render-markdown.render.quote' )
56local RenderTable = require (' render-markdown.render.table' )
67local component = require (' render-markdown.component' )
78local list = require (' render-markdown.list' )
@@ -14,6 +15,7 @@ local str = require('render-markdown.str')
1415--- @field private marks render.md.Marks
1516--- @field private config render.md.BufferConfig
1617--- @field private context render.md.Context
18+ --- @field private renderers table<string , render.md.Renderer>
1719local Handler = {}
1820Handler .__index = Handler
1921
@@ -25,6 +27,12 @@ function Handler.new(buf)
2527 self .marks = list .new_marks ()
2628 self .config = state .get_config (buf )
2729 self .context = Context .get (buf )
30+ self .renderers = {
31+ code = RenderCode .new (buf , self .marks , self .config , self .context ),
32+ heading = RenderHeading .new (buf , self .marks , self .config , self .context ),
33+ quote = RenderQuote .new (buf , self .marks , self .config , self .context ),
34+ table = RenderTable .new (buf , self .marks , self .config , self .context ),
35+ }
2836 return self
2937end
3038
@@ -34,32 +42,20 @@ function Handler:parse(root)
3442 self .context :query (root , state .markdown_query , function (capture , node )
3543 local info = NodeInfo .new (self .buf , node )
3644 logger .debug_node_info (capture , info )
37- if capture == ' section' then
45+
46+ local renderer = self .renderers [capture ]
47+ if renderer ~= nil then
48+ renderer :render (info )
49+ elseif capture == ' section' then
3850 self :section (info )
39- elseif capture == ' heading' then
40- RenderHeading .new (self .buf , self .marks , self .config , self .context ):render (info )
4151 elseif capture == ' dash' then
4252 self :dash (info )
43- elseif capture == ' code' then
44- RenderCode .new (self .buf , self .marks , self .config , self .context ):render (info )
4553 elseif capture == ' list_marker' then
4654 self :list_marker (info )
4755 elseif capture == ' checkbox_unchecked' then
4856 self :checkbox (info , self .config .checkbox .unchecked )
4957 elseif capture == ' checkbox_checked' then
5058 self :checkbox (info , self .config .checkbox .checked )
51- elseif capture == ' quote' then
52- self .context :query (node , state .markdown_quote_query , function (nested_capture , nested_node )
53- local nested_info = NodeInfo .new (self .buf , nested_node )
54- logger .debug_node_info (nested_capture , nested_info )
55- if nested_capture == ' quote_marker' then
56- self :quote_marker (nested_info , info )
57- else
58- logger .unhandled_capture (' markdown quote' , nested_capture )
59- end
60- end )
61- elseif capture == ' table' then
62- RenderTable .new (self .buf , self .marks , self .config , self .context ):render (info )
6359 else
6460 logger .unhandled_capture (' markdown' , capture )
6561 end
@@ -187,25 +183,6 @@ function Handler:checkbox(info, checkbox)
187183 })
188184end
189185
190- --- @private
191- --- @param info render.md.NodeInfo
192- --- @param block_quote render.md.NodeInfo
193- function Handler :quote_marker (info , block_quote )
194- local quote = self .config .quote
195- if not quote .enabled then
196- return
197- end
198- local callout = component .callout (self .buf , block_quote .text , ' contains' )
199- local highlight = callout ~= nil and callout .highlight or quote .highlight
200- self .marks :add (true , info .start_row , info .start_col , {
201- end_row = info .end_row ,
202- end_col = info .end_col ,
203- virt_text = { { info .text :gsub (' >' , quote .icon ), highlight } },
204- virt_text_pos = ' overlay' ,
205- virt_text_repeat_linebreak = quote .repeat_linebreak or nil ,
206- })
207- end
208-
209186--- @class render.md.handler.Markdown : render.md.Handler
210187local M = {}
211188
0 commit comments