-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for DocumenterVitepress
Calling to_documenter now returns an object wrapping the plot data. This can be used to alter behaviour based on the documentation rendering backend. Signed-off-by: Fabian Nawratil <[email protected]>
- Loading branch information
Showing
11 changed files
with
133 additions
and
20 deletions.
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 |
---|---|---|
|
@@ -4,4 +4,6 @@ | |
/Manifest.toml | ||
/docs/Manifest.toml | ||
/docs/build/ | ||
testdebug.jl | ||
testdebug.jl | ||
|
||
.vscode/ |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [0.2.0] - 2025-01-02 | ||
|
||
### Added | ||
|
||
- DocumenterVitepress extension to circumvent the limitation of raw javascript code in Vue. | ||
|
||
### Changed | ||
|
||
- The `to_documenter` function no longer directly returns HTML, but rather an object for which `Base.show(::MIME"text/html")` is defined. |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "PlotlyDocumenter" | ||
uuid = "9b90f1cd-2639-4507-8b17-2fbe371ceceb" | ||
authors = ["Alberto Mengali <[email protected]>"] | ||
version = "0.1.3" | ||
version = "0.2.0" | ||
|
||
[deps] | ||
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" | ||
|
@@ -10,25 +10,28 @@ PackageExtensionCompat = "65ce6f38-6b18-4e1d-a461-8949797d7930" | |
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | ||
|
||
[weakdeps] | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
DocumenterVitepress = "4710194d-e776-4893-9690-8d956a29c365" | ||
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5" | ||
PlotlyLight = "ca7969ec-10b3-423e-8d99-40f33abb42bf" | ||
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a" | ||
PlotlyLight = "ca7969ec-10b3-423e-8d99-40f33abb42bf" | ||
|
||
[extensions] | ||
DocumenterVitepressPlotsExt = ["DocumenterVitepress", "Documenter"] | ||
PlotlyBaseExt = "PlotlyBase" | ||
PlotlyJSExt = "PlotlyJS" | ||
PlotlyLightExt = "PlotlyLight" | ||
|
||
[compat] | ||
Downloads = "1" | ||
HypertextLiteral = "0.9" | ||
PackageExtensionCompat = "1" | ||
Downloads = "1" | ||
julia = "1.6" | ||
|
||
[extras] | ||
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5" | ||
PlotlyLight = "ca7969ec-10b3-423e-8d99-40f33abb42bf" | ||
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a" | ||
PlotlyLight = "ca7969ec-10b3-423e-8d99-40f33abb42bf" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
|
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ makedocs(; | |
), | ||
pages=[ | ||
"Home" => "index.md", | ||
"DocumenterVitepress" => "vitepress.md", | ||
], | ||
) | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Usage with DocumenterVitepress | ||
|
||
PlotlyDocumenter provides an extension to work with DocumenterVitepress. As raw javascript code cannot be executed in Vue, an alternate approach is required. | ||
For this reason, when using DocumenterVitepress, the custom plot object will be rendered as the `<VuePlotly/>` component from the [vue3-plotly-ts](https://github.com/boscoh/vue3-plotly-ts) package. | ||
|
||
!!! warning | ||
The keyword arguments for `to_documenter` are ignored when using DocumenterVitepress. | ||
|
||
To make this work, first install the `vue3-plotly-ts` package in your project: | ||
|
||
```bash | ||
npm install vue3-plotly-ts | ||
``` | ||
|
||
Then, add the `VuePlotly` component to your `.vitepress/theme/index.ts` file: | ||
|
||
```typescript | ||
import VuePlotly from "vue3-plotly-ts" | ||
|
||
export default { | ||
... | ||
enhanceApp({ app, router, siteData }) { | ||
... | ||
app.component('VuePlotly', VuePlotly); | ||
... | ||
} | ||
} satisfies Theme | ||
``` | ||
In your `make.jl`, make sure you call `using PlotlyDocumenter` before `makedocs`. | ||
|
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module DocumenterVitepressPlotsExt | ||
|
||
using Documenter | ||
using DocumenterVitepress | ||
using HypertextLiteral | ||
using PlotlyDocumenter | ||
|
||
DocumenterVitepress.mime_priority(::MIME"text/vnd.plotlydocumenter.plot") = 2.5; | ||
DocumenterVitepress.render_mime(io::IO, mime::MIME"text/vnd.plotlydocumenter.plot", node, element, page, doc; kwargs...) = println(io, element) | ||
|
||
function Documenter.display_dict(x::PlotlyDocumenterPlot; context = nothing) | ||
base_dict = invoke(Documenter.display_dict, Tuple{Any}, x; context) | ||
rendered = @htl(""" | ||
<VuePlotly | ||
:data="$(x.data)" | ||
:layout="$(x.layout)" | ||
:config="$(x.config)" | ||
/> | ||
""") | ||
base_dict[MIME"text/vnd.plotlydocumenter.plot"()] = repr(MIME"text/html"(), rendered, context = context) | ||
return base_dict | ||
end | ||
|
||
end |
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