Repository: tlienart/Franklin.jl
Pull request #503 (2020-05-29 08:42:26)

I502


Patch:
diff --git a/Project.toml b/Project.toml
index 35146712..645c979a 100644
--- a/Project.toml
+++ b/Project.toml
@@ -1,7 +1,7 @@
 name = "Franklin"
 uuid = "713c75ef-9fc9-4b05-94a9-213340da978e"
 authors = ["Thibaut Lienart <tlienart@me.com>"]
-version = "0.8.0"
+version = "0.8.1"
 
 [deps]
 Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
diff --git a/src/converter/markdown/md.jl b/src/converter/markdown/md.jl
index 86bef2b6..7edb6e9b 100644
--- a/src/converter/markdown/md.jl
+++ b/src/converter/markdown/md.jl
@@ -20,8 +20,8 @@ Returns the html string as well as a dictionary of page variables.
 * `has_mddefs=true`:   a bool indicating whether to look for definitions of
                         page variables
 """
-function convert_md(mds::AS,
-                    pre_lxdefs::Vector{LxDef}=collect(values(GLOBAL_LXDEFS));
+function convert_md(mds::AbstractString,
+                    pre_lxdefs=collect(values(GLOBAL_LXDEFS));
                     isrecursive::Bool=false,
                     isinternal::Bool=false,
                     isconfig::Bool=false,
@@ -103,6 +103,7 @@ function convert_md(mds::AS,
     # as the step `find_all_ocblocks` possibly found and deactivated {...}.
     dbb = find_double_brace_blocks(toks_pre_ocb)
     deactivate_inner_dbb!(dbb, ranges)
+
     # ------------------------------------------------------------------------
     #> 4. Page variable definition (mddefs), also if in config, update lxdefs
     if has_mddefs
@@ -138,8 +139,8 @@ function convert_md(mds::AS,
 
     #> 1. Merge all the blocks that will need further processing before
     # insertion
-    b2insert = merge_blocks(lxcoms, deactivate_divs(blocks),
-                            sp_chars, fnrefs, dbb, hrules)
+    b2insert = merge_blocks(lxcoms, deactivate_divs(vcat(blocks, dbb)),
+                            sp_chars, fnrefs, hrules)
 
     #> 2. Form intermediate markdown + html
     inter_md, mblocks = form_inter_md(mds, b2insert, lxdefs)
diff --git a/src/converter/markdown/utils.jl b/src/converter/markdown/utils.jl
index 7e3db1c7..a7d06613 100644
--- a/src/converter/markdown/utils.jl
+++ b/src/converter/markdown/utils.jl
@@ -41,8 +41,9 @@ from_ifsmaller(v::Vector, idx::Int, len::Int)::Int = (idx > len) ? BIG_INT : fro
 """
 $(SIGNATURES)
 
-Since divs are recursively processed, once they've been found, everything inside them needs to be
-deactivated and left for further re-processing to avoid double inclusion.
+Since divs are recursively processed, once they've been found, everything
+inside them needs to be deactivated and left for further re-processing to
+avoid double inclusion.
 """
 function deactivate_divs(blocks::Vector{OCBlock})::Vector{OCBlock}
     active_blocks = ones(Bool, length(blocks))
diff --git a/src/parser/ocblocks.jl b/src/parser/ocblocks.jl
index df33e3e5..d4919db4 100644
--- a/src/parser/ocblocks.jl
+++ b/src/parser/ocblocks.jl
@@ -95,7 +95,7 @@ reprocessed. There's effectively two cases:
     is contained inside a larger block.
 """
 function deactivate_inner_blocks!(blocks::Vector{OCBlock}, nin=MD_OCB_NO_INNER)
-    ranges  = Vector{Pair{Int,Int}}()
+    ranges = Vector{Pair{Int,Int}}()
     isempty(blocks) && return ranges
     # see #444 it's important to ensure the blocks are sorted and they now
     # may not be given that we're finding them in 2 passes.
@@ -107,12 +107,14 @@ function deactivate_inner_blocks!(blocks::Vector{OCBlock}, nin=MD_OCB_NO_INNER)
     nb      = length(blocks)
     active  = ones(Bool, nb)
     heads   = from.(blocks)
