From cfb78bf65141e3f1826a0f9cac9c731f76214554 Mon Sep 17 00:00:00 2001 From: murat Date: Mon, 29 Jun 2026 20:01:33 +0300 Subject: [PATCH] chore: add formatShortcode function to styling module --- luago.lua | 30 +----------------------------- styling.lua | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/luago.lua b/luago.lua index f57c119..cc5f9a8 100644 --- a/luago.lua +++ b/luago.lua @@ -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 diff --git a/styling.lua b/styling.lua index 1fb4b86..f2a9580 100644 --- a/styling.lua +++ b/styling.lua @@ -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