-
DescriptionI have created my first shortcode extension! It adds bootstrap tooltips over a bootstrap info icon. It works, but I wondered if it can be easier. Bootstrap tooltips have to be initialized. Per the bootstrap documentation I can do this in quarto with some YAML on the page that wants to use them: include-after-body:
text: |
<script>
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
</script> But is there a way to do this inside the extension so users don't have to include this in their
in my lua code but, that didn't work. (I did try this function in my |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Defining a function does not make it used. The only code used in your Lua file is: You don't even call your It's unclear with your current code how you can tell "it does not work" as there is nothing to reproduce. Edit: some examples |
Beta Was this translation helpful? Give feedback.
-
Additionally, you are not defining/inserting your JavaScript the same way and in the same place, i.e., "after body", see https://quarto.org/docs/extensions/lua-api.html#html-dependencies |
Beta Was this translation helpful? Give feedback.
This is the key step. The javascript needs to run after the body has been created. I must use the
afterBody
kwarg. So, changing the function to:and then using the function inside my main
return {}
worked.