monollonom Posted March 29, 2023 Share Posted March 29, 2023 TextformatterFootnotes Github: https://github.com/eprcstudio/TextformatterFootnotes Modules directory: https://processwire.com/modules/textformatter-footnotes/ This textformatter adds footnotes using Markdown Extra’s syntax, minus Markdown About This textformatter was primarly created to ease the addition of footnotes within HTML textareas (CKEditor or TinyMCE) using Markdown Extra’s syntax. It will also retain any inline formatting tags that are whitelisted. Usage To create a footnote reference, add a caret and an identifier inside brackets ([^1]). Then add the footnote in its own line using another caret and number inside brackets with a colon and text ([^1]: My footnote.). It will be put automatically inside the footnotes block at the end of the text. Notes: the identifier has to be a number but it is permissive in that you can put in the wrong order and it will be numbered back sequentially there is no support for indentation, though since <br> tags are allowed you should be fine if a footnote has no corresponding reference, it will be ignored and left as is Options In the module settings, you can change the icon (string) used as the backreference link but also the classes used for the wrapper, the reference and backreference links. You can also edit the list of whitelisted HTML tags that won’t be removed in the footnotes. Hook If you want to have a more granular control over the footnotes (e.g. per field), you can use this hook: $wire->addHookBefore("TextformatterFootnotes::addFootnotes", function(HookEvent $event) { $str = $event->arguments(0); $options = $event->arguments(1); $field = $event->arguments(2); if($field != "your-field-name") return; // Say you want to change the icon for a <svg> $options["icon"] = file_get_contents("{$event->config->paths->templates}assets/icons/up.svg"); // Or change the wrapper’s class $options["wrapperClass"] = "my-own-wrapper-class"; // Put back the updated options array $event->arguments(1, $options); }); Check the source code for more options. 7 1 Link to comment Share on other sites More sharing options...
gornycreative Posted April 10, 2023 Share Posted April 10, 2023 Small thing, I was getting an error without any custom options defined. As is, the line where you set up the arguments: public function ___addFootnotes($str, $options = [], $field = "") { This results in an error if you do not pass an additional options array - e.g. just a $str and $field. An error on line 83 array_merge results - second argument is not an array. I didn't pull the repo via git so I can't do a PR handily, but reversing the parameter order resolves it. public function ___addFootnotes($str, $field = "", $options = []) { 1 Link to comment Share on other sites More sharing options...
monollonom Posted April 10, 2023 Author Share Posted April 10, 2023 Quick question regarding your usage: were you calling the function on its own? Or was it through the textformatter applied to a text field? What I could do is check if $options is not an array and in this case assume it's $field, but the $field argument is not used within the function as it's just there so you can do field-specific stuff using the hook. Edit: oh wait I just saw my mistake... on line 44 ? 2 Link to comment Share on other sites More sharing options...
monollonom Posted April 10, 2023 Author Share Posted April 10, 2023 Issue fixed and module updated! Should be good but let me know if you notice anything else @gornycreative 3 Link to comment Share on other sites More sharing options...
gornycreative Posted April 10, 2023 Share Posted April 10, 2023 Cool, yes adding the empty parameter was ? 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now