Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer committed Jun 4, 2024
1 parent 091c170 commit bf4252f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/src/notebooks/example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```
Expand Down
2 changes: 1 addition & 1 deletion src/html.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
20 changes: 12 additions & 8 deletions src/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions test/html.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<span class="tex">` by Pluto.
@test contains(html, raw"But this is math <span class=\"tex\">$x$</span>.")
@test contains(html, raw"The prices are \$4 and \$5")
@test contains(html, raw"The prices are \$10 and \$20")
end

0 comments on commit bf4252f

Please sign in to comment.