From 4f7907ac68f46a3262829af987c73f18e697c0ec Mon Sep 17 00:00:00 2001 From: Thibaut Lienart Date: Sat, 24 Oct 2020 19:26:55 +0200 Subject: [PATCH] closes #670 + patch release (#671) --- Project.toml | 2 +- src/converter/markdown/md.jl | 4 ++-- src/parser/ocblocks.jl | 43 ++++++++++++++++++------------------ 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Project.toml b/Project.toml index 1bb9e7155..eed9ac852 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Franklin" uuid = "713c75ef-9fc9-4b05-94a9-213340da978e" authors = ["Thibaut Lienart "] -version = "0.10.6" +version = "0.10.7" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/converter/markdown/md.jl b/src/converter/markdown/md.jl index 33768613d..e194852d8 100644 --- a/src/converter/markdown/md.jl +++ b/src/converter/markdown/md.jl @@ -108,14 +108,14 @@ function convert_md(mds::AbstractString, (lprelx > 0) && (lxdefs = cat(pastdef.(pre_lxdefs), lxdefs, dims=1)) #>> c. find latex environments lxenvs, tokens = find_lxenvs(tokens, lxdefs, braces) - deactivate_blocks_in_envs!(blocks, lxenvs) + ranges2 = deactivate_blocks_in_envs!(blocks, lxenvs) #>> d. find latex commands lxcoms, _ = find_lxcoms(tokens, lxdefs, braces) #> 3[ex]. find double brace blocks, note we do it on pre_ocb tokens # as the step `find_all_ocblocks` possibly found and deactivated {...}. dbb = find_double_brace_blocks(toks_pre_ocb) - deactivate_inner_dbb!(dbb, ranges) + deactivate_inner_dbb!(dbb, vcat(ranges, ranges2)) # ------------------------------------------------------------------------ #> 4. Page variable definition (mddefs), also if in config, update lxdefs diff --git a/src/parser/ocblocks.jl b/src/parser/ocblocks.jl index 4951c251d..1447b1296 100644 --- a/src/parser/ocblocks.jl +++ b/src/parser/ocblocks.jl @@ -141,33 +141,13 @@ function deactivate_inner_blocks!(blocks::Vector{OCBlock}, nin=MD_OCB_NO_INNER) return ranges end - -""" -$SIGNATURES - -Given ranges found by `deactivate_inner_blocks!` deactivate double brace blocks -that are within those ranges (they will be reprocessed later). -""" -function deactivate_inner_dbb!(dbb, ranges) - isempty(dbb) && return nothing - isempty(ranges) && return nothing - 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) - isnothing(r) || (active[i] = false) - end - deleteat!(dbb, map(!, active)) - return nothing -end - """ $SIGNATURES Deactivate blocks that are contained in an environment so that they be reprocessed later. """ function deactivate_blocks_in_envs!(blocks, lxenvs) - lxe_ranges = [] + lxe_ranges = Vector{Pair{Int,Int}}() for lxe in lxenvs range = from(lxe) => to(lxe) any(r -> r.first < range.first && r.second > range.second, lxe_ranges) && continue @@ -182,7 +162,26 @@ function deactivate_blocks_in_envs!(blocks, lxenvs) end end deleteat!(blocks, inner_blocks) - return + return lxe_ranges +end + +""" +$SIGNATURES + +Given ranges found by `deactivate_inner_blocks!` deactivate double brace blocks +that are within those ranges (they will be reprocessed later). +""" +function deactivate_inner_dbb!(dbb, ranges) + isempty(dbb) && return nothing + isempty(ranges) && return nothing + 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) + isnothing(r) || (active[i] = false) + end + deleteat!(dbb, map(!, active)) + return nothing end """