Skip to content

Commit

Permalink
Merge pull request #350 from JonasIsensee/texexports
Browse files Browse the repository at this point in the history
Reworking format.jl
  • Loading branch information
aviatesk authored Jun 2, 2020
2 parents 9ccf3a2 + 533667b commit 73bf7fe
Show file tree
Hide file tree
Showing 17 changed files with 915 additions and 854 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: julia

julia:
- 1 # current stable
- 1.0 # lts
- nightly

script:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Mustache = "0.4.1, 0.5, 1"
Plots = "0.28, 0.29, 1.0"
Requires = "1.0"
YAML = "0.3, 0.4"
julia = "1"
julia = "1.2"

[extras]
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Expand Down
38 changes: 22 additions & 16 deletions src/Weave.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Weave

using Highlights, Mustache, Requires
using Highlights, Mustache, Requires, Pkg


# directories
Expand All @@ -16,24 +16,27 @@ const WEAVE_OPTION_NAME_DEPRECATED = "options" # remove this when tagging v0.11
const WEAVE_OPTION_DEPRECATE_ID = "weave_option_duplicate_id"
const DEFAULT_FIG_PATH = "figures"

const WEAVE_VERSION = try
'v' * Pkg.TOML.parsefile(normpath(PKG_DIR, "Project.toml"))["version"]
catch
""
end
weave_info() = WEAVE_VERSION, string(Date(now()))

function __init__()
@require Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" include("plots.jl")
@require Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004" include("gadfly.jl")
end

# utilitity functions
@static @isdefined(isnothing) || begin
isnothing(::Any) = false
isnothing(::Nothing) = true
end
take2string!(io) = String(take!(io))

"""
list_out_formats(io = stdout)
List supported output formats
"""
list_out_formats(io = stdout) = for (k, v) in FORMATS; println(io, string(k, ": ", v.formatdict[:description])); end
list_out_formats(io = stdout) = for (k, v) in FORMATS; println(io, string(k, ": ", v.description)); end

"""
tangle(source::AbstractString; kwargs...)
Expand Down Expand Up @@ -171,36 +174,40 @@ function weave(
throw_errors = throw_errors,
)

# format document
# render document
# ---------------

# overwrites options with those specified in header, that are needed for formatting document
# overwrites options with those specified in header, that are needed for rendering document
# NOTE: these YAML options can be given dynamically
if !isnothing(weave_options)
if haskey(weave_options, "template")
template = weave_options["template"]
# resolve relative to this document
# resolve relative to this document
template isa AbstractString && (template = normpath(dirname(source), template))
end
if haskey(weave_options, "css")
css = weave_options["css"]
# resolve relative to this document
# resolve relative to this document
css isa AbstractString && (css = normpath(dirname(source), css))
end
highlight_theme = get(weave_options, "highlight_theme", highlight_theme)
pandoc_options = get(weave_options, "pandoc_options", pandoc_options)
latex_cmd = get(weave_options, "latex_cmd", latex_cmd)
keep_unicode = get(weave_options, "keep_unicode", keep_unicode)
end

get!(doc.format.formatdict, :keep_unicode, keep_unicode)
rendered = format(doc, template, highlight_theme; css = css)
set_rendering_options!(doc; template = template, highlight_theme = highlight_theme, css = css, keep_unicode = keep_unicode)
rendered = render_doc(doc)

outname = get_outname(out_path, doc)

open(io->write(io,rendered), outname, "w")

# document generation via external programs
# -----------------------------------------

if !isnothing(weave_options)
pandoc_options = get(weave_options, "pandoc_options", pandoc_options)
end

doctype = doc.doctype
if doctype == "pandoc2html"
mdname = outname
Expand Down Expand Up @@ -333,8 +340,7 @@ include("display_methods.jl")
include("reader/reader.jl")
include("run.jl")
include("cache.jl")
include("formats.jl")
include("format.jl")
include("rendering/rendering.jl")
include("pandoc.jl")
include("converter.jl")

Expand Down
6 changes: 3 additions & 3 deletions src/display_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Markdown, .WeaveMarkdown
mutable struct Report <: AbstractDisplay
cwd::AbstractString
basename::AbstractString
formatdict::Dict{Symbol,Any}
format::WeaveFormat
pending_code::AbstractString
cur_result::AbstractString
rich_output::AbstractString
Expand All @@ -18,11 +18,11 @@ mutable struct Report <: AbstractDisplay
throw_errors::Bool
end

function Report(cwd, basename, formatdict, mimetypes, throw_errors)
function Report(cwd, basename, format, mimetypes, throw_errors)
Report(
cwd,
basename,
formatdict,
format,
"",
"",
"",
Expand Down
Loading

0 comments on commit 73bf7fe

Please sign in to comment.