From bf4252f2ac5b5ad080f33bb18bf5fe3fc3c02161 Mon Sep 17 00:00:00 2001 From: Rik Huijzer Date: Tue, 4 Jun 2024 10:51:24 +0200 Subject: [PATCH] Add test --- docs/src/notebooks/example.jl | 2 +- src/html.jl | 2 +- src/output.jl | 20 ++++++++++++-------- test/html.jl | 22 ++++++++++++++++++++++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/docs/src/notebooks/example.jl b/docs/src/notebooks/example.jl index ab8ddf3..1487b73 100644 --- a/docs/src/notebooks/example.jl +++ b/docs/src/notebooks/example.jl @@ -35,7 +35,7 @@ For example, $x = 3\pi$ and y = \frac{a \cdot b}{c^2} ``` -For using the dollar symbol normally, escape it with a leading backslash just like in Pluto: +For using the dollar symbol normally, escape it with a backslash just like in Pluto: ```markdown The prices were \$5 and \$10. ``` diff --git a/src/html.jl b/src/html.jl index 72fc4c9..37533da 100644 --- a/src/html.jl +++ b/src/html.jl @@ -138,7 +138,7 @@ end function _patch_dollar_symbols(body::String)::String lines = split(body, '\n') - # Pluto wraps inline HTML in a tex class, so if we see a dollar symbol in a plain text output, + # Pluto wraps inline LaTeX in a tex class, so if we see a dollar symbol in a plain text output, # we should escape it since it is not a LaTeX expression. for i in 1:length(lines) line = lines[i] diff --git a/src/output.jl b/src/output.jl index 2fbd66c..0f04cd5 100644 --- a/src/output.jl +++ b/src/output.jl @@ -177,15 +177,19 @@ function _throw_if_error(session::ServerSession, nb::Notebook) filename = _indent(nb.path) code = _indent(cell.code) body = cell.output.body::Dict{Symbol,Any} - msg = body[:msg]::String - error_text::String = if body[:stacktrace] isa CapturedException - val = body[:stacktrace]::CapturedException - io = IOBuffer() - ioc = IOContext(io, :color => Base.get_have_color()) - showerror(ioc, val) - _indent(String(take!(io))) + error_text::String = if haskey(body, :stacktrace) + if body[:stacktrace] isa CapturedException + val = body[:stacktrace]::CapturedException + io = IOBuffer() + ioc = IOContext(io, :color => Base.get_have_color()) + showerror(ioc, val) + _indent(String(take!(io))) + else + _indent(string(body[:stacktrace])::String) + end else - _indent(string(body[:stacktrace])::String) + # Fallback. + string(body)::String end msg = """ Execution of notebook failed. diff --git a/test/html.jl b/test/html.jl index d066a98..5e20f02 100644 --- a/test/html.jl +++ b/test/html.jl @@ -243,3 +243,25 @@ end ]) html, _ = notebook2html_helper(nb; use_distributed=false) end + +@testset "patch_dollar_symbols" begin + nb = Notebook([ + Cell(raw""" + md\"\"\" + # Foo + + ```markdown + The prices are \$4 and \$5. + ``` + The prices are \$10 and \$20. + + But this is math $x$. + \"\"\" + """) + ]) + html, _ = notebook2html_helper(nb; use_distributed=false) + # Verify that inline math is converted to `` by Pluto. + @test contains(html, raw"But this is math $x$.") + @test contains(html, raw"The prices are \$4 and \$5") + @test contains(html, raw"The prices are \$10 and \$20") +end