Skip to content
Permalink
Browse files

resolves #481, #301 encode anchors containing characters outside ASCI…

…I range in hex (PR #499)

- hex encode anchors that contain characters outside the ASCII range
- squelch the following warning: regexp match /.../n against to UTF-8 string (pdf-core < 0.6.1)
  • Loading branch information...
mojavelinux committed Aug 8, 2016
1 parent f083ad8 commit c3955c5cd7010dc9acb0b54f0e477ec2c81750c6
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/asciidoctor-pdf/converter.rb
@@ -313,9 +313,15 @@ def convert_section sect, opts = {}
# QUESTION should we store page_start & destination in internal map?
# TODO ideally, this attribute should be pdf-page-start
sect.set_attr 'page_start', page_number
# NOTE auto-generate an anchor if one doesn't exist so TOC works
# QUESTION should we just assign the section this generated id?
sect.set_attr 'anchor', (sect_anchor = sect.id || %(__autoid-#{page_number}-#{y.ceil}))
if (sect_anchor = sect.id)
# NOTE encode anchor in hex if it contains characters outside the ASCII range
sect_anchor = %(0x#{::PDF::Core.string_to_hex sect_anchor}) unless sect_anchor.ascii_only?
else
# NOTE auto-generate an anchor if one doesn't exist so TOC works
sect_anchor = %(__autoid-#{page_number}-#{y.ceil})
end
sect.set_attr 'anchor', sect_anchor
add_dest_for_block sect, sect_anchor
sect.chapter? ? (layout_chapter_title sect, title, align: align) : (layout_heading title, align: align)
end
@@ -1391,15 +1397,17 @@ def convert_inline_anchor node
%(<a href="#{node.target}">#{node.text || path}</a>)
else
refid = node.attributes['refid']
# NOTE encode anchor in hex if it contains characters outside the ASCII range
anchor = refid.ascii_only? ? refid : %(0x#{::PDF::Core.string_to_hex refid})
# NOTE reference table is not comprehensive (we don't catalog all inline anchors)
if (reftext = node.document.references[:ids][refid])
%(<a anchor="#{refid}">#{node.text || reftext}</a>)
%(<a anchor="#{anchor}">#{node.text || reftext}</a>)
else
# NOTE we don't catalog all inline anchors, so we can't warn here (maybe once conversion is complete)
#source = $VERBOSE ? %( in source:\n#{node.parent.lines * "\n"}) : nil
#warn %(asciidoctor: WARNING: reference '#{refid}' not found#{source})
#%[(see #{node.text || %([#{refid}])})]
%(<a anchor="#{refid}">#{node.text || "[#{refid}]"}</a>)
%(<a anchor="#{anchor}">#{node.text || "[#{refid}]"}</a>)
end
end
when :ref

0 comments on commit c3955c5

Please sign in to comment.
You can’t perform that action at this time.