mirror of https://github.com/mpastell/Weave.jl
Compare commits
34 Commits
Author | SHA1 | Date |
---|---|---|
Sebastian Pfitzner | 77793c775c | |
Sheehan Olver | ad0885ce00 | |
Sebastian Pfitzner | e10aaefd94 | |
Sebastian Pfitzner | 8ad4e876d3 | |
Sebastian Pfitzner | af2a6e14c9 | |
Sebastian Pfitzner | 20aaefec0a | |
Gerhard Aigner | 2a78676d41 | |
Gerhard Aigner | 59332c1768 | |
Sebastian Pfitzner | db28a69d94 | |
Sheehan Olver | 0b96591f39 | |
Sebastian Pfitzner | a38cec95db | |
Sebastian Pfitzner | 562f8e4ab3 | |
Sebastian Pfitzner | 9f666b3bb5 | |
KristofferC | a63577f69c | |
Xing Shi Cai | 7e0f5641c2 | |
Nicholas W. M. Ritchie | b022a54458 | |
Nicholas W. M. Ritchie | b669a14038 | |
Sebastian Pfitzner | b7941c2811 | |
ExpandingMan | d40e95a4bb | |
xgdgsc | df47ea191f | |
Sebastian Pfitzner | 381de22c7d | |
github-actions[bot] | 06b259a7b0 | |
Sebastian Pfitzner | 749c0c262c | |
Sebastian Pfitzner | 696db1d82b | |
Mike | d4c65729e4 | |
Mike | 1dfb8d76d6 | |
Sebastian Pfitzner | 48c99c791f | |
Sebastian Pfitzner | ec3f464c37 | |
Mike | 4c60bd8d64 | |
Sebastian Pfitzner | e1d31c2ef6 | |
Shuhei Kadowaki | 99916dd70c | |
Sebastian Pfitzner | 6b6f82bed4 | |
Shuhei Kadowaki | b1de7efede | |
Nathan Hattersley | 849cc20e88 |
|
@ -1,6 +1,6 @@
|
|||
name = "Weave"
|
||||
uuid = "44d3d7a6-8a23-5bf8-98c5-b353f8df5ec9"
|
||||
version = "0.10.7"
|
||||
version = "0.10.12"
|
||||
|
||||
[deps]
|
||||
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
|
||||
|
@ -12,15 +12,17 @@ Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
|
|||
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
|
||||
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
|
||||
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
|
||||
RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00"
|
||||
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
|
||||
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
|
||||
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
|
||||
|
||||
[compat]
|
||||
Highlights = "0.3.1, 0.4"
|
||||
Highlights = "0.3.1, 0.4, 0.5"
|
||||
JSON = "0.21"
|
||||
Mustache = "0.4.1, 0.5, 1"
|
||||
Plots = "0.28, 0.29, 1.0"
|
||||
RelocatableFolders = "0.1,0.2,0.3,1"
|
||||
Requires = "1.0"
|
||||
YAML = "0.3, 0.4"
|
||||
julia = "1.2"
|
||||
|
|
|
@ -97,3 +97,8 @@ Thanks for the important additions, fixes and comments.
|
|||
|
||||
- [DiffEqTutorials.jl](https://github.com/JuliaDiffEq/DiffEqTutorials.jl) uses Weave to output tutorials (`.jmd` documents) to html, pdf and Jupyter notebooks.
|
||||
- [TuringTutorials](https://github.com/TuringLang/TuringTutorials) uses Weave to convert notebooks to html.
|
||||
|
||||
## Related packages
|
||||
|
||||
- [Literate.jl](https://github.com/fredrikekre/Literate.jl) can be used to generate Markdown and Jupyter notebooks directly from Julia source files with markdown in comments.
|
||||
- [Quarto](https://quarto.org) can generate Jupyter notebooks, HTML, or PDF directly from a Markdown format containing Julia code blocks, and also works with R and Python.
|
||||
|
|
|
@ -130,7 +130,7 @@ e.g. to include a Plots figure in markdown you can use:
|
|||
```
|
||||
or to produce any HTML output:
|
||||
```
|
||||
! display("text/html", "Header from julia");
|
||||
! display("text/html", HTML("Header from julia"));
|
||||
```
|
||||
|
||||
### Script Format
|
||||
|
|
13
src/Weave.jl
13
src/Weave.jl
|
@ -1,14 +1,13 @@
|
|||
module Weave
|
||||
|
||||
using Highlights, Mustache, Requires, Pkg, REPL
|
||||
|
||||
using Highlights, Mustache, Requires, Pkg, REPL, RelocatableFolders, Base64
|
||||
|
||||
# directories
|
||||
const PKG_DIR = normpath(@__DIR__, "..")
|
||||
const TEMPLATE_DIR = normpath(PKG_DIR, "templates")
|
||||
const STYLESHEET_DIR = normpath(PKG_DIR, "stylesheets")
|
||||
const TEMPLATE_DIR = @path joinpath(PKG_DIR, "templates")
|
||||
const STYLESHEET_DIR = @path joinpath(PKG_DIR, "stylesheets")
|
||||
# keeps paths of sample documents for easy try
|
||||
const EXAMPLE_FOLDER = normpath(PKG_DIR, "examples")
|
||||
const EXAMPLE_FOLDER = @path joinpath(PKG_DIR, "examples")
|
||||
|
||||
# constant names
|
||||
const WEAVE_OPTION_NAME = "weave_options"
|
||||
|
@ -244,12 +243,12 @@ function specific_options!(weave_options, doctype)
|
|||
end
|
||||
|
||||
get_out_path(doc, out_path, ext::Nothing = nothing) = get_out_path(doc, out_path, doc.format.extension)
|
||||
function get_out_path(doc, out_path, ext)
|
||||
function get_out_path(doc, out_path, ext)
|
||||
if (out_path === :doc) || (out_path === :pwd)
|
||||
abspath(get_cwd(doc, out_path), string(doc.basename, '.', ext))
|
||||
elseif isempty(splitext(out_path)[2]) # directory given
|
||||
abspath(get_cwd(doc, out_path), string(doc.basename, '.', ext))
|
||||
else
|
||||
else
|
||||
# out_path is given, but if extension is explitly provided override this will override the extension
|
||||
abspath(string(splitext(out_path)[1], '.', ext))
|
||||
end
|
||||
|
|
|
@ -5,9 +5,11 @@ using ..Weave: isnothing, take2string!
|
|||
using Markdown
|
||||
import Markdown: @trigger, @breaking, Code, MD, withstream, startswith, LaTeX
|
||||
|
||||
# Note that this definition causes a "Method overwritten" warning,
|
||||
# but defining this function in __init__() is not legal in julia v1.5
|
||||
function Markdown.latex(io::IO, tex::Markdown.LaTeX)
|
||||
# HACK: that this definition is type-piracy. It is required since `Markdown`
|
||||
# does not have a built in system for contextual rendering by users. `io` here
|
||||
# should always be either `IOBuffer` or `IOContext` since it is reached via
|
||||
# `sprint` in all user-facing code paths in `Markdown`.
|
||||
function Markdown.latex(io::Union{IOBuffer,IOContext}, tex::Markdown.LaTeX)
|
||||
math_envs = ["align", "equation", "eqnarray"]
|
||||
use_dollars =
|
||||
!any([occursin("\\begin{$me", tex.formula) for me in math_envs])
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module WeavePlots
|
||||
|
||||
using Base64, ..Plots, ..Weave
|
||||
using ..Base64, ..Plots, ..Weave
|
||||
|
||||
|
||||
# Pre-execute hooks to set the plot size for the chunk
|
||||
|
|
|
@ -5,7 +5,7 @@ function parse_markdown(document_body; is_pandoc = false)
|
|||
r"^<<(?<options>.*?)>>=\s*$",
|
||||
r"^@\s*$"
|
||||
else
|
||||
r"^[`~]{3}(\{?)julia\s*([;,]?)\s*(?<options>.*?)(\}|\s*)$",
|
||||
r"^[`~]{3}(\{?)julia\s*([;,\{]?)\s*(?<options>.*?)(\}|\s*)$",
|
||||
r"^[`~]{3}\s*$"
|
||||
end
|
||||
return header, parse_markdown_body(document_body, code_start, code_end, offset)
|
||||
|
|
|
@ -152,11 +152,11 @@ end
|
|||
Base.@kwdef mutable struct LaTeXMinted <: LaTeXFormat
|
||||
description = "LaTeX using minted package for code highlighting"
|
||||
extension = "tex"
|
||||
codestart = "\\begin{minted}[escapeinside=||, mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}"
|
||||
codestart = "\\begin{minted}[texcomments = true, mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}"
|
||||
codeend = "\\end{minted}"
|
||||
termstart = "\\begin{minted}[escapeinside=||, mathescape, fontsize=\\footnotesize, xleftmargin=0.5em]{jlcon}"
|
||||
termstart = "\\begin{minted}[texcomments = true, mathescape, fontsize=\\footnotesize, xleftmargin=0.5em]{jlcon}"
|
||||
termend = "\\end{minted}"
|
||||
outputstart = "\\begin{minted}[escapeinside=||, mathescape, fontsize=\\small, xleftmargin=0.5em, frame = leftline]{text}"
|
||||
outputstart = "\\begin{minted}[texcomments = true, mathescape, fontsize=\\small, xleftmargin=0.5em, frame = leftline]{text}"
|
||||
outputend = "\\end{minted}"
|
||||
mimetypes = ["application/pdf", "image/png", "text/latex", "text/plain"]
|
||||
fig_ext = ".pdf"
|
||||
|
|
|
@ -90,6 +90,8 @@ function run_doc(
|
|||
@info "Weaved all chunks" progress=1 _id=PROGRESS_ID
|
||||
cd_back()
|
||||
popdisplay(report) # ensure display pops out even if internal error occurs
|
||||
# Temporary fig_path is not automatically removed because it contains files so...
|
||||
!isnothing(fig_path) && startswith(fig_path, "jl_") && rm(normpath(cwd, fig_path), force=true, recursive=true)
|
||||
end
|
||||
|
||||
return doc
|
||||
|
|
|
@ -61,7 +61,7 @@ function write_doc(docformat::Pandoc2PDF, doc, rendered, out_path)
|
|||
cmd = `pandoc -f markdown+raw_tex -s --pdf-engine=xelatex --highlight-style=tango
|
||||
$filt $citeproc $(docformat.pandoc_options)
|
||||
--include-in-header=$(docformat.header_template)
|
||||
-V fontsize=12pt -o $(out)`
|
||||
-o $(out)`
|
||||
proc = open(cmd, "r+")
|
||||
println(proc.in, rendered)
|
||||
close(proc.in)
|
||||
|
|
|
@ -72,6 +72,10 @@ let opts = get_options("```julia, opt1 = 1, opt2 = \"2\"\n```")
|
|||
@test (:opt1 => 1) in opts
|
||||
@test (:opt2 => "2") in opts
|
||||
end
|
||||
let opts = get_options("```julia{opt1 = 1, opt2 = \"2\"}\n```")
|
||||
@test (:opt1 => 1) in opts
|
||||
@test (:opt2 => "2") in opts
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -6,18 +6,18 @@
|
|||
doc = mock_run("""
|
||||
```julia
|
||||
using DataFrames
|
||||
DataFrame(rand(10,3))
|
||||
DataFrame(a=rand(10))
|
||||
```
|
||||
"""; doctype = "md2html")
|
||||
@test isdefined(doc.chunks[1], :rich_output)
|
||||
@test count("<tr>", doc.chunks[1].rich_output) == 12 # additonal 2 for name and type row
|
||||
@test count("<tr", doc.chunks[1].rich_output) == 12 # additonal 2 for name and type row
|
||||
|
||||
# limit
|
||||
n = 100000
|
||||
doc = mock_run("""
|
||||
```julia
|
||||
using DataFrames
|
||||
DataFrame(rand($n,3))
|
||||
DataFrame(a=rand($n))
|
||||
```
|
||||
"""; doctype = "md2html")
|
||||
@test isdefined(doc.chunks[1], :rich_output)
|
||||
|
|
Loading…
Reference in New Issue