jugglerchris/rust-html2text

Preformatted text not passed to the decorator

robinkrahl opened this issue · 3 comments

pre tags will not cause a call to the decorate_preformat_* methods of the TextDecorator. Apparently, the Renderer::add_preformatted_block method is never called.

println!("{:?}", html2text::parse("<pre>test</pre>".as_bytes()).render_rich(100).into_lines());

[TaggedLine { v: [Str(TaggedString { s: "test", tag: [] })] }]

You're right - looks like that was lost in 714abad when I reworked <pre> handling. Renderer::add_preformatted_block() is obsolete (it was based on a bad assumption on my part that you couldn't have other tags in <pre> blocks) and should be removed.

I guess WrappedBlock<T> needs to track whether it's had to insert a newline and WrappedBlock<T>::add_preformatted_text() then needs both tag stacks passed in. I'll try to look at doing that in the next few days if no-one gets there first.

I think this is now fixed. I'll do a release shortly.