-    while i < nb
+    while i <= nb
         cblock = blocks[i]
+        # is the block active and is it a "no-inner"?
         if active[i] && cblock.name ∈ nin
             # find all blocks within the span of this block, deactivate them
             chead = heads[i]
             ctail = to(cblock)
+            # keep track of the range
             push!(ranges, (chead => ctail))
             # look at all blocks starting after the current one that may
             # be within its span (note that, at worst, we have a few thousand
@@ -139,7 +141,7 @@ function deactivate_inner_dbb!(dbb, ranges)
     active = ones(Bool, length(dbb))
     for (i, d) in enumerate(dbb)
         hd, td = from(d), to(d)
-        r = findfirst(r -> r.first <= hd && td <= r.second, ranges)
+        r = findfirst(r -> r.first < hd && td < r.second, ranges)
         isnothing(r) || (active[i] = false)
     end
     deleteat!(dbb, map(!, active))


Test patch:
diff --git a/test/global/cases2.jl b/test/global/cases2.jl
index b1ef339e..ee1cefd7 100644
--- a/test/global/cases2.jl
+++ b/test/global/cases2.jl
@@ -187,7 +187,7 @@ end
         {{hasmath}} {{hascode}}
         $x = 5$
         """ |> fdi
-    @test isapproxstr(s, "<p>true false \\(x = 5\\)</p>")
+    @test isapproxstr(s, "true false \\(x = 5\\)")
     F.set_var!(F.LOCAL_VARS, "hascode", false)
     F.set_var!(F.LOCAL_VARS, "hasmath", false)
     s = raw"""
@@ -196,8 +196,8 @@ end
         blah
         ```
         """ |> fdi
-    @test isapproxstr(s, """<p>
+    @test isapproxstr(s, """
         false true
-        <pre><code class=\"language-r\">blah</code></pre></p>
+        <pre><code class=\"language-r\">blah</code></pre>
         """)
 end
diff --git a/test/parser/markdown-extra.jl b/test/parser/markdown-extra.jl
index fd09d487..554e9e2b 100644
--- a/test/parser/markdown-extra.jl
+++ b/test/parser/markdown-extra.jl
@@ -117,13 +117,13 @@ end
         @def title = "hello"
         {{title}}{{title}}
         """ |> fd2html_td
-    @test isapproxstr(s, "<p>hellohello</p>")
+    @test isapproxstr(s, "hellohello")
     s = """
         @def a_b = "hello"
         @def c_d = "goodbye"
         {{a_b}}{{c_d}}
         """ |> fd2html_td
-    @test isapproxstr(s, "<p>hellogoodbye</p>")
+    @test isapproxstr(s, "hellogoodbye")
 end
 
 # issue 424 with double braces
@@ -134,7 +134,7 @@ end
         $\rho=\frac{e^{-\beta \mathcal{E}_{s}}} {\mathcal{Z}} $
         """ |> fd2html_td
     @test isapproxstr(s, """
-        <p>hello \\(\\rho=\\frac{e^{-\\beta \\mathcal{E}_{s}}} {\\mathcal{Z}} \\)</p>""")
+        hello \\(\\rho=\\frac{e^{-\\beta \\mathcal{E}_{s}}} {\\mathcal{Z}} \\)""")
 end
 
 # issue 432 and consequences
diff --git a/test/parser/md-dbb.jl b/test/parser/md-dbb.jl
index f8f8c514..7727ac58 100644
--- a/test/parser/md-dbb.jl
+++ b/test/parser/md-dbb.jl
@@ -51,3 +51,13 @@ end
         <div class="bold">2.0</div>
         """)
 end
+
+@testset "iss#502" begin
+    s = """
+       @def upcoming_release_short = "1.5"
+       @def upcoming_release_date = "May 28, 2020"
+
+       Blah v{{upcoming_release_short}} and {{upcoming_release_date}}.
+       """ |> fd2html
+    @test isapproxstr(s, "<p>Blah v1.5 and May 28, 2020.</p>")
+end