Skip to content

Commit

Permalink
Merge pull request #66 from mojavelinux/issue-27
Browse files Browse the repository at this point in the history
resolves #27 fix xref between chapter files
  • Loading branch information
mojavelinux committed Jan 11, 2016
2 parents 9f5a896 + f0125eb commit 3bfc499
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/asciidoctor-epub3/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,8 @@ def inline_anchor node
when :xref
refid = (node.attr 'refid') || target
id_attr = unless @xrefs_used.include? refid
# QUESTION should we just drop id attribute in this case?
refid = refid.gsub '#', '--' if refid.include? '#'
@xrefs_used << refid
%( id="xref-#{refid}")
end
Expand Down
17 changes: 9 additions & 8 deletions lib/asciidoctor-epub3/spine_item_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def process doc, reader, target, attributes
warn %(asciidoctor: WARNING: #{reader.line_info}: include file not found: #{include_file})
return
end
inherited_attributes = spine_doc.attributes.dup
%w(spine doctitle docfile docdir docname).each {|key| inherited_attributes.delete key }
inherited_attrs = spine_doc.attributes.dup
# QUESTION should we keep backend-epub3 for convenience?
%w(backend-epub3 backend-epub3-doctype-book docdir docfile docname doctitle outfilesuffix spine).each {|key| inherited_attrs.delete key }

# parse header to get author information
spine_item_doc_meta = ::Asciidoctor.load_file include_file,
Expand All @@ -25,18 +26,18 @@ def process doc, reader, target, attributes
# blank out author information if present in sub-document
# FIXME this is a huge hack...we need a cleaner way to do this; perhaps an API method that retrieves all the author attribute names
if spine_item_doc_meta.attr? 'author'
%w(author firstname lastname email authorinitials authors authorcount).each {|key| inherited_attributes.delete key }
%w(author firstname lastname email authorinitials authors authorcount).each {|key| inherited_attrs.delete key }
idx = 1
while inherited_attributes.key? %(author_#{idx})
%W(author_#{idx} firstname_#{idx} lastname_#{idx} email_#{idx} authorinitials_#{idx}).each {|key| inherited_attributes.delete key }
while inherited_attrs.key? %(author_#{idx})
%W(author_#{idx} firstname_#{idx} lastname_#{idx} email_#{idx} authorinitials_#{idx}).each {|key| inherited_attrs.delete key }
idx += 1
end
end

# REVIEW reaching into converter to resolve document id feels like a hack; should happen in Asciidoctor parser
# also, strange that "id" doesn't work here
inherited_attributes['css-signature'] = DocumentIdGenerator.generate_id spine_item_doc_meta
inherited_attributes['docreldir'] = ::File.dirname target
inherited_attrs['css-signature'] = DocumentIdGenerator.generate_id spine_item_doc_meta
inherited_attrs['docreldir'] = ::File.dirname target

# NOTE can't assign spine document as parent since there's too many assumptions in the Asciidoctor processor
spine_item_doc = ::Asciidoctor.load_file include_file,
Expand All @@ -47,7 +48,7 @@ def process doc, reader, target, attributes
backend: 'epub3-xhtml5',
doctype: :article,
header_footer: true,
attributes: inherited_attributes
attributes: inherited_attrs

# restore attributes to those defined in the document header
spine_item_doc.restore_attributes
Expand Down

0 comments on commit 3bfc499

Please sign in to comment.