Skip to content

Commit ac5c3d8

Browse files
author
Corey White
committed
Fixed code and block
1 parent b035246 commit ac5c3d8

File tree

2 files changed

+41
-35
lines changed

2 files changed

+41
-35
lines changed

utils/grass_html2md.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ process_file() {
5050
cat "$file" | \
5151
sed 's#<div class="code"><pre>#<pre><code>#g' | \
5252
sed 's#</pre></div>#</code></pre>#g' | \
53-
pandoc -f html-native_divs-native_spans \
54-
-t gfm+pipe_tables --wrap=none \
53+
pandoc -f html-native_divs \
54+
-t gfm+pipe_tables --wrap=auto \
5555
--lua-filter "${UTILSPATH}/pandoc_codeblock.lua" | \
56-
sed 's/``` {#sh}/```sh/' | sed 's+ \\\$+ \$+g' | sed 's+%20+-+g' > "${f%%.html}.md"
56+
sed 's+ \\\$+ \$+g' | sed 's+%20+-+g' > "${f%%.html}.md"
5757

5858
rm -f "$file"
5959

utils/pandoc_codeblock.lua

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ function RawInline(el)
3434
return el
3535
end
3636

37+
-- function CodeBlock(el)
38+
-- -- Use native CodeBlock to prevent `{=markdown}` wrapping
39+
-- local lang = el.classes[1] or "sh" -- Preserve language if available
40+
-- return pandoc.CodeBlock(el.text, lang)
41+
-- end
42+
3743
function CodeBlock(el)
38-
-- Use native CodeBlock to prevent `{=markdown}` wrapping
44+
-- Ensure fenced code blocks with backticks
3945
local lang = el.classes[1] or "sh" -- Preserve language if available
40-
return pandoc.CodeBlock(el.text, lang)
46+
return pandoc.RawBlock("markdown", "```" .. lang .. "\n" .. el.text .. "\n```")
4147
end
4248

4349
function wrap_text(text, max_length, indent)
@@ -95,38 +101,38 @@ end
95101
-- return pandoc.Para({pandoc.RawInline("markdown", "![" .. alt_text .. "](" .. src .. ")")})
96102
-- end
97103

98-
-- function DefinitionList(el)
99-
-- local new_blocks = {}
104+
function DefinitionList(el)
105+
local new_blocks = {}
100106

101-
-- for _, item in ipairs(el.content) do
102-
-- local term = item[1] -- Term (<dt>)
103-
-- local definitions = item[2] -- Definitions (<dd>)
104-
105-
-- -- Split the term into separate parts: first word as header, rest as sub-item
106-
-- if #term > 1 then
107-
-- -- First part of the term becomes the header (###)
108-
-- -- term[1] = term[1].src
109-
-- table.insert(new_blocks, pandoc.Header(3, term[1], {}))
110-
111-
-- -- Remaining parts are combined and formatted (e.g., italicized)
112-
-- local sub_term = {}
113-
-- for i = 2, #term do
114-
-- table.insert(sub_term, term[i])
115-
-- end
116-
-- table.insert(new_blocks, pandoc.Para(sub_term))
117-
-- else
118-
-- -- If the term is simple, just use it as a header
119-
-- table.insert(new_blocks, pandoc.Header(3, term, {}))
120-
-- end
121-
122-
-- -- Process the definitions and convert to blockquote format
123-
-- for _, def in ipairs(definitions) do
124-
-- table.insert(new_blocks, pandoc.BlockQuote(def))
125-
-- end
126-
-- end
107+
for _, item in ipairs(el.content) do
108+
local term = item[1] -- Term (<dt>)
109+
local definitions = item[2] -- Definitions (<dd>)
127110

128-
-- return new_blocks
129-
-- end
111+
-- Split the term into separate parts: first word as header, rest as sub-item
112+
if #term > 1 then
113+
-- First part of the term becomes the header (###)
114+
-- term[1] = term[1].src
115+
table.insert(new_blocks, pandoc.Header(3, term[1], {}))
116+
117+
-- Remaining parts are combined and formatted (e.g., italicized)
118+
local sub_term = {}
119+
for i = 2, #term do
120+
table.insert(sub_term, term[i])
121+
end
122+
table.insert(new_blocks, pandoc.Para(sub_term))
123+
else
124+
-- If the term is simple, just use it as a header
125+
table.insert(new_blocks, pandoc.Header(3, term, {}))
126+
end
127+
128+
-- Process the definitions and convert to blockquote format
129+
for _, def in ipairs(definitions) do
130+
table.insert(new_blocks, pandoc.BlockQuote(def))
131+
end
132+
end
133+
134+
return new_blocks
135+
end
130136

131137
function TableCell(el)
132138
-- Remove inline styles from table cells

0 commit comments

Comments
 (0)