chore: add formatShortcode function to styling module

This commit is contained in:
2026-06-29 20:01:33 +03:00
parent e122769fb9
commit cfb78bf651
2 changed files with 31 additions and 29 deletions
+1 -29
View File
@@ -130,35 +130,7 @@ for index, _ in ipairs(markdownFiles) do
if start_idx and end_idx then
local shortcode = second:sub(1, start_idx - 1)
local third = second:sub(end_idx + 1)
local function formatShortcode(element)
local dir = markdownFiles[index].filePath:match("(.*)/[^/]+%.md$")
local results = {}
for mdfile in lfs.dir(dir) do
if mdfile:match("%.md$") and mdfile ~= markdownFiles[index].fileName .. ".md" then
local fileName = mdfile:match("(.-)%.md$")
for i, _ in ipairs(markdownFiles) do
if markdownFiles[i].fileName == fileName then
local copy = element
-- replace items starting with list.item.
for option in copy:gmatch("{{list%.item%.(.-)}}") do
local value = markdownFiles[i].options[option]
if value then
copy = copy:gsub("{{list%.item%." .. option .. "}}", value)
end
end
table.insert(results, copy)
end
end
end
end
return table.concat(results, "\n")
end
shortcode = formatShortcode(shortcode)
shortcode = styling.formatShortcode(shortcode, markdownFiles, index)
content = first .. shortcode .. third
end
end
+30
View File
@@ -1,3 +1,4 @@
local lfs = require("lfs")
local module = {}
local function styleLists(s)
local lines = {}
@@ -137,4 +138,33 @@ function module.transform(s)
return s
end
function module.formatShortcode(element, markdownFiles, index)
local dir = markdownFiles[index].filePath:match("(.*)/[^/]+%.md$")
local results = {}
for mdfile in lfs.dir(dir) do
if mdfile:match("%.md$") and mdfile ~= markdownFiles[index].fileName .. ".md" then
local fileName = mdfile:match("(.-)%.md$")
for i, _ in ipairs(markdownFiles) do
if markdownFiles[i].fileName == fileName then
local copy = element
-- replace items starting with list.item.
for option in copy:gmatch("{{list%.item%.(.-)}}") do
local value = markdownFiles[i].options[option]
if value then
copy = copy:gsub("{{list%.item%." .. option .. "}}", value)
end
end
table.insert(results, copy)
end
end
end
end
return table.concat(results, "\n")
end
return module