Skip to content

Commit

Permalink
closes #163
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart committed Jun 4, 2019
1 parent 551498a commit 4a1d0c4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
DocStringExtensions = ">= 0.7.0"
Highlights = ">= 0.3.0"
JuDocTemplates = ">= 0.1.0"
LiveServer = ">= 0.1.0"
LiveServer = ">= 0.3.0"
julia = "^1.0.0"
14 changes: 13 additions & 1 deletion src/converter/md_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function md2html(ss::AbstractString, stripp::Bool=false)::AbstractString
isempty(ss) && return ss

# Use the base Markdown -> Html converter and post process headers
partial = ss |> Markdown.parse |> Markdown.html |> make_header_refs
partial = ss |> fix_inserts |> Markdown.parse |> Markdown.html |> make_header_refs

# In some cases, base converter adds <p>...</p>\n which we might not want
stripp || return partial
Expand Down Expand Up @@ -48,6 +48,18 @@ function deactivate_divs(blocks::Vector{OCBlock})::Vector{OCBlock}
return blocks[active_blocks]
end

"""
$(SIGNATURES)
The insertion token have whitespaces around them: ` ##JDINSERT## `, this mostly helps but causes
a problem when combined with italic or bold markdown mode since `_blah_` works but not `_ blah _`.
This function looks for any occurrence of `[\\*_] ##JDINSERT##` or the opposite and removes the
extraneous whitespace.
"""
fix_inserts(s::AbstractString)::String =
replace(replace(s, r"([\*_]) ##JDINSERT##" => s"\1##JDINSERT##"),
r"##JDINSERT## ([\*_])" => s"##JDINSERT##\1")


"""
$(SIGNATURES)
Expand Down
34 changes: 34 additions & 0 deletions test/converter/markdown2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# this follows `markdown.jl` but spurred by bugs/issues

function inter(st::String)
tokens = J.find_tokens(st, J.MD_TOKENS, J.MD_1C_TOKENS)
blocks, tokens = J.find_all_ocblocks(tokens, J.MD_OCB_ALL)
lxdefs, tokens, braces, blocks = J.find_md_lxdefs(tokens, blocks)
lxcoms, _ = J.find_md_lxcoms(tokens, lxdefs, braces)
blocks2insert = J.merge_blocks(lxcoms, blocks)
inter_md, mblocks = J.form_inter_md(st, blocks2insert, lxdefs)
inter_html = J.md2html(inter_md)
return inter_md, inter_html
end

@testset "Code+italic (#163)" begin
st = raw"""A _B `C` D_ E""" * J.EOS
imd, ih = inter(st)
@test imd == "A _B ##JDINSERT## D_ E"
@test ih == "<p>A <em>B ##JDINSERT## D</em> E</p>\n"

st = raw"""A _`B` C D_ E""" * J.EOS
imd, ih = inter(st)
@test imd == "A _ ##JDINSERT## C D_ E"
@test ih == "<p>A <em>##JDINSERT## C D</em> E</p>\n"

st = raw"""A _B C `D`_ E""" * J.EOS
imd, ih = inter(st)
@test imd == "A _B C ##JDINSERT## _ E"
@test ih == "<p>A <em>B C ##JDINSERT##</em> E</p>\n"

st = raw"""A _`B` C `D`_ E""" * J.EOS
imd, ih = inter(st)
@test imd == "A _ ##JDINSERT## C ##JDINSERT## _ E"
@test ih == "<p>A <em>##JDINSERT## C ##JDINSERT##</em> E</p>\n"
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ println("🍺")
# CONVERTER folder
println("CONVERTER/MD")
include("converter/markdown.jl")
include("converter/markdown2.jl")
include("converter/hyperref.jl")
println("🍺")

Expand Down

0 comments on commit 4a1d0c4

Please sign in to comment.