Skip to content

Commit 4ac2804

Browse files
feat: only use auto index when marker is 1
## Details Request: #254 Previously auto indexing was added for ordered lists to generate the number value based on the items position in the list. This works for standard lists but sometimes users want to override the number based on the value actually set. To support this the default value has been updated to only use the auto value if the user value is <= 1. The icons function now also takes a third parameter with the text value of the marker.
1 parent c89e5e0 commit 4ac2804

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

Diff for: README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,10 @@ require('render-markdown').setup({
375375
-- If a function is provided both of these values are passed in using 1 based indexing
376376
-- If a list is provided we index into it using a cycle based on the level
377377
-- If the value at that level is also a list we further index into it using a clamp based on the index
378-
ordered_icons = function(level, index)
379-
return string.format('%d.', index)
378+
ordered_icons = function(level, index, value)
379+
value = vim.trim(value)
380+
local value_index = tonumber(value:sub(1, #value - 1))
381+
return string.format('%d.', value_index > 1 and value_index or index)
380382
end,
381383
-- Padding to add to the left of bullet point
382384
left_pad = 0,
@@ -878,8 +880,10 @@ require('render-markdown').setup({
878880
-- If a function is provided both of these values are passed in using 1 based indexing
879881
-- If a list is provided we index into it using a cycle based on the level
880882
-- If the value at that level is also a list we further index into it using a clamp based on the index
881-
ordered_icons = function(level, index)
882-
return string.format('%d.', index)
883+
ordered_icons = function(level, index, value)
884+
value = vim.trim(value)
885+
local value_index = tonumber(value:sub(1, #value - 1))
886+
return string.format('%d.', value_index > 1 and value_index or index)
883887
end,
884888
-- Padding to add to the left of bullet point
885889
left_pad = 0,

Diff for: doc/render-markdown.txt

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 December 06
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 December 07
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -422,8 +422,10 @@ Default Configuration ~
422422
-- If a function is provided both of these values are passed in using 1 based indexing
423423
-- If a list is provided we index into it using a cycle based on the level
424424
-- If the value at that level is also a list we further index into it using a clamp based on the index
425-
ordered_icons = function(level, index)
426-
return string.format('%d.', index)
425+
ordered_icons = function(level, index, value)
426+
value = vim.trim(value)
427+
local value_index = tonumber(value:sub(1, #value - 1))
428+
return string.format('%d.', value_index > 1 and value_index or index)
427429
end,
428430
-- Padding to add to the left of bullet point
429431
left_pad = 0,
@@ -915,8 +917,10 @@ Bullet Point Configuration ~
915917
-- If a function is provided both of these values are passed in using 1 based indexing
916918
-- If a list is provided we index into it using a cycle based on the level
917919
-- If the value at that level is also a list we further index into it using a clamp based on the index
918-
ordered_icons = function(level, index)
919-
return string.format('%d.', index)
920+
ordered_icons = function(level, index, value)
921+
value = vim.trim(value)
922+
local value_index = tonumber(value:sub(1, #value - 1))
923+
return string.format('%d.', value_index > 1 and value_index or index)
920924
end,
921925
-- Padding to add to the left of bullet point
922926
left_pad = 0,

Diff for: lua/render-markdown/health.lua

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

66
---@private
7-
M.version = '7.6.12'
7+
M.version = '7.6.13'
88

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

Diff for: lua/render-markdown/init.lua

+8-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ local M = {}
128128
---@field public checked? render.md.UserCheckboxComponent
129129
---@field public custom? table<string, render.md.UserCustomCheckbox>
130130

131-
---@alias render.md.bullet.Icons string[]|string[][]|fun(level: integer, index: integer): string?
131+
---@alias render.md.bullet.Icons
132+
---| string[]
133+
---| string[][]
134+
---| fun(level: integer, index: integer, value: string): string?
132135

133136
---@class (exact) render.md.UserBullet
134137
---@field public enabled? boolean
@@ -510,8 +513,10 @@ M.default_config = {
510513
-- If a function is provided both of these values are passed in using 1 based indexing
511514
-- If a list is provided we index into it using a cycle based on the level
512515
-- If the value at that level is also a list we further index into it using a clamp based on the index
513-
ordered_icons = function(level, index)
514-
return string.format('%d.', index)
516+
ordered_icons = function(level, index, value)
517+
value = vim.trim(value)
518+
local value_index = tonumber(value:sub(1, #value - 1))
519+
return string.format('%d.', value_index > 1 and value_index or index)
515520
end,
516521
-- Padding to add to the left of bullet point
517522
left_pad = 0,

Diff for: lua/render-markdown/render/list_item.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ end
8787
---@private
8888
---@param level integer
8989
function Render:icon(level)
90+
local node = self.data.marker
9091
local index = self.node:sibling_count('list_item')
9192
local icons = self.data.ordered and self.bullet.ordered_icons or self.bullet.icons
9293
local icon = nil
9394
if type(icons) == 'function' then
94-
icon = icons(level, index)
95+
icon = icons(level, index, node.text)
9596
else
9697
icon = List.cycle(icons, level)
9798
if type(icon) == 'table' then
@@ -101,7 +102,6 @@ function Render:icon(level)
101102
if icon == nil then
102103
return
103104
end
104-
local node = self.data.marker
105105
local text = Str.pad(self.data.spaces) .. icon
106106
local position, conceal = 'overlay', nil
107107
if Str.width(text) > Str.width(node.text) then

0 commit comments

Comments
 (0)