diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2018-04-19 02:12:14 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-19 02:12:14 -0600 |
| commit | 36fcf8591b0a3d7ff140f8bf26142c875e6043f2 (patch) | |
| tree | e94c1cc45f1aaf064631c2a287f1ee0eb3f8acb2 | |
| parent | 349a34ab1c8f63d6e7842e6ac970f4b2889456bf (diff) | |
| parent | 60dd2aae617f3f88cfbfb31edec1237c97238fcb (diff) | |
merge PR #2666
resolves #2387 allow role to be set on document
| -rw-r--r-- | lib/asciidoctor/converter/html5.rb | 9 | ||||
| -rw-r--r-- | lib/asciidoctor/parser.rb | 43 | ||||
| -rw-r--r-- | test/sections_test.rb | 4 |
3 files changed, 30 insertions, 26 deletions
diff --git a/lib/asciidoctor/converter/html5.rb b/lib/asciidoctor/converter/html5.rb index 5bba5642..be39a11d 100644 --- a/lib/asciidoctor/converter/html5.rb +++ b/lib/asciidoctor/converter/html5.rb @@ -115,13 +115,14 @@ module Asciidoctor end result << '</head>' - body_attrs = [] - body_attrs << %(id="#{node.id}") if node.id + body_attrs = node.id ? [%(id="#{node.id}")] : [] if (sectioned = node.sections?) && (node.attr? 'toc-class') && (node.attr? 'toc') && (node.attr? 'toc-placement', 'auto') - body_attrs << %(class="#{node.doctype} #{node.attr 'toc-class'} toc-#{node.attr 'toc-position', 'header'}") + classes = [node.doctype, (node.attr 'toc-class'), %(toc-#{node.attr 'toc-position', 'header'})] else - body_attrs << %(class="#{node.doctype}") + classes = [node.doctype] end + classes << (node.attr 'docrole') if node.attr? 'docrole' + body_attrs << %(class="#{classes * ' '}") body_attrs << %(style="max-width: #{node.attr 'max-width'};") if node.attr? 'max-width' result << %(<body #{body_attrs * ' '}>) diff --git a/lib/asciidoctor/parser.rb b/lib/asciidoctor/parser.rb index 72410229..5ebfd137 100644 --- a/lib/asciidoctor/parser.rb +++ b/lib/asciidoctor/parser.rb @@ -122,19 +122,19 @@ class Parser # returns the Hash of orphan block attributes captured above the header def self.parse_document_header(reader, document) # capture lines of block-level metadata and plow away comment lines that precede first block - block_attributes = parse_block_metadata_lines reader, document + block_attrs = parse_block_metadata_lines reader, document + doc_attrs = document.attributes # special case, block title is not allowed above document title, # carry attributes over to the document body - if (implicit_doctitle = is_next_line_doctitle? reader, block_attributes, document.attributes['leveloffset']) && - (block_attributes.key? 'title') - return document.finalize_header block_attributes, false + if (implicit_doctitle = is_next_line_doctitle? reader, block_attrs, doc_attrs['leveloffset']) && block_attrs['title'] + return document.finalize_header block_attrs, false end # yep, document title logic in AsciiDoc is just insanity # definitely an area for spec refinement assigned_doctitle = nil - unless (val = document.attributes['doctitle']).nil_or_empty? + unless (val = doc_attrs['doctitle']).nil_or_empty? document.title = assigned_doctitle = val end @@ -142,42 +142,43 @@ class Parser if implicit_doctitle source_location = reader.cursor if document.sourcemap document.id, _, doctitle, _, atx = parse_section_title reader, document - unless assigned_doctitle - document.title = assigned_doctitle = doctitle - end + document.title = assigned_doctitle = doctitle unless assigned_doctitle + document.header.source_location = source_location if source_location # default to compat-mode if document uses atx-style doctitle - document.set_attr 'compat-mode' unless atx || (document.attribute_locked? 'compat-mode') - if (separator = block_attributes['separator']) - document.set_attr 'title-separator', separator unless document.attribute_locked? 'title-separator' + doc_attrs['compat-mode'] = '' unless atx || (document.attribute_locked? 'compat-mode') + if (separator = block_attrs['separator']) + doc_attrs['title-separator'] = separator unless document.attribute_locked? 'title-separator' end - document.header.source_location = source_location if source_location - document.attributes['doctitle'] = section_title = doctitle - if (doc_id = block_attributes['id']) + doc_attrs['doctitle'] = section_title = doctitle + if (doc_id = block_attrs['id']) document.id = doc_id else doc_id = document.id end - if (doc_reftext = block_attributes['reftext']) - document.attributes['reftext'] = doc_reftext + if (doc_role = block_attrs['role']) + doc_attrs['docrole'] = doc_role + end + if (doc_reftext = block_attrs['reftext']) + doc_attrs['reftext'] = doc_reftext end - block_attributes = {} + block_attrs = {} parse_header_metadata reader, document document.register :refs, [doc_id, document] if doc_id end - unless (val = document.attributes['doctitle']).nil_or_empty? || val == section_title + unless (val = doc_attrs['doctitle']).nil_or_empty? || val == section_title document.title = assigned_doctitle = val end # restore doctitle attribute to original assignment - document.attributes['doctitle'] = assigned_doctitle if assigned_doctitle + doc_attrs['doctitle'] = assigned_doctitle if assigned_doctitle # parse title and consume name section of manpage document parse_manpage_header(reader, document) if document.doctype == 'manpage' - # NOTE block_attributes are the block-level attributes (not document attributes) that + # NOTE block_attrs are the block-level attributes (not document attributes) that # precede the first line of content (document title, first section or first block) - document.finalize_header block_attributes + document.finalize_header block_attrs end # Public: Parses the manpage header of the AsciiDoc source read from the Reader diff --git a/test/sections_test.rb b/test/sections_test.rb index 8194104f..c98e9c41 100644 --- a/test/sections_test.rb +++ b/test/sections_test.rb @@ -466,8 +466,10 @@ content doc = document_from_string input assert_empty doc.blocks[0].attributes output = doc.convert + assert_css '#idname', output, 1 assert_css 'body#idname', output, 1 - assert_css '.rolename', output, 0 + assert_css '.rolename', output, 1 + assert_css 'body.rolename', output, 1 end end |
