Skip to content

Commit d594417

Browse files
committed
Add wbr tags in long inline code spans
1 parent 2d79d97 commit d594417

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/render_html.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ function highlight(lang, text) {
3535
return result
3636
}
3737

38+
function maybeSplitInlineCode(html) {
39+
if (html.length <= 16) return html
40+
return html.replace(/[.\/](?!\/)/, "$&<wbr>")
41+
}
42+
3843
function anchor(token) {
3944
return token.hashID ? `<a class="${token.hashID.charAt(0)}_ident" id="${token.hashID}" href="#${token.hashID}"></a>` : ""
4045
}
@@ -88,7 +93,7 @@ let renderer = {
8893

8994
html_block(token) { return token.content },
9095

91-
code_inline(token) { return `<code>${escape(token.content)}</code>` },
96+
code_inline(token) { return `<code>${maybeSplitInlineCode(escape(token.content))}</code>` },
9297

9398
strong_open() { return "<strong>" },
9499
strong_close() { return "</strong>" },

0 commit comments

Comments
 (0)