diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2014-07-15 01:57:27 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2014-07-15 01:57:27 -0600 |
| commit | bab16feadd8c35b462b7b5430d0f2ab255b17d71 (patch) | |
| tree | 4a418b9eb89f27196a06406804e13a021f50b7f7 | |
| parent | 2088cc3508d0fd365cd0856d8fc0bfae0ab1b915 (diff) | |
resolves #589 basic support for resolving xref from reftext
| -rw-r--r-- | features/xref.feature | 82 | ||||
| -rw-r--r-- | lib/asciidoctor/converter/html5.rb | 2 | ||||
| -rw-r--r-- | lib/asciidoctor/substitutors.rb | 18 |
3 files changed, 94 insertions, 8 deletions
diff --git a/features/xref.feature b/features/xref.feature index d9c29025..c2ec2592 100644 --- a/features/xref.feature +++ b/features/xref.feature @@ -19,7 +19,7 @@ Feature: Cross References When it is converted to html Then the result should match the HTML structure """ - table.tableblock.frame-all.grid-all style='width: 100%;' + table.tableblock.frame-all.grid-all.spread colgroup col style='width: 100%;' tbody @@ -34,3 +34,83 @@ Feature: Cross References .sectionbody .paragraph: p Instructions go here. """ + + + Scenario: Create a cross reference using the target section title + Given the AsciiDoc source + """ + == Section One + + content + + == Section Two + + refer to <<Section One>> + """ + When it is converted to html + Then the result should match the HTML structure + """ + .sect1 + h2#_section_one Section One + .sectionbody: .paragraph: p content + .sect1 + h2#_section_two Section Two + .sectionbody: .paragraph: p + 'refer to + a href='#_section_one' Section One + """ + + + Scenario: Create a cross reference using the target reftext + Given the AsciiDoc source + """ + [reftext="the first section"] + == Section One + + content + + == Section Two + + refer to <<the first section>> + """ + When it is converted to html + Then the result should match the HTML structure + """ + .sect1 + h2#_section_one Section One + .sectionbody: .paragraph: p content + .sect1 + h2#_section_two Section Two + .sectionbody: .paragraph: p + 'refer to + a href='#_section_one' the first section + """ + + + Scenario: Create a cross reference using the formatted target title + Given the AsciiDoc source + """ + == Section *One* + + content + + == Section Two + + refer to <<Section *One*>> + """ + When it is converted to html + Then the result should match the HTML structure + """ + .sect1 + h2#_section_strong_one_strong + 'Section + strong One + .sectionbody: .paragraph: p content + .sect1 + h2#_section_two Section Two + .sectionbody: .paragraph: p + 'refer to + a href='#_section_strong_one_strong' + 'Section + strong One + """ diff --git a/lib/asciidoctor/converter/html5.rb b/lib/asciidoctor/converter/html5.rb index 5a797e64..70429373 100644 --- a/lib/asciidoctor/converter/html5.rb +++ b/lib/asciidoctor/converter/html5.rb @@ -945,7 +945,7 @@ Your browser does not support the video tag. case node.type when :xref refid = (node.attr 'refid') || target - # FIXME seems like text should be prepared already + # NOTE we lookup text in converter because DocBook doesn't need this logic text = node.text || (node.document.references[:ids][refid] || %([#{refid}])) %(<a href="#{target}">#{text}</a>) when :ref diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb index e21af764..93c84e8f 100644 --- a/lib/asciidoctor/substitutors.rb +++ b/lib/asciidoctor/substitutors.rb @@ -962,23 +962,29 @@ module Substitutors fragment = id end - # handles form: id - if !path - refid = fragment - target = "##{fragment}" # handles forms: doc#, doc.adoc#, doc#id and doc.adoc#id - else + if path path = Helpers.rootname(path) # the referenced path is this document, or its contents has been included in this document if @document.attributes['docname'] == path || @document.references[:includes].include?(path) refid = fragment path = nil - target = "##{fragment}" + target = %(##{fragment}) else refid = fragment ? %(#{path}##{fragment}) : path path = "#{@document.attributes['relfileprefix']}#{path}#{@document.attributes.fetch 'outfilesuffix', '.html'}" target = fragment ? %(#{path}##{fragment}) : path end + # handles form: id or Section Title + else + # resolve fragment as reftext if cannot be resolved as refid and looks like reftext + if !(@document.references[:ids].has_key? fragment) && + ((fragment.include? ' ') || fragment.downcase != fragment) && + (resolved_id = RUBY_MIN_VERSION_1_9 ? (@document.references[:ids].key fragment) : (@document.references[:ids].index fragment)) + fragment = resolved_id + end + refid = fragment + target = %(##{fragment}) end Inline.new(self, :anchor, reftext, :type => :xref, :target => target, :attributes => {'path' => path, 'fragment' => fragment, 'refid' => refid}).convert } |
