Skip to content

Commit

Permalink
Wip3 (#240)
Browse files Browse the repository at this point in the history
* Fix crash if non-ASCII character precedes $ math (#239)

* Fix crash if non-ASCII character precedes $ math

* Fix similar crash in prerendering step

* adding a nextind and restricting to 1.1

* fixing travis
  • Loading branch information
tlienart authored Sep 29, 2019
1 parent 7a4e9ec commit 2cc0443
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 39 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: julia
os:
- linux
julia:
- 1.0
- 1.1
- 1.2
- 1.3
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
DocStringExtensions = ">= 0.7.0"
JuDocTemplates = ">= 0.1.0"
LiveServer = ">= 0.3.0"
julia = "^1.0.0"
julia = "^1.1.0"

[extras]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ See [the docs](https://tlienart.github.io/JuDoc.jl/stable) for more information

### Quick demo

With Julia ≥ 1.0:
With Julia ≥ 1.1:

```julia
pkg> add JuDoc
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ On this page:

## Installation

With Julia ≥ 1.0,
With Julia ≥ 1.1,

```julia-repl
pkg> add JuDoc
Expand Down
2 changes: 1 addition & 1 deletion src/converter/js_prerender.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function js2html(hs::String, jsbuffer::IOBuffer, matches::Vector{RegexMatch},
head, c = 1, 1
for i 1:2:length(matches)-1
mo, mc = matches[i:i+1]
write(htmls, subs(hs, head, mo.offset - 1))
write(htmls, subs(hs, head, prevind(hs, mo.offset)))
pp = strip(parts[c])
if startswith(pp, "<pre><code class=\"julia-repl")
pp = replace(pp, r"shell&gt;"=>"<span class=hljs-metas>shell&gt;</span>")
Expand Down
8 changes: 3 additions & 5 deletions src/converter/md.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,14 @@ function convert_inter_html(ihtml::AS,

# write whatever is at the front, skip the extra space if still present
prev = prevind(ihtml, m.offset - δ1)
if prev > 0
prev -= ifelse(ihtml[prev] == ' ', 1, 0)
else
prev = 0
if prev > 0 && ihtml[prev] == ' '
prev = prevind(ihtml, prev)
end
(head prev) && write(htmls, subs(ihtml, head:prev))
# move head appropriately
head = iend + δ2
if head strlen
head += ifelse(ihtml[head] in (' ', '>'), 1, 0)
head = ifelse(ihtml[head] in (' ', '>'), nextind(ihtml, head), head)
end
# store the resolved block
write(htmls, convert_block(blocks[i], lxcontext))
Expand Down
72 changes: 43 additions & 29 deletions test/global/postprocess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,46 @@
@test occursin("=\"/prependme/libs/katex/katex.min.css", index)
end

if J.JD_CAN_PRERENDER && J.JD_CAN_HIGHLIGHT
@testset "Prerender" begin
hs = raw"""
<!doctype html>
<html lang=en>
<meta charset=UTF-8>
<div class=jd-content>
<h1>Title</h1>
<p>Blah</p>
<p>Consider an invertible matrix \(M\) made of blocks \(A\), \(B\), \(C\) and \(D\) with</p>
\[ M \quad\!\! =\quad\!\! \begin{pmatrix} A & B \\ C & D \end{pmatrix} \]
<pre><code class=language-julia >using Test
# Woodbury formula
b = 2
println("hello $b")
</code></pre>
</div>
"""
jskx = J.js_prerender_katex(hs)
# conversion of `\(M\)` (inline)
@test occursin("""<span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>M</mi></mrow>""", jskx)
# conversion of the equation (display)
@test occursin("""<span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>M</mi>""", jskx)
jshl = J.js_prerender_highlight(hs)
# conversion of the code
@test occursin("""<pre><code class="julia hljs"><span class="hljs-keyword">using</span>""", jshl)
@test occursin(raw"""<span class="hljs-string">"hello <span class="hljs-variable">$b</span>"</span>""", jshl)
end
end # if can prerender
if J.JD_CAN_PRERENDER; @testset "prerender" begin
@testset "katex" begin
hs = raw"""
<!doctype html>
<html lang=en>
<meta charset=UTF-8>
<div class=jd-content>
<p>range is \(10\sqrt{3}\)\(20\sqrt{2}\) <!-- non-ascii en dash --></p>
<p>Consider an invertible matrix \(M\) made of blocks \(A\), \(B\), \(C\) and \(D\) with</p>
\[ M \quad\!\! =\quad\!\! \begin{pmatrix} A & B \\ C & D \end{pmatrix} \]
</div>
"""

jskx = J.js_prerender_katex(hs)
# conversion of the non-ascii endash (inline)
@test occursin("""–<span class=\"katex\">""", jskx)
# conversion of `\(M\)` (inline)
@test occursin("""<span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>M</mi></mrow>""", jskx)
# conversion of the equation (display)
@test occursin("""<span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>M</mi>""", jskx)
end

if J.JD_CAN_HIGHLIGHT; @testset "highlight" begin
hs = raw"""
<!doctype html>
<html lang=en>
<meta charset=UTF-8>
<div class=jd-content>
<h1>Title</h1>
<p>Blah</p>
<pre><code class=language-julia >using Test
# Woodbury formula
b = 2
println("hello $b")
</code></pre>
</div>
"""
jshl = J.js_prerender_highlight(hs)
# conversion of the code
@test occursin("""<pre><code class="julia hljs"><span class="hljs-keyword">using</span>""", jshl)
@test occursin(raw"""<span class="hljs-string">"hello <span class="hljs-variable">$b</span>"</span>""", jshl)
end; end # if can highlight
end; end # if can prerender
20 changes: 20 additions & 0 deletions test/parser/markdown+latex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ end
end


@testset "Unicode lx" begin
st = raw"""
Call me “$x$”, not $🍕$.
""" * J.EOS

steps = explore_md_steps(st)
blocks, _ = steps[:ocblocks]

# first math block
β = blocks[1]
@test β.name == :MATH_A
@test β.ss == "\$x\$"

# second math block
β = blocks[2]
@test β.name == :MATH_A
@test β.ss == "\$🍕\$"
end


@testset "Lx defs+coms" begin
st = raw"""
\newcommand{\E}[1]{\mathbb E\left[#1\right]}blah de blah
Expand Down

0 comments on commit 2cc0443

Please sign in to comment.