(@) item 1
(@) item 2
## header ##
< br />(@) item 3
Pandoc generates the following html pages by default:
1. item 1
2. item 2
header
3. item 3
But using a custom writer (we use pandoc –print-default-data-file sample.lua as an example) it produces:
< p>
1. item 1
2. item 2
header
1. item 3
The example lua-writer contains the following Sequence list processing code:
function OrderedList(items)
local buffer = {}
for _, item in pairs(items) do
table.insert(buffer, "
end
return "
- \n" .. table.concat(buffer, "\n") .. "\n
end
If printing is added to the first element in the items table
function OrderedList(items)
local buffer = {}
for elem, item in pairs(items) do
print(elem)
table.insert(buffer, "
end
return "
- \n" .. table.concat(buffer, "\n") .. "\n
end
We will only see the final list item The number:
1
2
1
So I don’t think the problem is in the writer itself. Do you have any ideas how to solve it this problem?
-- for counting examples (@)
local ExampleIdx = 1
function OrderedList(items, num, sty, delim)
local buffer = {}
for _, item in pairs(items) do
table.insert(buffer, "
end
local start = ""
if sty == " Example" then
if ExampleIdx> 1 then
start = 'start="' .. ExampleIdx ..'"'
end
ExampleIdx = ExampleIdx + table.getn(items)
end
return'
- \n' .. table.concat(buffer, "\n") .. "\n
end
Pandoc provides an amazing extension example_lists for consecutively numbered lists throughout the document. We tried to use a custom writer to generate html, but the numbers in the resulting html were Break. Consider the following md code:
(@) item 1
(@) item 2
## header ##
(@) item 3
Pandoc generates the following html pages by default:
p>
1. item 1
2. item 2
header
3. item 3
But use a custom writer (we use pandoc –print- default-data-file sample.lua as an example) It produces:
1. item 1
2. item 2
header
1 . item 3
The example lua-writer contains the following code for ordered list processing:
function OrderedList(items)
local buffer = {}
for _, item in pairs(items) do
table.insert(buffer, "
end< br /> return "
- \n" .. table.concat(buffer, "\n") .. "\n
end
If it is items table Add printing to the first element in the
function OrderedList(items)
local buffer = {}
for elem, item in pairs(items) do
print(elem)
table.insert(buffer, "
end
return "
- \ n" .. table.concat(buffer, "\n") .. "\n
end
We will only see the number of the final list item: p>
1
2
1
So I don’t think the problem is in the writer itself. Do you have any ideas on how to solve this problem?
Check the custom writer (src/Text/Pandoc/Writers/Custom.hs) through pandoc sources, you may find that the OrderedList function actually has four Parameters, the third of which is the list style. You should be interested in the example list style. Therefore, you can update the OrderedList implementation accordingly: introduce global variables to calculate the total items in the Example-list, and change the function code according to the list style ( Add the start attribute to the ol html tag of the example list).
-- for counting examples (@)
local ExampleIdx = 1
function OrderedList(items, num, sty, delim)
local buffer = {}
for _, item in pairs(items) do
table.insert(buffer, "< li>" .. item .. "")
end
local start = ""
if sty == "Example" then
if ExampleIdx> 1 then
start = 'start="' .. ExampleIdx ..'"'
end
ExampleIdx = ExampleIdx + table.getn(items)
end
return'< ol' .. start ..'>\n' .. table.concat(buffer, "\n") .. "\n"
end