Skip to content

Commit

Permalink
Merge pull request #139 from tlienart/async-bugfix
Browse files Browse the repository at this point in the history
fixed hyperref issues due to asynchronicity, removed async
  • Loading branch information
tlienart authored May 1, 2019
2 parents 63eeca5 + cfea0bb commit baa3cdb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/converter/lx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ JD_LOC_EQDICT_COUNTER
Counter to keep track of equation numbers as they appear along the page, this helps with equation
referencing.
"""
const JD_LOC_EQDICT_COUNTER = randstring(JD_LEN_RANDSTRING+1)
const JD_LOC_EQDICT_COUNTER = "COUNTER_" * randstring(JD_LEN_RANDSTRING)

"""
$(SIGNATURES)
Expand Down Expand Up @@ -106,7 +106,6 @@ Given a latex command such as `\\eqref{abc}`, hash the reference (here `abc`), c
dictionary `d` has an entry corresponding to that hash and return the appropriate HTML for it.
"""
function form_href(lxc::LxCom, dname::String; parens="("=>")", class="href")::String

ct = content(lxc.braces[1]) # "r1, r2, r3"
refs = strip.(split(ct, ",")) # ["r1", "r2", "r3"]
names = refstring.(refs)
Expand Down
1 change: 1 addition & 0 deletions src/converter/md_blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function convert_mathblock(β::OCBlock, lxdefs::Vector{LxDef})::String

# check if there's a label, if there is, add that to the dictionary
matched = match(r"\\label{(.*?)}", inner)

if !isnothing(matched)
name = refstring(strip(matched.captures[1]))
write(htmls, "<a id=\"$name\"></a>")
Expand Down
29 changes: 15 additions & 14 deletions src/manager/judoc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@ Keyword arguments:
* `port=8000`: the port to use for the local server (should pick a number between 8000 and 9000)
* `single=false`: whether to run a single pass or run continuously
* `prerender=false`: whether to pre-render javascript (KaTeX and highlight.js)
* `nomess=false`: suppresses all messages (internal use).
"""
function serve(; clear::Bool=true, verb::Bool=false, port::Int=8000, single::Bool=false,
prerender::Bool=false)::Union{Nothing,Int}
prerender::Bool=false, nomess::Bool=false)::Union{Nothing,Int}
# set the global path
JD_FOLDER_PATH[] = pwd()
# construct the set of files to watch
watched_files = jd_setup(clear=clear)

nomess && (verb = false)

# do a first full pass
println("→ Initial full pass... ")
nomess || println("→ Initial full pass... ")
start = time()
sig = jd_fullpass(watched_files; clear=clear, verb=verb, prerender=prerender)
sig < 0 && return sig
verb && (print(rpad("\n✔ full pass...", 40)); time_it_took(start); println(""))

# start the continuous loop
if !single
println("→ Starting the server...")
nomess || println("→ Starting the server...")
coreloopfun = (cntr, fw) -> jd_loop(cntr, fw, watched_files; clear=clear, verb=verb)
# start the liveserver in the current directory
LiveServer.setverbose(verb)
Expand Down Expand Up @@ -91,9 +94,8 @@ function jd_fullpass(watched_files::NamedTuple; clear::Bool=false, verb::Bool=fa
pg_foot = read(joinpath(JD_PATHS[:in_html], "page_foot.html"), String)
foot = read(joinpath(JD_PATHS[:in_html], "foot.html"), String)

# reset page variables and latex definitions
# reset global page variables and latex definitions
def_GLOB_VARS!()
def_LOC_VARS!()
def_GLOB_LXDEFS!()

# process configuration file
Expand All @@ -104,27 +106,26 @@ function jd_fullpass(watched_files::NamedTuple; clear::Bool=false, verb::Bool=fa
indexhtml = JD_PATHS[:in] => "index.html"

# rest of the pages, done asynchronously
tasks = Vector{Task}()
s = 0
@sync begin
if isfile(joinpath(indexmd...))
push!(tasks, @async process_file(:md, indexmd, head, pg_foot, foot; clear=clear,
prerender=prerender))
s += process_file(:md, indexmd, head, pg_foot, foot; clear=clear,
prerender=prerender)
elseif isfile(joinpath(indexhtml...))
push!(tasks, @async process_file(:html, indexhtml, head, pg_foot, foot; clear=clear,
prerender=prerender))
s += process_file(:html, indexhtml, head, pg_foot, foot; clear=clear,
prerender=prerender)
else
@warn "I didn't find an index.[md|html], there should be one. Ignoring."
end
# process rest of the files
for (case, dict) pairs(watched_files), (fpair, t) dict
occursin("index.", fpair.second) && continue
sleep(0.001)
push!(tasks, @async process_file(case, fpair, head, pg_foot, foot, t; clear=clear,
prerender=prerender))
s += process_file(case, fpair, head, pg_foot, foot, t; clear=clear,
prerender=prerender)
end
end
# return -1 if any task has failed
return -Int(any(t->t.result < 0, tasks))
return ifelse(s<0, -1, 0)
end


Expand Down
2 changes: 1 addition & 1 deletion src/manager/post_processing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function optimize(; prerender::Bool=true, minify::Bool=true, sig::Bool=false)::U
print("→ Full pass")
withpre = ifelse(prerender, rpad(" (with pre-rendering)", 24), rpad(" (no pre-rendering)", 24))
print(withpre)
succ = (serve(single=true, prerender=prerender) == 0)
succ = (serve(single=true, prerender=prerender, nomess=true) === nothing)
time_it_took(start)

#
Expand Down

0 comments on commit baa3cdb

Please sign in to comment.