puzzle / prawn-markup

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

Adding generated content into Prawn Table Cell seems problamatic #8

Closed sdglhm closed 4 years ago

sdglhm commented 4 years ago

Hi,

I'm trying to add Prawn-Markup generated content into a prawn table cell. My code as follows,

data += [[ { content: post.content, size: 9, padding: [5, 5, 5, 15] } ]]

pdf.table data

And my post.content has basic markups like bold/italic/etc...

However, when I try to add pdf.markup(post.content) it doesn't seem to work properly and shows the following error which is totally understandable since prawn-markup doesn't output something like a text.

Prawn::Errors::UnrecognizedTableContent

If I add .to_s method, it would render the content.

image

But this content isn't getting rendered at the correct cell position. Following is what I get at the cell position.

image

#<Nokogiri::HTML::SAX::ParserContext:0x00007f97c9612070>

Is there a way I could monkey-patch something so this would render inside a prawn table?

Thank you.

codez commented 4 years ago

The markup method has no defined return value and surely does not return anything that could be rendered somewhere else. I think there is no simple way to render markup in a table like you think.

You could try to model your table in html and insert your post.content there, then let prawn markup render the entire table.

sdglhm commented 4 years ago

Thank you @codez After going through the source I also thought the same. I can understand that it would be impossible for something like this to be implemented as there's no clear way to return a formatted string with things like move_down

Thank you for your response. Keep the awesome project going.