From dd4d5a0ec1c0d0d119fa15f0107c43b0bb07f9e3 Mon Sep 17 00:00:00 2001 From: Fengyang Wang Date: Sun, 29 Sep 2019 12:37:53 -0400 Subject: [PATCH 1/3] Fix crash if non-ASCII character precedes $ math (#239) * Fix crash if non-ASCII character precedes $ math * Fix similar crash in prerendering step --- src/converter/js_prerender.jl | 2 +- src/converter/md.jl | 6 +-- test/global/postprocess.jl | 72 +++++++++++++++++++++-------------- test/parser/markdown+latex.jl | 20 ++++++++++ 4 files changed, 66 insertions(+), 34 deletions(-) diff --git a/src/converter/js_prerender.jl b/src/converter/js_prerender.jl index 063fc833c..b54cc096c 100644 --- a/src/converter/js_prerender.jl +++ b/src/converter/js_prerender.jl @@ -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, "
"shell>")
diff --git a/src/converter/md.jl b/src/converter/md.jl
index a38cdf810..b85cc6f9e 100644
--- a/src/converter/md.jl
+++ b/src/converter/md.jl
@@ -290,10 +290,8 @@ 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
diff --git a/test/global/postprocess.jl b/test/global/postprocess.jl
index 055a15242..445aaf0f5 100644
--- a/test/global/postprocess.jl
+++ b/test/global/postprocess.jl
@@ -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"""
-    
-    
-    
-    
-

Title

-

Blah

-

Consider an invertible matrix \(M\) made of blocks \(A\), \(B\), \(C\) and \(D\) with

- \[ M \quad\!\! =\quad\!\! \begin{pmatrix} A & B \\ C & D \end{pmatrix} \] -
using Test
-      # Woodbury formula
-      b = 2
-      println("hello $b")
-      
-
- """ - jskx = J.js_prerender_katex(hs) - # conversion of `\(M\)` (inline) - @test occursin("""M""", jskx) - # conversion of the equation (display) - @test occursin("""M""", jskx) - jshl = J.js_prerender_highlight(hs) - # conversion of the code - @test occursin("""
using""", jshl)
-  @test occursin(raw""""hello $b"""", jshl)
-end
-end # if can prerender
+if J.JD_CAN_PRERENDER; @testset "prerender" begin
+    @testset "katex" begin
+        hs = raw"""
+        
+        
+        
+        
+

range is \(10\sqrt{3}\)–\(20\sqrt{2}\)

+

Consider an invertible matrix \(M\) made of blocks \(A\), \(B\), \(C\) and \(D\) with

+ \[ M \quad\!\! =\quad\!\! \begin{pmatrix} A & B \\ C & D \end{pmatrix} \] +
+ """ + + jskx = J.js_prerender_katex(hs) + # conversion of the non-ascii endash (inline) + @test occursin("""–""", jskx) + # conversion of `\(M\)` (inline) + @test occursin("""M""", jskx) + # conversion of the equation (display) + @test occursin("""M""", jskx) + end + + if J.JD_CAN_HIGHLIGHT; @testset "highlight" begin + hs = raw""" + + + +
+

Title

+

Blah

+
using Test
+        # Woodbury formula
+        b = 2
+        println("hello $b")
+        
+
+ """ + jshl = J.js_prerender_highlight(hs) + # conversion of the code + @test occursin("""
using""", jshl)
+        @test occursin(raw""""hello $b"""", jshl)
+    end; end # if can highlight
+end; end # if can prerender
diff --git a/test/parser/markdown+latex.jl b/test/parser/markdown+latex.jl
index 621eebd1f..b5d784e11 100644
--- a/test/parser/markdown+latex.jl
+++ b/test/parser/markdown+latex.jl
@@ -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

From d4cdb0efa2dfcd5a97013ca80c1e964327acf402 Mon Sep 17 00:00:00 2001
From: Thibaut Lienart 
Date: Sun, 29 Sep 2019 18:39:41 +0200
Subject: [PATCH 2/3] adding a nextind and restricting to 1.1

---
 Project.toml        | 2 +-
 README.md           | 2 +-
 docs/src/index.md   | 2 +-
 src/converter/md.jl | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/Project.toml b/Project.toml
index 746d76990..bc61b9c4d 100644
--- a/Project.toml
+++ b/Project.toml
@@ -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"
diff --git a/README.md b/README.md
index 7ded06bf9..1e3eab773 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/docs/src/index.md b/docs/src/index.md
index 346c74da9..e46bc57d7 100644
--- a/docs/src/index.md
+++ b/docs/src/index.md
@@ -26,7 +26,7 @@ On this page:
 
 ## Installation
 
-With Julia ≥ 1.0,
+With Julia ≥ 1.1,
 
 ```julia-repl
 pkg> add JuDoc
diff --git a/src/converter/md.jl b/src/converter/md.jl
index b85cc6f9e..5ec4fb482 100644
--- a/src/converter/md.jl
+++ b/src/converter/md.jl
@@ -297,7 +297,7 @@ function convert_inter_html(ihtml::AS,
         # 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))

From 6e168422c2a5e1d052c679325c5dbbb8a334f6b0 Mon Sep 17 00:00:00 2001
From: Thibaut Lienart 
Date: Sun, 29 Sep 2019 18:40:49 +0200
Subject: [PATCH 3/3] fixing travis

---
 .travis.yml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index f32b0b528..07cde5164 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,7 +3,6 @@ language: julia
 os:
   - linux
 julia:
-  - 1.0
   - 1.1
   - 1.2
   - 1.3