Repository: tlienart/Franklin.jl
Pull request #522 (2020-06-13 15:08:11)

Dev01
brings in #511, #510, supersedes #509 #508 #507 

adds anchor class to anchors.

closes #511, 
closes #510, 
closes #509 
closes #508 
closes #507 


Patch:
diff --git a/Project.toml b/Project.toml
index d1108a23..88a3c936 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.3"
+version = "0.8.4"
 
 [deps]
 Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
@@ -25,7 +25,7 @@ DocStringExtensions = "0.8"
 FranklinTemplates = "0.6,0.7"
 HTTP = "0.8"
 Literate = "2.2"
-LiveServer = "0.3"
+LiveServer = "0.4,0.5"
 NodeJS = "0.6,1"
 OrderedCollections = "1.1"
 julia = "1.1"
diff --git a/src/converter/latex/hyperrefs.jl b/src/converter/latex/hyperrefs.jl
index 88c226d4..82766913 100644
--- a/src/converter/latex/hyperrefs.jl
+++ b/src/converter/latex/hyperrefs.jl
@@ -72,13 +72,13 @@ lx_citep(lxc::LxCom, _) = form_href(lxc, "BIBR"; class="bibref")
 
 function lx_label(lxc::LxCom, _)
     refs = content(lxc.braces[1]) |> strip |> refstring
-    return "<a id=\"$refs\"></a>"
+    return "<a id=\"$refs\" class=\"anchor\"></a>"
 end
 
 function lx_biblabel(lxc::LxCom, _)::String
     name = refstring(stent(lxc.braces[1]))
     PAGE_BIBREFS[name] = content(lxc.braces[2])
-    return "<a id=\"$name\"></a>"
+    return "<a id=\"$name\" class=\"anchor\"></a>"
 end
 
 function lx_toc(::LxCom, _)
diff --git a/src/converter/markdown/blocks.jl b/src/converter/markdown/blocks.jl
index 72475503..8babbcb0 100644
--- a/src/converter/markdown/blocks.jl
+++ b/src/converter/markdown/blocks.jl
@@ -92,7 +92,7 @@ function convert_math_block(β::OCBlock, lxdefs::Vector{LxDef})::String
 
         if !isnothing(matched)
             name   = refstring(matched.captures[1])
-            write(htmls, "<a id=\"$name\"></a>")
+            write(htmls, "<a id=\"$name\" class=\"anchor\"></a>")
             inner  = replace(inner, r"\\label{.*?}" => "")
             # store the label name and associated number
             PAGE_EQREFS[name] = PAGE_EQREFS[PAGE_EQREFS_COUNTER]
diff --git a/src/manager/dir_utils.jl b/src/manager/dir_utils.jl
index 884921ac..6ac37964 100644
--- a/src/manager/dir_utils.jl
+++ b/src/manager/dir_utils.jl
@@ -94,6 +94,10 @@ function _out_path2(base::String)::String
     return outpath
 end
 
+_access(p)   = isa(p, Regex) ? p.pattern : p
+_isempty(p)  = isempty(_access(p))
+_endswith(p) = endswith(_access(p), '/')
+
 
 """
 $(SIGNATURES)
@@ -103,10 +107,13 @@ The variable `verb` propagates verbosity.
 """
 function scan_input_dir!(args...; kw...)
     to_ignore = union(IGNORE_FILES, globvar("ignore"))
-    # differentiate between files and dirs
-    dir_indicator = [endswith(c, "/") for c in to_ignore]
-    d2i = [d for d in to_ignore[dir_indicator] if length(d) > 1]
-    f2i = filter!((!) ∘ isempty, to_ignore[.!dir_indicator])
+    # remove empty patterns or strings
+    filter!(!_isempty, to_ignore)
+    # differentiate between files and dirs pattern
+    dir_indicator = [_endswith(c) for c in to_ignore]
+    # ignore "/"
+    d2i = filter!(d -> length(d) > 1, to_ignore[dir_indicator])
+    f2i = to_ignore[.!dir_indicator]
 
     if FD_ENV[:STRUCTURE] < v"0.2"
         return _scan_input_dir!(args...; files2ignore=f2i, dirs2ignore=d2i)
@@ -120,8 +127,8 @@ function _scan_input_dir!(other_files::TrackedFiles,
                           html_files::TrackedFiles,
                           literate_files::TrackedFiles,
                           verb::Bool=false;
-                          files2ignore::Vector{String}=String[],
-                          dirs2ignore::Vector{String}=String[])::Nothing
+                          files2ignore=String[],
+                          dirs2ignore=String[])::Nothing
     # top level files (src/*)
     for file ∈ readdir(PATHS[:src])
         fpath = joinpath(PATHS[:src], file)
