Closed trych closed 6 months ago
One approach for the API might be to add a method on the $blocks
collection which would return a new collection of blocks with modified "text"
/ "markdown"
blocks that contain numbered <sup>
tags and then a new custom "footnotes"
block type appended to the end?
Then users could still loop through the blocks manually and could even customize the output of the footnotes themselves with a custom snippet...
I agree with your suggestion @s3ththompson, I think this would be the best way to set it up. The issue is that for now, one cannot register methods to the Blocks object (see kirby.nolt.io/228). So until this feature is added there's no integrated way to achieve this...
I have put together some methods for you to be able to output notes in the meantime, but keep in mind that it'll probably need to be updated once Blocks methods are available.
I admit, I don't quite understand @s3ththompson's proposed solution. But would it not be sufficient to have some sort of global counter per page that keeps counting up through all the blocks whenever it finds a footnote and then the footnote receives its number from that counter?
Edit: Ah, sorry, I hadn't seen your linked method. At first glance it looks this is a bit similar to what I suggested (if I understand this right?). I will give this a try in my setup.
@trych a global counter would fix the numbering of inline <sup>
tags, but it wouldn't solve the problem of how (and where) to output the final list of footnotes at the bottom of the page.
given that the whole point of Blocks is to introduce structured "blocks" of content, it seems natural to make the final list of footnotes at the bottom of the page a Block itself.
Ultimately though, Kirby's Blocks system doesn't have great primitives or patterns (yet) for creating Blocks that are aware of siblings and relative positioning. Because they are so self-contained, they make implementing a cross-page feature like footnotes tricky.
@sylvainjule just an FYI, i've been thinking about writing an extension to the Writer block to add support for inline WYSIWYG footnotes per this example. I'm assuming that would probably warrant a new plugin right? If you disagree, I'd be happy to work out the right way to extend kirby-footnotes
and submit a PR instead.
@sylvainjule just an FYI, i've been thinking about writing an extension to the Writer block to add support for inline WYSIWYG footnotes per this example. I'm assuming that would probably warrant a new plugin right? If you disagree, I'd be happy to work out the right way to extend
kirby-footnotes
and submit a PR instead.
Sounds great! I think having it as a new plugin would be easier to maintain for both of us indeed, but we should probably sync the output syntax so that editors can use one, the other, or both simultaneously with the same markup output.
@sylvainjule I just gave your new Blocks sample snippet a try. While it does handle the numbering correctly now over several blocks, it removes the formatting completely, from my text. That means the markdown is not parsed and all the kirbytags are not parsed either. This refers to the markdown blocks only, with text blocks it seems to work fine.
Do you now what could be causing this? Does the new withoutBlocksFootnotes()
method not parse markdown?
This is what I get now:
This is what I got with the old methods (that didn't allow the numbering over several blocks):
Edit: Had a look at the plugin code and it seems that the $kt
argument of the withoutBlocksFootnotes()
method is set to false
when I think it should be set to true
? Referring to this line.
Thank you for the temporary solution @sylvainjule, as @trych pointed it out, the withoutBlocksFootnotes()
method should be set to true:
'withoutBlocksFootnotes' => function($field, $startAt) {
return Footnotes::convert($field->text(), false, true, false, false, $startAt);
}
To
'withoutBlocksFootnotes' => function($field, $startAt) {
return Footnotes::convert($field->text(), false, true, false, true, $startAt);
}
I have added a blocks method built upon the collectFootnotes
worklow PRed by @rasteiner, replacing the previous way of dealing with footnotes in blocks.
Thanks for this great plugin! I was just giving it a try with the new blocks. And while I can get it to work within one block like so
it restarts the numbering of the footnotes with each block anew. That means I will have a footnote numbering like
1, 2, 3, 1, 2, 1, 2
etc. when I use more than one block.It would be nice, if there would be an easy way to continue the numbering from the previous block.