pandoc / lua-filters

A collection of lua filters for pandoc
MIT License
602 stars 165 forks source link

revealjs-codeblock should support startFrom attribute for line numbers #201

Open PeterSommerlad opened 2 years ago

PeterSommerlad commented 2 years ago

While playing with revealjs-codeblock plugin i figured that it does not honor the line numbering attribute from pandoc startFrom=10 . I could add that with my very limited lua abilities by iterating over the code block attributes and add the attribute manually. Because of my lack of experience with lua I place my " solution " here, but dare not to create a pull request, the solution is suboptimal, because the code block attributes are now iterated twice.

function CodeBlock(block)
  if FORMAT == 'revealjs' then
    local css_classes = {}
    local pre_tag_attributes = {}
    local code_tag_attributes = {}

    for _, class in ipairs(block.classes) do
      if is_numberlines_class(class) then
        if not is_data_line_number_in_attributes(block.attributes) then
          table.insert(block.attributes, {'data-line-numbers', ''})
        end
        for _, attribute in ipairs(block.attributes) do
          if attribute[1] == 'startFrom' then 
            table.insert(block.attributes, {'data-ln-start-from', attribute[2]})
          end
        end
      else
        table.insert(css_classes, class)
      end
    end
... continues