puzzle / prawn-markup

Parse simple HTML markup to include in Prawn PDFs
MIT License
65 stars 16 forks source link

Nested list parents don't support embedded markup #41

Closed 3rwolff closed 2 years ago

3rwolff commented 2 years ago

Nested lists don't support embedded html. Any ordered/unordered list element that has a nested list element below it, will not support the markup such as , , . These tags will be converted to HTML entities (i.e. <b> will appear as &lt;b&gt;). It appears that the symptomatic elements are being converted from strong to b tags for some reason (similar for italics which also have this issue).

With the following rich text:

"<div class=\"trix-content\">\n  <ol>\n<li> <strong>HELLO</strong><ol>\n<li> <strong>WORLD</strong><ol>\n<li> <strong>STUFF</strong>\n</li>\n<li> <strong>STUFF2</strong>\n</li>\n</ol>\n</li>\n<li> <strong>WORLD2</strong>\n</li>\n</ol>\n</li>\n<li> <strong>HELLO2</strong>\n</li>\n</ol>\n</div>\n"

The output will appear as:

1. <b>HELLO</b>
   1. <b>WORLD</b>
        1.STUFF
        2.STUFF2
   2.WORLD2
2.HELLO2
3rwolff commented 2 years ago

It seems that within the gem's file lib/prawn/markup/builders/list_builder.rb:161 the defaults forinline_formatare not set totrue` by default for lists. That seems crazy as they are for tables and blocks.

You can modify the gem's method with the following:

 def default_list_options
          {
            content: { inline_format: true },
            bullet: { align: :right }
          }
 end

For users experiencing this issue, you can use this simple workaround directly from your rails app. Simply call prawn.markup with the following option:

 prawn.markup(text.to_s,
       {
           list: { content: { inline_format: true } }
       }
 )
codez commented 2 years ago

I could not reproduce your issue. For nested lists, this behavior was fixed in 10a03502bc43532ba0559caa64e37998397194e3