Skip to content

Commit

Permalink
Set syntax_hl @requires_stylesheet on root doc
Browse files Browse the repository at this point in the history
The root document, after nearly all its content is moved to other,
child documents, is unlikely to have anything requiring
highlighting. Thus, the Document object's syntax_highlighter
@requires_stylesheet variable does not get set and a stylesheet
required by any child page(s) will not be written out.

To fix this, while converting the child pages, check whether any of
those pages has a syntax_highlighter with the @requires_stylesheet
variable set. If so, set this variable on the root document. This
causes Asciidoctor to write out the syntax highlighter stylesheet
while it is converting the root document (in
`lib/asciidoctor/convert.rb`).

Closes issue #34.
  • Loading branch information
owenh000 committed Jun 9, 2022
1 parent e8a927c commit e61c95a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/asciidoctor-multipage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ def convert_document(node)
# This node is the original full document which has not yet been
# processed; this is the entry point for the extension.

# Save a reference to the root document in the converter
# instance. This will be used to set the @requires_stylesheet
# variable on the root document in the write method.
@root_doc = node

# Turn off extensions to avoid running them twice.
# FIXME: DocinfoProcessor, InlineMacroProcessor, and Postprocessor
# extensions should be retained. Is this possible with the API?
Expand Down Expand Up @@ -594,6 +599,12 @@ def write(output, target)
::File.open(outfile, 'w') do |f|
f.write(doc.convert)
end
if (doc.syntax_highlighter and
doc.syntax_highlighter.write_stylesheet? doc)
root_doc = doc.mp_root.instance_variable_get(:@root_doc)
root_doc.syntax_highlighter.instance_variable_set(
:@requires_stylesheet, true)
end
end
end
end
Expand Down

0 comments on commit e61c95a

Please sign in to comment.