Skip to content

Commit 05b1e14

Browse files
authored
Fix regex for passing language to highlight.js (#960)
Co-authored-by: Sukera <[email protected]>
1 parent 88ec5b9 commit 05b1e14

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/converter/html/prerender.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ highlight.js to pre-render them to HTML.
4646
function js_prerender_highlight(hs::String)::String
4747
# look for "<pre><code" and "</code></pre>" these will have been automatically generated
4848
# and therefore the regex can be fairly strict with spaces etc
49-
matches = collect(eachmatch(r"<pre><code\s*(class=\"?(?:language-)?(.*?)\"?)?\s*>|<\/code><\/pre>", hs))
49+
matches = collect(eachmatch(r"<pre><code\s*(class=\"?(?:(?:language-)?(?<lang>[^\ \">]+))?(?:\s+([^\ \">]+)?)*\"?)?\s*>|<\/code><\/pre>", hs))
5050
isempty(matches) && return hs
5151

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

0 commit comments

Comments
 (0)