-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Store "unnumbered" class in DocBook role attribute #8481
Conversation
Thank you! I think the code in Edit: also perhaps maybeToList, but that depends on the chosen approach. |
Is the use of |
@tarleb Thank you. I did look for an import of Data.List and couldn't find one, so I thought it would be too intrusive to add. It can certainly be made more readable with Data.List functions. @jgm No, there is no standard method (that I know of). In the issue descriptions people mentioned "workarounds" just to be able to find these sections, so that's the intention of this: The XPath selector to identify the sections that are supposed to be unnumbered is deterministic, but the work to then act accordingly with section labelling has to be done in the stylesheets. |
No problem to use Data.List. |
@tarleb @jgm On second thought, this is a trivial filter to create since the class token already comes in from the MD reader, and we can put attributes pairs that create XML attributes. Maybe just write it and add to the filters repo and point to it? That would allow anyone to tailor which attribute and token to use, if they already have a stylesheet. My Lua is not stellar, but something like below would do it? That would remove the need to hardcode it in entirely.
|
Pandoc already does quite a few slightly opinionated things in various writers, so I think that making the change in the writer would be fine. Slightly shorter filter: function Header (hdr)
if hdr.classes:includes 'unnumbered' then
hdr.attributes.role = 'unnumbered'
return hdr
end
end |
I agree, I think it's fine to change this in the writer. |
Thank you. I will rewrite the enrichRole function and update. |
8c9ca0e
to
157d556
Compare
Markdown allows marking a heading as unnumbered, which is stored as a class token internally. This change will recognize this particular class token and append it to the role attribute, or create a role attribute with it if needed. This does not imply any processing in DocBook but is intended to let customized stylesheets identify these sections and act accordingly. fixes jgm#1402
157d556
to
fec74c6
Compare
@tarleb It is now more succinct. The Prelude lookup sufficed for this. To be honest I'm not sure it's more readable. I'll gladly take further pointers on changing it. |
enrichRole mattrs cls = [("role",rolevals) | rolevals /= ""]<>(filter (\x -> (fst x) /= "role") mattrs) | ||
where | ||
rolevals = T.unwords((filter (`elem` cand) cls)<>(maybeToList(lookup "role" mattrs))) | ||
cand = ["unnumbered"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks! This is good to merge from my POV.
Your comments on readability made me wonder, and I ended up writing an (untested!!) version trying to strike a balance between readability and and conciseness. Not sure if I succeeded, but here we go:
enrichRole :: [(Text, Text)] -> [Text] -> [(Text, Text)]
enrichRole mattrs cls = [("role", T.unword roles) | not (null roles)] <> nonRole
where
(roleAttr, nonRole) = partition (\(key, _v) -> key == "role") mattrs
roles = nub $ ["unnumbered" | "unnumbered" `elem` cls] <> map snd roleAttr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tarleb Thank you for the suggestion! I'm fine either way, although having cand
separate was something I hoped to keep, as I can envision there are more class tokens that would make sense to add as role tokens in DocBook, and adding to that list is (perhaps) less intimidating to future contributors. Let me know if you would prefer it changed, and if not, if there's more to do before merge (rebase on current master?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, keeping the list of "role classes" separate seems sensible.
I just noticed that some lines break the 80 chars limit, we generally want to keep lines below that length. Once that's fixed we can squash-merge everything into a single commit; no need for a rebase.
EDIT: We're less strict about this limit in the tests, those are fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tarleb Sorry, didn't get to the 80char fix before it merged. Will keep it in mind in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem at all. Thanks again, looking forward to the next one!
Markdown allows marking a heading as unnumbered, which is stored as a class token internally. This change will recognize this particular class token and append it to the role attribute, or create a role attribute with it if needed. This does not imply any processing in DocBook but is intended to let customized stylesheets identify these sections and act accordingly. Closes jgm#1402
Markdown allows marking a heading as unnumbered, which is stored as a class token internally. This change will recognize this particular class token and append it to the role attribute, or create a role attribute with it if needed. This does not imply any processing in DocBook but is intended to let customized stylesheets identify these sections and act accordingly.
The enrichRole function is intentionally designed to be able to take more class tokens in the future by extending the
cand
listfixes #1402