LUA – PANDOC number sample list does not apply to custom writers

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 numbering in the html was broken. Consider the following md code :

(@) 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, "
  • " .. item .. "
  • ")
    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, "
  • " .. item .. "
  • ")
    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?

    View custom writers through pandoc sources (src/Text/Pandoc/Writers/Custom.hs ), 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 Example-list 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, "
  • " .. item .. "
  • ")
    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:

    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, "
  • " .. item .. "
  • ")
    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, "
  • " .. item .. "
  • ")
    end
    return "
      \ n" .. table.concat(buffer, "\n") .. "\n
    "
    end

    We will only see the number of the final list item:

    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

    WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
    SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3203 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

    Leave a Comment

    Your email address will not be published.