Skip to content

Commit a020c88

Browse files
feat: ability to enable and disable atx and setext heading rendering
## Details Request: #381 Adds `heading.atx` and `heading.setext` boolean options. These let you disable rendering for a specific subset of heading types rather than an all or nothing. By default both remain enabled. Mostly helpful for `setext` headings since their syntax can overlap with nested lists.
1 parent a1fc4e5 commit a020c88

File tree

7 files changed

+29
-5
lines changed

7 files changed

+29
-5
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ require('render-markdown').setup({
303303
enabled = true,
304304
-- Additional modes to render headings.
305305
render_modes = false,
306+
-- Turn on / off atx heading rendering.
307+
atx = true,
308+
-- Turn on / off setext heading rendering.
309+
setext = true,
306310
-- Turn on / off any sign column related rendering.
307311
sign = true,
308312
-- Replaces '#+' of 'atx_h._marker'.
@@ -827,6 +831,10 @@ require('render-markdown').setup({
827831
enabled = true,
828832
-- Additional modes to render headings.
829833
render_modes = false,
834+
-- Turn on / off atx heading rendering.
835+
atx = true,
836+
-- Turn on / off setext heading rendering.
837+
setext = true,
830838
-- Turn on / off any sign column related rendering.
831839
sign = true,
832840
-- Replaces '#+' of 'atx_h._marker'.

doc/render-markdown.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2025 March 28
1+
*render-markdown.txt* For 0.10.0 Last change: 2025 March 30
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -368,6 +368,10 @@ Default Configuration ~
368368
enabled = true,
369369
-- Additional modes to render headings.
370370
render_modes = false,
371+
-- Turn on / off atx heading rendering.
372+
atx = true,
373+
-- Turn on / off setext heading rendering.
374+
setext = true,
371375
-- Turn on / off any sign column related rendering.
372376
sign = true,
373377
-- Replaces '#+' of 'atx_h._marker'.
@@ -890,6 +894,10 @@ Heading Configuration ~
890894
enabled = true,
891895
-- Additional modes to render headings.
892896
render_modes = false,
897+
-- Turn on / off atx heading rendering.
898+
atx = true,
899+
-- Turn on / off setext heading rendering.
900+
setext = true,
893901
-- Turn on / off any sign column related rendering.
894902
sign = true,
895903
-- Replaces '#+' of 'atx_h._marker'.

lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
55
local M = {}
66

77
---@private
8-
M.version = '8.1.22'
8+
M.version = '8.1.23'
99

1010
function M.check()
1111
M.start('version')

lua/render-markdown/init.lua

+6
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ local M = {}
261261
---@alias render.md.heading.Width 'full'|'block'
262262

263263
---@class (exact) render.md.UserHeading: render.md.UserBaseComponent
264+
---@field atx? boolean
265+
---@field setext? boolean
264266
---@field sign? boolean
265267
---@field icons? render.md.heading.Icons
266268
---@field position? render.md.heading.Position
@@ -482,6 +484,10 @@ M.default_config = {
482484
enabled = true,
483485
-- Additional modes to render headings.
484486
render_modes = false,
487+
-- Turn on / off atx heading rendering.
488+
atx = true,
489+
-- Turn on / off setext heading rendering.
490+
setext = true,
485491
-- Turn on / off any sign column related rendering.
486492
sign = true,
487493
-- Replaces '#+' of 'atx_h._marker'.

lua/render-markdown/render/heading.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ function Render:setup()
4343
local atx = nil
4444
local marker = nil
4545
local level = nil
46-
if self.node.type == 'atx_heading' then
46+
if self.node.type == 'atx_heading' and self.heading.atx then
4747
atx = true
4848
marker = assert(self.node:child_at(0), 'atx heading expected child marker')
4949
level = Str.width(marker.text)
50-
elseif self.node.type == 'setext_heading' then
50+
elseif self.node.type == 'setext_heading' and self.heading.setext then
5151
atx = false
5252
marker = assert(self.node:child_at(1), 'ext heading expected child underline')
5353
level = marker.type == 'setext_h1_underline' and 1 or 2

lua/render-markdown/state.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function M.validate()
167167
end)
168168
:nested('heading', function(heading)
169169
component_rules(heading)
170-
:type({ 'sign', 'border_virtual', 'border_prefix' }, 'boolean')
170+
:type({ 'atx', 'setext', 'sign', 'border_virtual', 'border_prefix' }, 'boolean')
171171
:type({ 'above', 'below' }, 'string')
172172
:list('border', 'boolean', 'boolean')
173173
:list({ 'left_margin', 'left_pad', 'right_pad', 'min_width' }, 'number', 'number')

lua/render-markdown/types.lua

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@
176176
---@field min_width integer
177177

178178
---@class (exact) render.md.Heading: render.md.BaseComponent
179+
---@field atx boolean
180+
---@field setext boolean
179181
---@field sign boolean
180182
---@field icons render.md.heading.Icons
181183
---@field position render.md.heading.Position

0 commit comments

Comments
 (0)