Skip to content

Commit

Permalink
feat: Add inline heading position
Browse files Browse the repository at this point in the history
## Details

Request: #107

Currently heading icons are left padded with spaces to overlay the '#'s.
Keep this as the default behavior and add an 'inline' position option.
This results in the icons being aligned regardless of the heading level.
MeanderingProgrammer committed Jul 30, 2024
1 parent 3bdae40 commit 345596b
Showing 6 changed files with 24 additions and 6 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -202,10 +202,13 @@ require('render-markdown').setup({
enabled = true,
-- Turn on / off any sign column related rendering
sign = true,
-- Determines how the icon fills the available space:
-- inline: underlying '#'s are concealed resulting in a left aligned icon
-- overlay: result is left padded with spaces to hide any additional '#'
position = 'overlay',
-- Replaces '#+' of 'atx_h._marker'
-- The number of '#' in the heading determines the 'level'
-- The 'level' is used to index into the array using a cycle
-- The result is left padded with spaces to hide any additional '#'
icons = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
-- Added to the sign column if enabled
-- The 'level' is used to index into the array using a cycle
@@ -452,10 +455,13 @@ require('render-markdown').setup({
enabled = true,
-- Turn on / off any sign column related rendering
sign = true,
-- Determines how the icon fills the available space:
-- inline: underlying '#'s are concealed resulting in a left aligned icon
-- overlay: result is left padded with spaces to hide any additional '#'
position = 'overlay',
-- Replaces '#+' of 'atx_h._marker'
-- The number of '#' in the heading determines the 'level'
-- The 'level' is used to index into the array using a cycle
-- The result is left padded with spaces to hide any additional '#'
icons = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
-- Added to the sign column if enabled
-- The 'level' is used to index into the array using a cycle
10 changes: 8 additions & 2 deletions doc/render-markdown.txt
Original file line number Diff line number Diff line change
@@ -234,10 +234,13 @@ Full Default Configuration ~
enabled = true,
-- Turn on / off any sign column related rendering
sign = true,
-- Determines how the icon fills the available space:
-- inline: underlying '#'s are concealed resulting in a left aligned icon
-- overlay: result is left padded with spaces to hide any additional '#'
position = 'overlay',
-- Replaces '#+' of 'atx_h._marker'
-- The number of '#' in the heading determines the 'level'
-- The 'level' is used to index into the array using a cycle
-- The result is left padded with spaces to hide any additional '#'
icons = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
-- Added to the sign column if enabled
-- The 'level' is used to index into the array using a cycle
@@ -483,10 +486,13 @@ HEADINGS *render-markdown-setup-headings*
enabled = true,
-- Turn on / off any sign column related rendering
sign = true,
-- Determines how the icon fills the available space:
-- inline: underlying '#'s are concealed resulting in a left aligned icon
-- overlay: result is left padded with spaces to hide any additional '#'
position = 'overlay',
-- Replaces '#+' of 'atx_h._marker'
-- The number of '#' in the heading determines the 'level'
-- The 'level' is used to index into the array using a cycle
-- The result is left padded with spaces to hide any additional '#'
icons = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
-- Added to the sign column if enabled
-- The 'level' is used to index into the array using a cycle
2 changes: 1 addition & 1 deletion lua/render-markdown/handler/markdown.lua
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ function M.heading(config, buf, info)
-- is added to account for the space after the last `#` but before the heading title,
-- and concealed text is subtracted since that space is not usable
local padding = level + 1 - ts.concealed(buf, info) - str.width(icon)
if padding < 0 then
if heading.position == 'inline' or padding < 0 then
-- Requires inline extmarks to place when there is not enough space available
if util.has_10 then
---@type render.md.Mark
6 changes: 5 additions & 1 deletion lua/render-markdown/init.lua
Original file line number Diff line number Diff line change
@@ -90,6 +90,7 @@ local M = {}
---@class (exact) render.md.UserHeading
---@field public enabled? boolean
---@field public sign? boolean
---@field public position? 'overlay'|'inline'
---@field public icons? string[]
---@field public signs? string[]
---@field public width? 'full'|'block'
@@ -216,10 +217,13 @@ M.default_config = {
enabled = true,
-- Turn on / off any sign column related rendering
sign = true,
-- Determines how the icon fills the available space:
-- inline: underlying '#'s are concealed resulting in a left aligned icon
-- overlay: result is left padded with spaces to hide any additional '#'
position = 'overlay',
-- Replaces '#+' of 'atx_h._marker'
-- The number of '#' in the heading determines the 'level'
-- The 'level' is used to index into the array using a cycle
-- The result is left padded with spaces to hide any additional '#'
icons = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
-- Added to the sign column if enabled
-- The 'level' is used to index into the array using a cycle
1 change: 1 addition & 0 deletions lua/render-markdown/state.lua
Original file line number Diff line number Diff line change
@@ -162,6 +162,7 @@ function M.validate()
append_errors(path .. '.heading', heading, {
enabled = { heading.enabled, 'boolean', nilable },
sign = { heading.sign, 'boolean', nilable },
position = one_of(heading.position, { 'overlay', 'inline' }, {}, nilable),
icons = string_array(heading.icons, nilable),
signs = string_array(heading.signs, nilable),
width = one_of(heading.width, { 'full', 'block' }, {}, nilable),
1 change: 1 addition & 0 deletions lua/render-markdown/types.lua
Original file line number Diff line number Diff line change
@@ -79,6 +79,7 @@
---@class (exact) render.md.Heading
---@field public enabled boolean
---@field public sign boolean
---@field public position 'overlay'|'inline'
---@field public icons string[]
---@field public signs string[]
---@field public width 'full'|'block'

0 comments on commit 345596b

Please sign in to comment.