mirror of https://github.com/mpastell/Weave.jl
fix lots of things I missed before
parent
770496b3af
commit
62d56846f4
|
@ -337,8 +337,7 @@ include("display_methods.jl")
|
|||
include("reader/reader.jl")
|
||||
include("run.jl")
|
||||
include("cache.jl")
|
||||
include("formats.jl")
|
||||
include("format.jl")
|
||||
include("rendering/format.jl")
|
||||
include("rendering/common.jl")
|
||||
include("rendering/htmlformats.jl")
|
||||
include("rendering/markdownformats.jl")
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
# TODO:
|
||||
# - 1. do assertions for definition mandatory fields in `@define_format` macro
|
||||
# - 2. implement fallback format/rendering functions in format.jl
|
||||
# - 3. export this as public API
|
||||
|
||||
|
||||
abstract type WeaveFormat end
|
||||
const FORMATS = Dict{String,WeaveFormat}()
|
||||
|
||||
# TODO: do some assertion for necessary fields of `format`
|
||||
register_format!(format_name::AbstractString, format::WeaveFormat) = push!(FORMATS, format_name => format)
|
||||
register_format!(_,format) = error("Format needs to be a subtype of WeaveFormat.")
|
|
@ -1,3 +1,16 @@
|
|||
# TODO:
|
||||
# - 1. do assertions for definition mandatory fields in `@define_format` macro
|
||||
# - 2. implement fallback format/rendering functions in format.jl
|
||||
# - 3. export this as public API
|
||||
|
||||
|
||||
const FORMATS = Dict{String,WeaveFormat}()
|
||||
|
||||
# TODO: do some assertion for necessary fields of `format`
|
||||
register_format!(format_name::AbstractString, format::WeaveFormat) = push!(FORMATS, format_name => format)
|
||||
register_format!(_,format) = error("Format needs to be a subtype of WeaveFormat.")
|
||||
|
||||
|
||||
# TODO: reorganize this file into multiple files corresponding to each output format
|
||||
|
||||
using Mustache, Highlights, .WeaveMarkdown, Markdown, Dates, Pkg
|
|
@ -2,7 +2,7 @@
|
|||
# ----
|
||||
abstract type HTMLFormat <: WeaveFormat end
|
||||
|
||||
mutable struct JMarkdown2HTML <: HTMLFormat
|
||||
Base.@kwdef mutable struct JMarkdown2HTML <: HTMLFormat
|
||||
description = "Julia markdown to html"
|
||||
codestart = "\n"
|
||||
codeend = "\n"
|
||||
|
@ -23,7 +23,7 @@ mutable struct JMarkdown2HTML <: HTMLFormat
|
|||
end
|
||||
register_format!("md2html", JMarkdown2HTML())
|
||||
|
||||
mutable struct Pandoc2HTML <: HTMLFormat
|
||||
Base.@kwdef mutable struct Pandoc2HTML <: HTMLFormat
|
||||
description = "Markdown to HTML (requires Pandoc 2)"
|
||||
codestart = "\n"
|
||||
codeend = "\n"
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
abstract type MarkdownFormat end
|
||||
abstract type MarkdownFormat <: WeaveFormat end
|
||||
# markdown
|
||||
# --------
|
||||
|
||||
@define_format GitHubMarkdown <: MarkdownFormat
|
||||
description = "GitHub markdown",
|
||||
codestart = "````julia",
|
||||
codeend = "````\n\n",
|
||||
outputstart = "````",
|
||||
outputend = "````\n\n",
|
||||
fig_ext = ".png",
|
||||
extension = "md",
|
||||
mimetypes =
|
||||
["image/png", "image/svg+xml", "image/jpg", "text/markdown", "text/plain"]
|
||||
Base.@kwdef mutable struct GitHubMarkdown <: MarkdownFormat
|
||||
description = "GitHub markdown"
|
||||
codestart = "````julia"
|
||||
codeend = "````\n\n"
|
||||
outputstart = "````"
|
||||
outputend = "````\n\n"
|
||||
fig_ext = ".png"
|
||||
extension = "md"
|
||||
mimetypes = ["image/png", "image/svg+xml", "image/jpg",
|
||||
"text/markdown", "text/plain"]
|
||||
keep_unicode = false
|
||||
termstart = codestart
|
||||
termend = codeend
|
||||
|
@ -23,7 +23,7 @@ abstract type MarkdownFormat end
|
|||
end
|
||||
register_format!("github", GitHubMarkdown())
|
||||
|
||||
mutable struct Hugo <: MarkdownFormat
|
||||
Base.@kwdef mutable struct Hugo <: MarkdownFormat
|
||||
description = "Hugo markdown (using shortcodes)"
|
||||
codestart = "````julia"
|
||||
codeend = "````\n\n"
|
||||
|
@ -43,7 +43,7 @@ mutable struct Hugo <: MarkdownFormat
|
|||
end
|
||||
register_format!("hugo", Hugo())
|
||||
|
||||
mutable struct MultiMarkdown <: MarkdownFormat
|
||||
Base.@kwdef mutable struct MultiMarkdown <: MarkdownFormat
|
||||
description = "MultiMarkdown"
|
||||
codestart = "````julia"
|
||||
codeend = "````\n\n"
|
||||
|
@ -66,14 +66,13 @@ register_format!("multimarkdown", MultiMarkdown())
|
|||
# pandoc
|
||||
# ------
|
||||
|
||||
mutable struct Pandoc <: MarkdownFormat
|
||||
Base.@kwdef mutable struct Pandoc <: MarkdownFormat
|
||||
description = "Pandoc markdown"
|
||||
codestart = "~~~~{.julia}"
|
||||
codeend = "~~~~~~~~~~~~~\n\n"
|
||||
outputstart = "~~~~"
|
||||
outputend = "~~~~\n\n"
|
||||
fig_ext = ".png"
|
||||
out_width = nothing
|
||||
extension = "md"
|
||||
# Prefer png figures for markdown conversion, svg doesn't work with latex
|
||||
mimetypes = ["image/png", "image/jpg", "image/svg+xml",
|
||||
|
|
|
@ -11,13 +11,12 @@ Base.@kwdef mutable struct JMarkdown2tex <: TexFormat
|
|||
outputend = "\\end{lstlisting}\n"
|
||||
fig_ext = ".pdf"
|
||||
extension = "tex"
|
||||
out_width = "\\linewidth",
|
||||
mimetypes = ["application/pdf", "image/png", "image/jpg",
|
||||
"text/latex", "text/markdown", "text/plain"]
|
||||
keep_unicode = false
|
||||
termstart = codestart
|
||||
termend = codeend
|
||||
out_width = nothing
|
||||
out_width = "\\linewidth"
|
||||
out_height = nothing
|
||||
fig_pos = nothing
|
||||
fig_env = nothing
|
||||
|
@ -25,7 +24,7 @@ Base.@kwdef mutable struct JMarkdown2tex <: TexFormat
|
|||
end
|
||||
register_format!("md2tex", JMarkdown2tex())
|
||||
|
||||
mutable struct Tex <: TexFormat
|
||||
Base.@kwdef mutable struct Tex <: TexFormat
|
||||
description = "Latex with custom code environments"
|
||||
codestart = "\\begin{juliacode}"
|
||||
codeend = "\\end{juliacode}"
|
||||
|
@ -35,22 +34,17 @@ mutable struct Tex <: TexFormat
|
|||
termend = "\\end{juliaterm}"
|
||||
fig_ext = ".pdf"
|
||||
extension = "tex"
|
||||
out_width = "\\linewidth"
|
||||
fig_env = "figure"
|
||||
fig_pos = "htpb"
|
||||
mimetypes = ["application/pdf", "image/png", "text/latex", "text/plain"]
|
||||
keep_unicode = false
|
||||
termstart = codestart
|
||||
termend = codeend
|
||||
out_width = nothing
|
||||
out_width = "\\linewidth"
|
||||
out_height = nothing
|
||||
fig_pos = nothing
|
||||
fig_env = nothing
|
||||
highlight_theme = nothing
|
||||
end
|
||||
register_format!("tex", Tex())
|
||||
|
||||
mutable struct TexMinted <: TexFormat
|
||||
Base.@kwdef mutable struct TexMinted <: TexFormat
|
||||
description = "Latex using minted for highlighting"
|
||||
codestart =
|
||||
"\\begin{minted}[mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}"
|
||||
|
@ -58,22 +52,17 @@ mutable struct TexMinted <: TexFormat
|
|||
outputstart =
|
||||
"\\begin{minted}[fontsize=\\small, xleftmargin=0.5em, mathescape, frame = leftline]{text}"
|
||||
outputend = "\\end{minted}"
|
||||
fig_ext = ".pdf"
|
||||
extension = "tex"
|
||||
mimetypes = ["application/pdf", "image/png", "text/latex", "text/plain"]
|
||||
keep_unicode = false
|
||||
termstart =
|
||||
"\\begin{minted}[fontsize=\\footnotesize, xleftmargin=0.5em, mathescape]{jlcon}"
|
||||
termend = "\\end{minted}"
|
||||
fig_ext = ".pdf"
|
||||
extension = "tex"
|
||||
out_width = "\\linewidth"
|
||||
out_height = nothing
|
||||
fig_env = "figure"
|
||||
fig_pos = "htpb"
|
||||
mimetypes = ["application/pdf", "image/png", "text/latex", "text/plain"]
|
||||
keep_unicode = false
|
||||
termstart = codestart
|
||||
termend = codeend
|
||||
out_width = nothing
|
||||
out_height = nothing
|
||||
fig_pos = nothing
|
||||
fig_env = nothing
|
||||
highlight_theme = nothing
|
||||
end
|
||||
register_format!("texminted", TexMinted())
|
||||
|
@ -150,7 +139,7 @@ end
|
|||
|
||||
# return "\\begin{minted}[mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}\n$result\n\\end{minted}\n"
|
||||
format_termchunk(chunk, docformat::TexFormat) =
|
||||
should_render(chunk) ? highlight_term(MIME("text/latex"), chunk.output, docformat.highlight_theme]) : ""
|
||||
should_render(chunk) ? highlight_term(MIME("text/latex"), chunk.output, docformat.highlight_theme) : ""
|
||||
|
||||
|
||||
function formatfigures(chunk, docformat::TexFormat)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Rest
|
||||
# ----
|
||||
|
||||
mutable struct Rest <: WeaveFormat
|
||||
Base.@kwdef mutable struct Rest <: WeaveFormat
|
||||
description = "reStructuredText and Sphinx"
|
||||
codestart = ".. code-block:: julia\n"
|
||||
codeend = "\n\n"
|
||||
|
@ -10,11 +10,10 @@ mutable struct Rest <: WeaveFormat
|
|||
indent = 4
|
||||
fig_ext = ".png"
|
||||
extension = "rst"
|
||||
out_width = "15 cm"
|
||||
keep_unicode = false
|
||||
termstart = codestart
|
||||
termend = codeend
|
||||
out_width = nothing
|
||||
out_width = "15 cm"
|
||||
out_height = nothing
|
||||
fig_pos = nothing
|
||||
fig_env = nothing
|
||||
|
@ -27,7 +26,7 @@ register_format!("rst", Rest())
|
|||
# -----
|
||||
|
||||
# asciidoc -b html5 -a source-highlighter=pygments ...
|
||||
mutable struct AsciiDoc <: WeaveFormat
|
||||
Base.@kwdef mutable struct AsciiDoc <: WeaveFormat
|
||||
description = "AsciiDoc"
|
||||
codestart = "[source,julia]\n--------------------------------------"
|
||||
codeend = "--------------------------------------\n\n"
|
||||
|
@ -35,11 +34,10 @@ mutable struct AsciiDoc <: WeaveFormat
|
|||
outputend = "--------------------------------------\n\n"
|
||||
fig_ext = ".png"
|
||||
extension = "txt"
|
||||
out_width = "600"
|
||||
keep_unicode = false
|
||||
termstart = codestart
|
||||
termend = codeend
|
||||
out_width = nothing
|
||||
out_width = "600"
|
||||
out_height = nothing
|
||||
fig_pos = nothing
|
||||
fig_env = nothing
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
abstract type WeaveChunk end
|
||||
abstract type Inline end
|
||||
abstract type WeaveFormat end
|
||||
|
||||
mutable struct WeaveDoc
|
||||
source::AbstractString
|
||||
|
|
Loading…
Reference in New Issue