Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworking format.jl #350

Merged
merged 25 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e200428
introduce common supertype for JMarkdown2tex and Tex
JonasIsensee May 24, 2020
2fdd09b
introduce WeaveFormat abstract type
aviatesk May 25, 2020
f4ed10b
define render_doc and dispatch on it with different formats
aviatesk May 25, 2020
e7637de
Merge branch 'master' into texexports
aviatesk May 30, 2020
db89118
fix typing and improve `@define_format`
aviatesk May 30, 2020
119b333
move around code into separate files
JonasIsensee May 30, 2020
6e99822
removing duplicate code
JonasIsensee May 30, 2020
770496b
remove format dict - make everything a field of format <: WeaveFormat…
JonasIsensee May 31, 2020
62d5684
fix lots of things I missed before
JonasIsensee May 31, 2020
3eba5de
make `texminted` output valid texfile
JonasIsensee May 31, 2020
45adb89
some cleanup
JonasIsensee May 31, 2020
9875bc1
pass fewer arguments and bugfixes
JonasIsensee May 31, 2020
b5477d2
revert improvements to tex rendering
JonasIsensee May 31, 2020
543f99a
rename files and include location + move texify
JonasIsensee May 31, 2020
ae0dc70
refactoring:
aviatesk Jun 1, 2020
55d2c97
set rendering options with dispatch:
aviatesk Jun 1, 2020
0bdab33
Merge branch 'master' into texexports
aviatesk Jun 1, 2020
19b4a79
reorder WeaveFormat field defs
aviatesk Jun 2, 2020
ae48729
use type field to restore header check
aviatesk Jun 2, 2020
c6b23d4
drop LTS support:
aviatesk Jun 2, 2020
4b12f3d
reorder functions again
aviatesk Jun 2, 2020
04b24ea
a bit more reorder
aviatesk Jun 2, 2020
0760591
bump up to julia 1.2
aviatesk Jun 2, 2020
aa7fd31
use isnothing & isempty
aviatesk Jun 2, 2020
533667b
type annotate API
aviatesk Jun 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 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,6 +16,13 @@ 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")
Expand All @@ -33,7 +40,7 @@ take2string!(io) = String(take!(io))

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,20 +178,20 @@ 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)
Expand All @@ -193,8 +200,8 @@ function weave(
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)

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