Skip to content

Commit

Permalink
Fix regex for passing language to highlight.js (#960)
Browse files Browse the repository at this point in the history
Co-authored-by: Sukera <[email protected]>
  • Loading branch information
Seelengrab and Seelengrab authored May 14, 2022
1 parent 88ec5b9 commit 05b1e14
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/converter/html/prerender.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ highlight.js to pre-render them to HTML.
function js_prerender_highlight(hs::String)::String
# look for "<pre><code" and "</code></pre>" these will have been automatically generated
# and therefore the regex can be fairly strict with spaces etc
matches = collect(eachmatch(r"<pre><code\s*(class=\"?(?:language-)?(.*?)\"?)?\s*>|<\/code><\/pre>", hs))
matches = collect(eachmatch(r"<pre><code\s*(class=\"?(?:(?:language-)?(?<lang>[^\ \">]+))?(?:\s+([^\ \">]+)?)*\"?)?\s*>|<\/code><\/pre>", hs))
isempty(matches) && return hs

# buffer to write the JS script
Expand All @@ -64,7 +64,7 @@ function js_prerender_highlight(hs::String)::String
cs = subs(hs, nextind(hs, matchrange(co).stop), prevind(hs, matchrange(cc).start))
# cs = escape_string(cs)
# lang
lang = co.captures[2]
lang = co[:lang]
# un-escape code string
cs = html_unescape(cs) |> escape_string
# add to content of jsbuffer
Expand Down

0 comments on commit 05b1e14

Please sign in to comment.