Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #448 decode character references in link URIs #450

Merged
merged 1 commit into from
May 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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