summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2018-04-14 03:33:26 -0600
committerDan Allen <dan.j.allen@gmail.com>2018-04-19 01:47:05 -0600
commit3d51e447e2b2dfd8662048de0d53f627067f0fa7 (patch)
treeb286c519b3f6e50a4578e2d7760af592d9a887b8
parent349a34ab1c8f63d6e7842e6ac970f4b2889456bf (diff)
resolves #2387 allow role to be set on document
- allow role to be set on document using block attribute (shorthand or longhand) - assign role to docrole attribute on document - add role to CSS classes on body in HTML5 output
-rw-r--r--lib/asciidoctor/converter/html5.rb9
-rw-r--r--lib/asciidoctor/parser.rb3
-rw-r--r--test/sections_test.rb4
3 files changed, 11 insertions, 5 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..45e76798 100644
--- a/lib/asciidoctor/parser.rb
+++ b/lib/asciidoctor/parser.rb
@@ -157,6 +157,9 @@ class Parser
else
doc_id = document.id
end
+ if (doc_role = block_attributes['role'])
+ document.attributes['docrole'] = doc_role
+ end
if (doc_reftext = block_attributes['reftext'])
document.attributes['reftext'] = doc_reftext
end
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