Skip to content
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

Don't Run makeSection multiple times #7950

Closed
connorp opened this issue Mar 8, 2022 · 3 comments
Closed

Don't Run makeSection multiple times #7950

connorp opened this issue Mar 8, 2022 · 3 comments

Comments

@connorp
Copy link

connorp commented Mar 8, 2022

Per this discussion, even though Lua exposes the make_sections function for use in filters, most of the pandoc writers (including HTML) call makeSection themselves, even if it has already been called. If your filter creates its own div/section/similar containing element after makeSection is called the first time, the second call to makeSection recreates the original div/section, breaking the result of the filter.

It would be good if the writers were only to call makeSection if it hasn't already been run, or equivalently, if makeSection could determine whether it had already been run, and only manipulate the AST if it has yet to be run.

This strikes me as the least disruptive change to enable filters to manipulate the divs/sections created around headers. Another approach could be to add an attribute to a header that prevents a div/section from being constructed around it by makeSections, but that seems like more difficult and more clumsy.

@jgm
Copy link
Owner

jgm commented Mar 8, 2022

Agreed, we need to improve this.

@jgm
Copy link
Owner

jgm commented Mar 8, 2022

Actually, I'm not yet convinced there is a problem. makeSections is already written in such a way that it shouldn't matter if it's run twice. See the test cases for the idempotency of makeSections which I just added to confirm this...

It may be that you made alterations that defeated this, but in that case we need more information.

@connorp
Copy link
Author

connorp commented Mar 8, 2022

Okay, I revisited the Lua filter I had written that makeSections makes difficult, and I don't seem to be getting the behavior that put me off it last year. Perhaps a subsequent update has fixed this issue silently? I'll play around a little more, and if I stumble upon this problem again, I'll reopen this, but I think for now I will close it. Sorry for the runaround!

@connorp connorp closed this as completed Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants