puzzle / prawn-markup

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

Underline links? #10

Open adamalbrecht opened 3 years ago

adamalbrecht commented 3 years ago

Is there a way to make <a> tags underlined and blue? If not, it would be nice if this was available to do in markup_option

Thanks!

codez commented 3 years ago

Currently no, but it should be possible to do.

We don't have that many resources for new features, but I'll keep that issue in the backlog. Pull requests are very welcome.

goulvench commented 2 years ago

Quick workaround:

# Add <u> and <color> inside links to style them as HTML links
your_html.gsub!(/<a ([^>]*)>(.*?)<\/a>/m, "<a \\1><u><color rgb=\"0000FF\">\\2</color></u></a>")

Requires Prawn-Markup 3.0.6 or greater!

@codez Can you outline how you'd see this implemented? I could try sending a PR. As I see it, this would mean adding a link entry in the markup_options hash to allow defining options, then calling start_u and start_color inside start_a (and closing them in order in end_a), and adding tests. Anything else?

codez commented 2 years ago

Yes, I think that's a good approach. Instead of calling start_u and start_color, I would directly insert the respective tags into the text in start_a and end_a. Like this the code is independent of the parsing methods that work on the stack.