pull/338/merge
Shuhei Kadowaki 2021-05-09 19:56:32 +04:30 committed by GitHub
commit 0ec7e90f7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 6 deletions

8
.gitignore vendored
View File

@ -1,11 +1,15 @@
Manifest.toml
/doc/build/
/stylesheets/bootswatch/
examples/figures/
examples/*.md
examples/*.pdf
examples/*.html
examples/*.rst
examples/*.tex
test/**/cache
test/**/figures
test/documents/output/gadfly_formats_test.txt
@ -19,10 +23,6 @@ test/**/chunk_options.jl
test/**/*.ipynb
!test/**/*ref.*
doc/build
doc/site
.idea
*.*~
*.aux
*.log

View File

@ -6,6 +6,7 @@ version = "0.10.8"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Highlights = "eafb193a-b7ab-5a9e-9068-77385905fa72"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"

24
deps/build.jl vendored Normal file
View File

@ -0,0 +1,24 @@
# # to update `themes`
# let
# using HTTP, JSON
# r = HTTP.request("GET", "https://bootswatch.com/api/4.json") |> HTTP.payload |> String |> JSON.parse
# lowercase.(get.(values(r["themes"]), "name", "")) |> repr |> clipboard
# end
bootswatch_version = "4"
themes = ["cerulean", "cosmo", "cyborg", "darkly", "flatly", "journal", "litera", "lumen", "lux", "materia", "minty", "pulse", "sandstone", "simplex", "sketchy", "slate", "solar", "spacelab", "superhero", "united", "yeti"]
targets = ["bootstrap.min.css", "_bootswatch.scss", "_variables.scss"]
BOOTSWATCH_DIR = normpath(@__DIR__, "..", "stylesheets", "bootswatch")
isdir(BOOTSWATCH_DIR) || mkdir(BOOTSWATCH_DIR)
function download_theme(theme)
theme_dir = normpath(BOOTSWATCH_DIR, theme)
isdir(theme_dir) || mkdir(theme_dir)
for target in targets
file = normpath(theme_dir, target)
isfile(file) || download("https://bootswatch.com/$(bootswatch_version)/$(theme)/$(target)", file)
end
end
download_theme.(themes)

View File

@ -1,6 +1,7 @@
module Weave
using Highlights, Mustache, Requires, Pkg, REPL
using InteractiveUtils: subtypes
# directories
@ -54,6 +55,16 @@ List supported output formats with its description.
"""
list_out_formats() = [k => v.description for (k,v) in FORMATS]
"""
list_highlight_themes()
List all the available syntax highlight themes, which can be passed to [`weave`](@ref)'s
`highlight_theme` keyword argument.
See also: [`weave`](@ref), [Highlights.jl's showcase page](https://juliadocs.github.io/Highlights.jl/latest/demo/themes/)
"""
list_highlight_themes() = subtypes(Highlights.AbstractTheme)
"""
tangle(source::AbstractString; kwargs...)
@ -114,7 +125,10 @@ Weave an input document to output file.
* `:refresh` runs all code chunks and save new cache
- `template::Union{Nothing,AbstractString,Mustache.MustacheTokens} = nothing`: Template (file path) or `Mustache.MustacheTokens`s for `md2html` or `md2tex` formats
- `css::Union{Nothing,AbstractString} = nothing`: Path of a CSS file used for md2html format
- `highlight_theme::Union{Nothing,Type{<:Highlights.AbstractTheme}} = nothing`: Theme used for syntax highlighting (defaults to `Highlights.Themes.DefaultTheme`)
- `highlight_theme::Union{Nothing,AbstractString,Symbol,Type{<:Highlights.AbstractTheme}} = nothing`: Theme used for syntax highlighting.
* If given `nothing` (default), Weave will use `Highlights.Themes.DefaultTheme`
* If given an instance of `AbstractString` or `Symbol`, Weave will try to search a theme based on string matching, e.g. `highlight_theme = "github"` will use `Highlights.Themes.GitHubTheme`
* If given an instance of `Highlights.AbstractTheme`, it will be directly used
- `pandoc_options::Vector{<:AbstractString} = $(DEFAULT_PANDOC_OPTIONS)`: `String`s of options to pass to pandoc for `pandoc2html` and `pandoc2pdf` formats, e.g. `["--toc", "-N"]`
- `latex_cmd::Vector{<:AbstractString} = $(DEFAULT_LATEX_CMD)`: The command used to make PDF file from .tex
- `keep_unicode::Bool = false`: If `true`, do not convert unicode characters to their respective latex representation. This is especially useful if a font and tex-engine with support for unicode characters are used
@ -135,7 +149,7 @@ function weave(
cache::Symbol = :off,
template::Union{Nothing,AbstractString,Mustache.MustacheTokens} = nothing,
css::Union{Nothing,AbstractString} = nothing, # TODO: rename to `stylesheet`
highlight_theme::Union{Nothing,Type{<:Highlights.AbstractTheme}} = nothing,
highlight_theme::Union{Nothing,AbstractString,Symbol,Type{<:Highlights.AbstractTheme}} = nothing,
pandoc_options::Vector{<:AbstractString} = DEFAULT_PANDOC_OPTIONS,
latex_cmd::Vector{<:AbstractString} = DEFAULT_LATEX_CMD,
keep_unicode::Bool = false,
@ -334,6 +348,7 @@ include_weave(source, informat = nothing) = include_weave(Main, source, informat
export weave,
list_out_formats,
list_highlight_themes,
tangle,
convert_doc,
notebook,

View File

@ -153,6 +153,15 @@ get_highlight_stylesheet(mime, highlight_theme::Type{<:Highlights.AbstractTheme}
get_highlight_theme(::Nothing) = Highlights.Themes.DefaultTheme
get_highlight_theme(highlight_theme::Type{<:Highlights.AbstractTheme}) = highlight_theme
function get_highlight_theme(s)
themes = list_highlight_themes()
s = string(s)
i = findfirst(themes) do theme
occursin(Regex(s, "i"), string(theme))
end
isnothing(i) && error("no highlight theme found for $s")
return themes[i]
end
highlight_code(mime, code, highlight_theme) =
highlight(mime, strip(code), Highlights.Lexers.JuliaLexer, highlight_theme)