-
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
Add support for theming admonition blocks by type #1685
Comments
Here's how you can implement this using an extended converter. class PDFConverterAdmonitionThemePerType < (Asciidoctor::Converter.for 'pdf')
register_for 'pdf'
def convert_admonition node
type = node.attr 'name'
key_prefix = %(admonition_#{type}_)
return super if (entries = theme.each_pair.select {|name, val| name.start_with? key_prefix }).empty?
save_theme do
entries.each {|name, val| theme[%(admonition_#{name.to_s.delete_prefix key_prefix})] = val }
super
end
end
end It works by temporarily overlaying the theme keys for a specific type onto the main admontion theme keys. |
This is going to be tricky to support by default since the admonition keys are a bit inconsistent. Both the label and icon can be configured per type, except the type comes after the element in the key name. Ideally, we would switch this all around so that the type is always the second segment of the key. admonition:
border-width: 0.5
tip:
border-color: #FFFF00
icon:
name: far-lightbub
label:
font-style: italic Making that change would warrant a major version bump. I'm also wondering whether the type should be in all uppercase so it is not confused with other key names. admonition:
TIP:
border-color: #FFFF00 |
Have been trying to figure this thing out too. Any chance we land this soon? I've seen the note about the extended converter above, which is also great as a workaround. Would love to ask - if I used |
I ended up figuring out how to actually apply the extended converter (by specifying a |
A pull request to update the docs would be most welcome. |
I ended up finding what needs to happen by reading:
What would be the best place to put these to make it easier for the next human who needs to sort this out? |
Given that you were the one looking for the information, I think you would be the best one to answer that question. Where did you expect to find it? Was this page not sufficient? https://docs.asciidoctor.org/pdf-converter/latest/extend/use-converter/ If so, what information would have helped? |
Well, in hope of being able to theme them, I was hoping to find it here: https://docs.asciidoctor.org/pdf-converter/latest/theme/admonition/ But, not being able to find any mention of it there threw me into a research sprawl. |
The issue is that the page you pointed to is about the theme keys, not about extensions. These are two separate things. But I suppose we could point out explicitly that it's not currently possible to theme admonitions by type, but there is an extended converter example in the use cases that shows you how you could do it. So I could see how that transition could work. |
Right, but that's where I'd go to in order to find how to theme admonitions :-) So anyways, I'm happy to make doc updates in multiple places too but am resorting to your guidance as to where that should go. p.s. another place I'd stick some guidance is within the actual file asciidoctor-pdf/docs/modules/extend/examples/pdf-converter-admonition-theme-per-type.rb Line 1 in 803b575
|
Yep. Sounds good. I'll review and help revise what you suggest..
|
This information is now incorporated into the docs. |
Thank you! |
Current behaviour
Currently if i want to use asciidoc pdf generator with theming, it is possible (thanks to another issue) to change basic stuff for admonition blocks:
https://github.com/asciidoctor/asciidoctor-pdf/blob/master/docs/theming-guide.adoc#keys-admonition
Example:
Issue:
#444
But i cannot change these settings (especially background color) for a specific block type (e. g. caution in red or warning in orange).
Improvement: Admonition settings based on type
It would be nice to be able to configure admonition settings based on the current type.
Example:
The text was updated successfully, but these errors were encountered: