diff --git a/README.md b/README.md
index bc66b1a..6626b21 100644
--- a/README.md
+++ b/README.md
@@ -109,6 +109,9 @@ Beside these options handled by Prawn / prawn-table, the following values may be
- `:radio`
- `:checked`: The char to print for a checked radio. Default is '◉'.
- `:unchecked`: The char to print for an unchecked radio. Default is '○'.
+- `:link`
+ - `:color`: The link color, which can be specified in either RGB or CMYK format.
+ - `:underline`: Specifies whether the link should be underlined. Default is false..
## Development
diff --git a/lib/prawn/markup/processor/text.rb b/lib/prawn/markup/processor/text.rb
index 6fa65e5..7494cf7 100644
--- a/lib/prawn/markup/processor/text.rb
+++ b/lib/prawn/markup/processor/text.rb
@@ -11,15 +11,30 @@ def self.prepended(base)
end
def start_a
+ start_u if link_options[:underline]
+ start_color(link_options[:color]) if link_options[:color].any?
append_text("")
end
alias start_link start_a
def end_a
append_text('')
+ end_color if link_options[:color].any?
+ end_u if link_options[:underline]
end
alias end_link end_a
+ def link_options
+ @link_options ||= HashMerger.deep(default_link_options, options[:link] || {})
+ end
+
+ def default_link_options
+ {
+ color: {},
+ underline: false
+ }
+ end
+
def start_b
append_text('')
end
@@ -78,8 +93,9 @@ def end_sup
append_text('')
end
- def start_color
- rgb, c, m, y, k = current_attrs.values_at('rgb', 'c', 'm', 'y', 'k')
+ def start_color(options = {})
+ options = current_attrs unless options.any?
+ rgb, c, m, y, k = options.transform_keys(&:to_s).values_at('rgb', 'c', 'm', 'y', 'k')
if [c, m, y, k].all?
append_text("")
diff --git a/spec/prawn/markup/showcase_spec.rb b/spec/prawn/markup/showcase_spec.rb
index c827255..00e4bda 100644
--- a/spec/prawn/markup/showcase_spec.rb
+++ b/spec/prawn/markup/showcase_spec.rb
@@ -19,7 +19,8 @@
iframe: {
placeholder: ->(src) { "Embedded content: #{src}" }
},
- input: { symbol_font: 'DejaVu', symbol_font_size: 16 }
+ input: { symbol_font: 'DejaVu', symbol_font_size: 16 },
+ link: { color: { rgb: "0000FF" }, underline: true }
}
doc.markup(html)
# lookatit