Skip to content

Commit

Permalink
Fix support for non-math LaTeX
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Oct 13, 2020
1 parent 067a78e commit d3ec102
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Writers/HTMLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1716,11 +1716,6 @@ end

mdconvert(html::Documents.RawHTML, parent; kwargs...) = Tag(Symbol("#RAW#"))(html.code)

function _strip_out(regex::Regex, string)
m = match(regex, string)
return m === nothing ? string : m[1]
end

# Select the "best" representation for HTML output.
mdconvert(mo::Documents.MultiOutput, parent; kwargs...) =
Base.invokelatest(mdconvert, mo.content, parent; kwargs...)
Expand All @@ -1738,12 +1733,18 @@ function mdconvert(d::Dict{MIME,Any}, parent; kwargs...)
elseif haskey(d, MIME"image/jpeg"())
out = Documents.RawHTML(string("<img src=\"data:image/jpeg;base64,", d[MIME"image/jpeg"()], "\" />"))
elseif haskey(d, MIME"text/latex"())
# If the show(io, ::MIME"text/latex", x) output is already wrapped in \[ ... \], we
# If the show(io, ::MIME"text/latex", x) output is already wrapped in \[ ... \] or $$ ... $$, we
# unwrap it first, since when we output Markdown.LaTeX objects we put the correct
# delimiters around it anyway.
out2 = _strip_out(r"\s*\\\[(.*)\\\]\s*", d[MIME"text/latex"()])
out1 = _strip_out(r"\s*\$\$(.*)\$\$\s*", out2)
out = Markdown.LaTeX(out1)
latex = d[MIME"text/latex"()]
equation = false
m_bracket = match(r"\s*\\\[(.*)\\\]\s*", latex)
m_dollars = match(r"\s*\\\[(.*)\\\]\s*", latex)
if m_bracket === nothing && m_dollars === nothing
out = Utilities.mdparse(latex; mode = :single)
else
out = Markdown.LaTeX(m_bracket !== nothing ? m_bracket[1] : m_dollars[1])
end
elseif haskey(d, MIME"text/markdown"())
out = Markdown.parse(d[MIME"text/markdown"()])
elseif haskey(d, MIME"text/plain"())
Expand Down

0 comments on commit d3ec102

Please sign in to comment.