-
Notifications
You must be signed in to change notification settings - Fork 334
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
Add exdoc:loaded event #2069
Merged
Merged
Add exdoc:loaded event #2069
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
31bbd14
Add exdoc:loaded event
josevalim 5963351
Fix lint
josevalim e2c8e93
Remove duped initialize
josevalim 4096b99
Update README.md
josevalim 35908f4
Update README.md
josevalim 2b8fe60
Remove duplication
josevalim 0916d53
Revert to swup on list
josevalim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,6 +370,8 @@ docs: [ | |
] | ||
``` | ||
|
||
On the JavaScript side, ExDoc emits the `"exdoc:loaded"` event. This event may be called multiple times, as you navigate across pages, so initialization that should happen only once must be conditional. We recommend external scripts to use `defer`, not `async`, as shown in the examples below. | ||
|
||
### Rendering Math | ||
|
||
If you write TeX-style math in your Markdown, such as `$\sum_{i}^{N} x_i$`, it ends up as raw text on the generated pages. To render expressions, we recommend using [KaTeX](https://katex.org/), a JavaScript library that turns expressions into graphics. To load and trigger KaTeX on every documentation page, we can insert the following HTML: | ||
|
@@ -381,13 +383,17 @@ If you write TeX-style math in your Markdown, such as `$\sum_{i}^{N} x_i$`, it e | |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex-copytex.min.css" rel="stylesheet" type="text/css"> | ||
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex-copytex.min.js" crossorigin="anonymous"></script> | ||
|
||
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous" | ||
onload="renderMathInElement(document.body, { | ||
delimiters: [ | ||
{left: '$$', right: '$$', display: true}, | ||
{left: '$', right: '$', display: false}, | ||
] | ||
});"></script> | ||
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous"></script> | ||
|
||
<script> | ||
window.addEventListener("exdoc:loaded", () => { | ||
renderMathInElement(document.body, { | ||
delimiters: [ | ||
{left: '$$', right: '$$', display: true}, | ||
{left: '$', right: '$', display: false}, | ||
] | ||
}) | ||
}) | ||
</script> | ||
``` | ||
|
||
|
@@ -402,7 +408,7 @@ Snippets are also objects you may want to render in a special manner. For exampl | |
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | ||
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | ||
<script> | ||
document.addEventListener("DOMContentLoaded", function () { | ||
window.addEventListener("exdoc:loaded", () => { | ||
for (const codeEl of document.querySelectorAll("pre code.vega-lite")) { | ||
try { | ||
const preEl = codeEl.parentElement; | ||
|
@@ -426,12 +432,19 @@ For more details and configuration options, see [vega/vega-embed](https://github | |
Similarly to the example above, if your Markdown includes Mermaid graph specification in `mermaid` code snippets: | ||
|
||
```html | ||
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js"></script> | ||
<script> | ||
function mermaidLoaded() { | ||
mermaid.initialize({ | ||
startOnLoad: false, | ||
theme: document.body.className.includes("dark") ? "dark" : "default" | ||
}); | ||
let initialized = false; | ||
|
||
window.addEventListener("exdoc:loaded", () => { | ||
if (!initialized) { | ||
mermaid.initialize({ | ||
startOnLoad: false, | ||
theme: document.body.className.includes("dark") ? "dark" : "default" | ||
}); | ||
initialized = true; | ||
} | ||
|
||
let id = 0; | ||
for (const codeEl of document.querySelectorAll("pre code.mermaid")) { | ||
const preEl = codeEl.parentElement; | ||
|
@@ -445,9 +458,8 @@ Similarly to the example above, if your Markdown includes Mermaid graph specific | |
preEl.remove(); | ||
}); | ||
} | ||
} | ||
}); | ||
</script> | ||
<script async src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js" onload="mermaidLoaded();"></script> | ||
``` | ||
|
||
For more details and configuration options, see the [Mermaid usage docs](https://mermaid-js.github.io/mermaid/#/usage). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now duplicated and could be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I will push it soon. And to be clear, the next line does:
That would still be fine, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I can confirm this one breaks it and nothing is being marked on the sidebar. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will ship a new version with this still using
swup:page:view
. If you have suggestions on how to unify it, it would be very welcome. :) Thank you ❤️There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I missed that this init is lazy and will always come after the first
exdoc:loaded
. Pushed changes to unify and make more clear in #2070