Using lists in prawn

后端 未结 7 1024
深忆病人
深忆病人 2021-02-13 15:53

Im using prawn to create pdfs that contain much data in table format and some lists. The problem with the lists is that Im just using text as lists because there is no semantic

7条回答
  •  抹茶落季
    2021-02-13 16:08

    I think a better approach is pre-processing the HTML string using Nokogiri, leaving only basics tags that Prawn could manage with "inline_format" option, as in this code:

    def self.render_html_text(instr)
       # Replacing 

    tag outstr = instr.gsub('

    ',"\n") outstr.gsub!('

    ',"\n") # Replacing
      &
    • tags doc = Nokogiri::HTML(outstr) doc.search('//ul').each do |ul| content = Nokogiri::HTML(ul.inner_html).xpath('//li').map{|n| "• #{n.inner_html}\n"}.join ul.replace(content) end #removing some tags inserted by Nokogiri doc.at_xpath('//body').inner_html end

提交回复
热议问题