@@ -188,8 +195,8 @@ function _scan_input_dir2!(other_files::TrackedFiles,
                            literate_scripts::TrackedFiles,
                            verb::Bool=false;
                            in_loop::Bool=false,
-                           files2ignore::Vector{String}=String[],
-                           dirs2ignore::Vector{String}=String[])::Nothing
+                           files2ignore::Vector=String[],
+                           dirs2ignore::Vector=String[])::Nothing
     # go over all files in the website folder
     for (root, _, files) ∈ walkdir(path(:folder))
         for file in files
@@ -270,17 +277,19 @@ Rules:
 * `'path/fname'` -> ignore exactly that
 * `'path/dir/'`  -> ignore everything starting with `path/dir/`
 """
-function should_ignore(fpath::AS, files2ignore::Vector{String},
-                       dirs2ignore::Vector{String})::Bool
+function should_ignore(fpath::AS, files2ignore::Vector,
+                       dirs2ignore::Vector)::Bool
     # fpath is necessarily an absolute path so can strip the folder part
     if FD_ENV[:STRUCTURE] < v"0.2"
         fpath = fpath[length(path(:src))+length(PATH_SEP)+1:end]
     else
         fpath = fpath[length(path(:folder))+length(PATH_SEP)+1:end]
     end
-    flag  = findfirst(c -> c == fpath, files2ignore)
-    isnothing(flag) || return true
-    flag  = findfirst(c -> startswith(fpath, c), dirs2ignore)
+    if any(c -> c isa Regex ? match(c, fpath) !== nothing : c == fpath,
+               files2ignore)
+        return true
+    end
+    flag = findfirst(c -> startswith(fpath, c), dirs2ignore)
     isnothing(flag) || return true
     return false
 end
diff --git a/src/manager/franklin.jl b/src/manager/franklin.jl
index d927ea13..a2a38175 100644
--- a/src/manager/franklin.jl
+++ b/src/manager/franklin.jl
@@ -42,6 +42,7 @@ Keyword arguments:
 * `on_write(pg, fd_vars)`: callback function after the page is rendered,
                       passing as arguments the rendered page and the page
                       variables
+* `host="127.0.0.1"`: the host to use for the local server
 """
 function serve(; clear::Bool=false,
                  verb::Bool=false,
@@ -55,7 +56,8 @@ function serve(; clear::Bool=false,
                  silent::Bool=false,
                  cleanup::Bool=true,
                  on_write::Function=(_, _) -> nothing,
-                 log::Bool=false
+                 log::Bool=false,
+                 host::String="127.0.0.1"
                  )::Union{Nothing,Int}
     LOGGING[] = log
     # set the global path
@@ -132,7 +134,7 @@ function serve(; clear::Bool=false,
         live_server_dir = ifelse(FD_ENV[:STRUCTURE] < v"0.2", "", "__site")
         LiveServer.setverbose(verb)
         LiveServer.serve(port=port, coreloopfun=coreloopfun,
-                         dir=live_server_dir)
+                         dir=live_server_dir, host=host)
     end
     flag_env &&
         rprint("→ Use Pkg.activate() to go back to your main environment.")
diff --git a/src/utils/vars.jl b/src/utils/vars.jl
index 9f59baa0..d67a1ece 100644
--- a/src/utils/vars.jl
+++ b/src/utils/vars.jl
@@ -23,7 +23,7 @@ const GLOBAL_VARS_DEFAULT = [
     "date_shortdays"   => Pair(String[],     (Vector{String},)),
     "prepath"          => Pair("",           (String,)),
     # will be added to IGNORE_FILES
-    "ignore"           => Pair(String[], (Vector{String},)),
+    "ignore"           => Pair(String[], (Vector{Any},)),
     # RSS
     "website_title"    => Pair("",   (String,)),
     "website_descr"    => Pair("",   (String,)),


Test patch:
diff --git a/test/converter/md/hyperref.jl b/test/converter/md/hyperref.jl
index 2c6fc0a6..ba107a3b 100644
--- a/test/converter/md/hyperref.jl
+++ b/test/converter/md/hyperref.jl
@@ -34,7 +34,7 @@
     @test isapproxstr(h, """
         <p>
           Some string
-          <a id="$h1"></a>\\[ x = x \\]
+          <a id="$h1" class=\"anchor\"></a>\\[ x = x \\]
           then as per <span class="bibref"><a href="#$h2">Amari and Douglas., 1998</a></span>  also this <span class="bibref">(<a href="#$h3">Bardenet et al., 2017</a>)</span>  and
           <span class="bibref"><a href="#$h2">Amari and Douglas., 1998</a>, <a href="#$h3">Bardenet et al., 2017</a></span>
           Reference to equation: <span class="eqref">(<a href="#$h1">1</a>)</span> .
@@ -43,8 +43,8 @@
           Then maybe some text etc.
         </p>
         <ul>
-          <li><p><a id="$h2"></a>  <strong>Amari</strong> and <strong>Douglas</strong>: <em>Why Natural Gradient</em>, 1998.</p></li>
-          <li><p><a id="$h3"></a>  <strong>Bardenet</strong>, <strong>Doucet</strong> and <strong>Holmes</strong>: <em>On Markov Chain Monte Carlo Methods for Tall Data</em>, 2017.</p></li>
+          <li><p><a id="$h2" class=\"anchor\"></a>  <strong>Amari</strong> and <strong>Douglas</strong>: <em>Why Natural Gradient</em>, 1998.</p></li>
+          <li><p><a id="$h3" class=\"anchor\"></a>  <strong>Bardenet</strong>, <strong>Doucet</strong> and <strong>Holmes</strong>: <em>On Markov Chain Monte Carlo Methods for Tall Data</em>, 2017.</p></li>
         </ul>
         """)
 end
@@ -58,7 +58,7 @@ end
        and *B $E$*.
     """
     h = st |> seval
-    @test occursin(raw"""<a id="eq_1"></a>\[ x = x \]""", h)
+    @test occursin(raw"""<a id="eq_1" class=\"anchor\"></a>\[ x = x \]""", h)
     @test occursin(raw"""<span class="eqref">(<a href="#eq_1">1</a>)</span>.""", h)
     @test occursin(raw"""<em>B \(E\)</em>.""", h)
 end
@@ -85,5 +85,5 @@ end
     h1 = F.refstring("eq:a trivial one")
     h2 = F.refstring("beyond hope")
 
-    m == "<p>Then something like  \$\$\\begin{array}{c}  \\mathbb E\\left[ f(X)\\right] \\in \\mathbb R &\\text{if}& f:\\mathbb R\\maptso\\mathbb R\\end{array}\$\$ and then  <a id=\"$h1\"></a>\$\$\\begin{array}{c}  1+1 &=&2 \\end{array}\$\$ but further  <a id=\"$h2\"></a>\$\$\\begin{array}{c}  1 &=& 1 \\end{array}\$\$ and finally a  <span class=\"eqref)\">({{href EQR $h1}})</span> and maybe  <span class=\"eqref)\">({{href EQR $h2}})</span>.</p>\n"
+    m == "<p>Then something like  \$\$\\begin{array}{c}  \\mathbb E\\left[ f(X)\\right] \\in \\mathbb R &\\text{if}& f:\\mathbb R\\maptso\\mathbb R\\end{array}\$\$ and then  <a id=\"$h1\" class=\"anchor\"></a>\$\$\\begin{array}{c}  1+1 &=&2 \\end{array}\$\$ but further  <a id=\"$h2\" class=\"anchor\"></a>\$\$\\begin{array}{c}  1 &=& 1 \\end{array}\$\$ and finally a  <span class=\"eqref)\">({{href EQR $h1}})</span> and maybe  <span class=\"eqref)\">({{href EQR $h2}})</span>.</p>\n"
 end
diff --git a/test/global/cases1.jl b/test/global/cases1.jl
index f2570fb1..0314dee5 100644
--- a/test/global/cases1.jl
+++ b/test/global/cases1.jl
@@ -203,5 +203,5 @@ end
         """
     F.def_GLOBAL_LXDEFS!()
     r = st |> conv
-    @test occursin("here <a id=\"anchor\"></a> done.", r)
+    @test occursin("here <a id=\"anchor\" class=\"anchor\"></a> done.", r)
 end
diff --git a/test/manager/dir_utils.jl b/test/manager/dir_utils.jl
index 8a590793..80ab5a25 100644
--- a/test/manager/dir_utils.jl
+++ b/test/manager/dir_utils.jl
@@ -3,11 +3,11 @@ fs2()
 @testset "ignore/fs2" begin
     gotd()
     s = """
-        @def ignore = ["foo.md", "path/foo.md", "dir/", "path/dir/"]
+        @def ignore = ["foo.md", "path/foo.md", "dir/", "path/dir/", r"index2.*"]
         """
     write(joinpath(td, "config.md"), s);
     F.process_config()
-    @test F.globvar("ignore") == ["foo.md", "path/foo.md", "dir/", "path/dir/"]
+    @test F.globvar("ignore") == ["foo.md", "path/foo.md", "dir/", "path/dir/", r"index2.*"]
 
     write(joinpath(td, "foo.md"), "anything")
     mkpath(joinpath(td, "path"))
@@ -17,6 +17,7 @@ fs2()
     mkpath(joinpath(td, "path", "dir"))
     write(joinpath(td, "path", "dir", "foo2.md"), "anything")
     write(joinpath(td, "index.md"), "standard things")
+    write(joinpath(td, "index2.md"), "anything")
     watched = F.fd_setup()
     @test length(watched.md) == 1
     @test first(watched.md).first.second == "index.md"