-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
688f932
commit 824fe12
Showing
7 changed files
with
72 additions
and
39 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 |
---|---|---|
@@ -1,15 +1,16 @@ | ||
name = "DocumenterDiagrams" | ||
uuid = "a106ebf2-4182-4cba-90d4-44cd3cc36e85" | ||
authors = ["Pedro Maciel Xavier <[email protected]>"] | ||
version = "0.27.0" | ||
version = "1.0.0" | ||
|
||
[deps] | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
Kroki = "b3565e16-c1f2-4fe9-b4ab-221c88942068" | ||
MarkdownAST = "d0879d2d-cac2-40c8-9cee-1863dc0c7391" | ||
TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" | ||
|
||
[compat] | ||
Documenter = "~0.27" | ||
Documenter = "1" | ||
Kroki = "0.2" | ||
TranscodingStreams = "=0.9.11" | ||
julia = "1.6" |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# DocumenterDiagrams.jl API | ||
|
||
```@docs | ||
DocumenterDiagrams.DiagramBlocks | ||
DocumenterDiagrams.DiagramBlock | ||
DocumenterDiagrams.DiagramExpander | ||
``` |
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,57 +1,77 @@ | ||
module DocumenterDiagrams | ||
|
||
import Kroki | ||
import Documenter.Utilities.DOM: DOM, Node | ||
import Documenter.Utilities.Markdown2: CodeBlock | ||
import Documenter.Utilities.MDFlatten: mdflatten | ||
import Documenter.Expanders: ExpanderPipeline, iscode | ||
import MarkdownAST: Node, CodeBlock | ||
import Documenter | ||
import Documenter.DOM | ||
import Documenter.MDFlatten: mdflatten | ||
import Documenter.Selectors: order, matcher, runner | ||
import Documenter.Writers.HTMLWriter: domify | ||
import Documenter.Writers.LaTeXWriter: Context, latex | ||
import Documenter.HTMLWriter: DCtx, domify | ||
|
||
# Data | ||
|
||
""" | ||
DiagramExpander | ||
Similar to the `RawBlocks` expander, but generates diagrams instead. | ||
""" | ||
abstract type DiagramBlocks <: ExpanderPipeline end | ||
abstract type DiagramExpander <: Documenter.Expanders.ExpanderPipeline end | ||
|
||
struct DiagramNode | ||
""" | ||
DiagramBlock | ||
""" | ||
struct DiagramBlock <: Documenter.AbstractDocumenterBlock | ||
codeblock::CodeBlock | ||
format::Symbol | ||
code::String | ||
end | ||
|
||
# Parsing | ||
order(::Type{DiagramExpander}) = 10.5 | ||
|
||
order(::Type{DiagramBlocks}) = 10.5 | ||
|
||
function matcher(::Type{DiagramBlocks}, node, page, doc) | ||
iscode(node, r"^@diagram") | ||
function matcher(::Type{DiagramExpander}, node, page, doc) | ||
return Documenter.iscode(node, r"^@diagram") | ||
end | ||
|
||
function runner(::Type{DiagramBlocks}, x, page, doc) | ||
m = match(r"@diagram[ ](.+)$", x.language) | ||
m === nothing && error("invalid '@diagram <format>' syntax: $(x.language)") | ||
function runner(::Type{DiagramExpander}, node, page, doc) | ||
block = node.element | ||
|
||
m = match(r"@diagram[ ](.+)$", block.info) | ||
|
||
if isnothing(m) | ||
error("invalid '@diagram <format>' syntax: $(block.info)") | ||
end | ||
|
||
page.mapping[x] = DiagramNode(Symbol(m[1]), x.code) | ||
format = Symbol(m[1]) | ||
|
||
node.element = DiagramBlock( | ||
block, # codeblock | ||
format, # format | ||
block.code, # code | ||
) | ||
|
||
return nothing | ||
end | ||
|
||
# Output | ||
function domify(::DCtx, node::Node, ::DiagramBlock) | ||
block = node.element | ||
|
||
raw_svg = String(Kroki.render(Kroki.Diagram(block.format, block.code), "svg")) | ||
|
||
function mdflatten(io, node::Node, e::DiagramNode) | ||
mdflatten(io, node, CodeBlock("@diagram $(e.format)", e.code)) | ||
return DOM.Tag(Symbol("#RAW#"))(raw_svg) | ||
end | ||
|
||
function domify(ctx, navnode, diag::DiagramNode) | ||
raw_svg = String(Kroki.render(Kroki.Diagram(diag.format, diag.code), "svg")) | ||
# function mdflatten(io, node::Node, e::DiagramBlock) | ||
# # mdflatten(io, node, CodeBlock("@diagram $(e.format)", e.code)) | ||
# return nothing | ||
# end | ||
|
||
DOM.Tag(Symbol("#RAW#"))(raw_svg) | ||
end | ||
abstract type DiagramBuilder <: Documenter.Builder.DocumentPipeline end | ||
|
||
order(::Type{DiagramBuilder}) = 8.1 | ||
|
||
function latex(io::Context, ::Node, diag::DiagramNode) | ||
# TODO: Not sure about this. | ||
# IDEA: write figure as png/pdf and _println \includegraphics since svg (default) is not very LaTeX-friendly | ||
nothing | ||
function runner(::Type{DiagramBuilder}, doc::Documenter.Document) | ||
return nothing | ||
end | ||
|
||
end # module DocumenterDiagrams |
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 |
---|---|---|
@@ -1,7 +1,16 @@ | ||
# DocumenterDiagrams.jl (TEST) | ||
|
||
## Diagram (TEST) | ||
|
||
```@diagram ditaa | ||
+------------------------+ +-------+ | ||
| DocumenterDiagrams.jl |--->| TEST | | ||
+------------------------+ +-------+ | ||
``` | ||
``` | ||
|
||
## API (TEST) | ||
|
||
```@docs | ||
DocumenterDiagrams.DiagramExpander | ||
DocumenterDiagrams.DiagramBlock | ||
``` |
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