-
Notifications
You must be signed in to change notification settings - Fork 500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PDF just one chapter, with correct chap/sect numbering #166
Comments
I wouldn't want to encourage you to do option 2 as that is a very non-semantic hack. Option 1 is a much better pursuit. This need actually comes up in all outputs, not just PDF, so we likely want to solve it in core. I'm thinking something like In the meantime, the best way to do this is by writing a Treeprocessor extension. With a Treeprocessor, you can walk all the block-level nodes and modify them. In this case, you would just descend the section notes and assign a new section number. require 'asciidoctor/extensions'
include ::Asciidoctor
Extensions.register do
# A treeprocessor that increments each level-1 section number by the value of
# the `sectnumoffset` attribute. The numbers of all subsections will be
# incremented automatically since those values are calculated dynamically.
treeprocessor do
process do |document|
if (sectnumoffset = (document.attr 'sectnumoffset', 0).to_i) > 0
((document.find_by context: :section) || []).each do |sect|
next unless sect.level == 1
sect.number += sectnumoffset
end
end
nil
end
end
end I've added this extension to the extensions lab. Here's the issue in core to track. asciidoctor/asciidoctor#1113 |
This is pretty similar to #188 |
I finally got around to figuring out how to install and run this treeprocessor. Thanks! It doesn't seem to work on appendixes, though. If I try to use :sectnumoffset: on an appendix, it says "can't convert FixedNum to String" (because appendixes use letters instead of numbers for their chapter number). |
@stallio Uh oh. Could you file an issue in the extensions lab and cite and example document to test. This Treeprocessor now lives there. https://github.com/asciidoctor/asciidoctor-extensions-lab I'll provide another technique for rendering a single chapter that gets all the numbering right. Load the document using the API, delete all the other chapters from the AST (or copy the chapter you want to another AST), then render the result. Perhaps we can add that to the extensions-lab for demonstration purposes. You can see something similar in the multipage HTML converter. See https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/multipage-html5-converter.rb |
...granted, that trick is somewhat ugly, but it certainly gets the job done :) |
The sectnumoffset extension works for me when outputting HTML, but gives me this error when outputting PDF:
I use docker-asciidoctor and am running If I remove those extra flags the PDF renders fine, so somehow this extension is interfering somehow, maybe some ordering issue? |
@arosien The issue you are seeing has nothing to do with Asciidoctor PDF. It's a problem with the version of Rouge you are using and a conflict with internal Asciidoctor behavior. I'll follow-up in the issue you posted to the extension lab. See asciidoctor/asciidoctor-extensions-lab#122 |
This is also possible using the following command:
At this point, I've shared everything I can offer to accomplish this goal. There's nothing else actionable for this converter, so I'm marking it as resolved. |
I want to make a PDF of just one chapter from a book, when that chapter is not necessarily chapter 1, and yet have the chapter/section numbering be correct (so if it's chapter 2, the first section would be 2.1, etc.)
I can think of a couple ways this could work:
Is there some way to do option 2 that I'm missing?
The text was updated successfully, but these errors were encountered: