dwp-forge / refnotes

4 stars 6 forks source link

References rendering issues when using "include" plugin #70

Closed p-kleczek closed 7 months ago

p-kleczek commented 2 years ago

The problem occurs when RefNotes are used in conjunction with "include" plugin.

Let's say we have two pages (A and B) and page B is include into page A as follows:

page A - part 1
page B (include)
page A - part 2

The problem is that references are rendered in multiple places on page A:

but in fact it's even more messed up :(


Here's a sort of MWE for this case:

Page A:

[(:cite:refA1)]
page A - part 1
{{page>pageB&nofooter&noheader&noindent}}
page A - part 2
[(:cite:refA2)]

Page B:

page B
[(:cite:refB)]
dwp-forge commented 7 months ago

The problem is caused by implicit note rendering instruction inserted at the end of each page that contains RN references (including the pages being included). So when rendering reaches the end of included page, there would be rendering of all notes from the included page but also all notes referenced by the "parent" page up to than moment.

The main idea for the fix is to disable implicit note rendering on the included pages, so that the parent page will take care of the note rendering for all references. The Include plugin actually does apply some sanitizing to the included page instructions for various plugins. So this issue could be partially fixed in the Include plugin by removing the implicit note rendering instructions before the included instructions are merged into the parent page.

But there is one more part to the puzzle. If parent page has no references, there will be no notes rendering on that page, and with notes rendering removed from the included pages there would be a bunch of dead links for references and no notes. So instead of relying on Include plugin, I'm trying to deal with includes in RefNotes by blocking implicit rendering inside the included sections and by adding implicit rendering if there were any includes.

This should address at least the basic use cases. If there are explicit note rendering blocks on included pages, they still will be rendered and may pick up references from the preceding part of the parent page. I didn't really test that, but it should be possible to keep them apart by carefully partitioning the references into separate namespaces.

Fixed by c34c58e.