Skip to content

Commit

Permalink
resolves #448 decode character references in link URIs (PR #450)
Browse files Browse the repository at this point in the history
- decode character references (e.g., &) in link URIs
- update terminology for refering to character references
- minor code cleanups
  • Loading branch information
mojavelinux committed May 26, 2016
1 parent 1b530ae commit 248292a
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/asciidoctor-pdf/formatted_text/transform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ module Pdf
module FormattedText
class Transform
EOL = "\n"
NamedEntityTable = {
:lt => '<',
:gt => '>',
:amp => '&',
:quot => '"',
:apos => '\''
CharEntityTable = {
lt: '<',
gt: '>',
amp: '&',
quot: '"',
apos: '\''
}
CharRefRx = /&(?:#([0-9]{2,5})|(#{CharEntityTable.keys * '|'}));/
#ZeroWidthSpace = %(\u200b)

def initialize(options = {})
Expand Down Expand Up @@ -103,7 +104,7 @@ def apply(parsed)
previous_fragment_is_text = true
when :entity
if (name = node[:name])
text = NamedEntityTable[name]
text = CharEntityTable[name]
else
# FIXME AFM fonts do not include a thin space glyph; set fallback_fonts to allow glyph to be resolved
text = [node[:number]].pack('U*')
Expand Down Expand Up @@ -183,15 +184,15 @@ def build_fragment(fragment, tag_name, attrs = {})
# fragment[:character_spacing] = value.to_f
#end
when :a
# QUESTION shouldn't anchor, link and name be mutually exclusive?
if !fragment[:anchor] && (value = attrs[:anchor])
fragment[:anchor] = value
end
if !fragment[:link] && (value = attrs[:href])
fragment[:link] = value
fragment[:link] = (value.include? '&') ? value.gsub(CharRefRx) {
$2 ? CharEntityTable[$2.to_sym] : [$1.to_i].pack('U*')
} : value
end
#if !fragment[:local] && (value = attrs[:local])
# fragment[:local] = value
#end
if !fragment[:name] && (value = attrs[:name])
fragment[:name] = value
fragment[:callback] = InlineDestinationMarker
Expand Down

0 comments on commit 248292a

Please sign in to comment.