Skip to content

Commit cc7bd5d

Browse files
authored
Wrap slash characters in tables (#15774)
* include slashes in list of chars to inject <wbr> tags around for better table rendering * add clarifying comment to tables.scss
1 parent 3df90fc commit cc7bd5d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

javascripts/wrap-code-terms.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
const wordsLongerThan18Chars = /[\w:]{18,}/g
1+
const wordsLongerThan18Chars = /[\w:/\\]{18,}/g
22
const camelCaseChars = /([a-z])([A-Z])/g
33
const underscoresAfter12thChar = /([\w:]{12}[^_]*?)_/g
4+
const slashChars = /([/\\])/g
45

5-
// insert a <wbr> tag in code terms that use camelcase or underscore
6-
// inspired by http://heap.ch/blog/2016/01/19/camelwrap/
6+
// This module improves table rendering on reference pages by inserting a <wbr>
7+
// tag in code terms that use camelcase, slashes, or underscores, inspired by
8+
// http://heap.ch/blog/2016/01/19/camelwrap/
79
export default function () {
810
const codeTerms = document.querySelectorAll('#article-contents table code')
911
if (!codeTerms) return
@@ -17,6 +19,8 @@ export default function () {
1719
// to keep word breaks looking nice, only break on underscores after the 12th char
1820
// so `has_organization_projects` will break after `has_organization` instead of after `has_`
1921
.replace(underscoresAfter12thChar, '$1_<wbr>')
22+
// Some Actions reference pages have tables with code terms separated by slashes
23+
.replace(slashChars, '$1<wbr>')
2024
})
2125
})
2226
}

stylesheets/tables.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
border-collapse: collapse;
33
position: relative;
44
font-size: 90%;
5+
/* We want to keep table-layout: auto so that column widths dynamically adjust;
6+
otherwise entries get needlessly smushed into narrow columns. As a workaround,
7+
we use javascripts/wrap-code-terms.js to prevent some reference table content
8+
from expanding beyond the horizontal boundaries of the parent element. */
59
table-layout: auto;
610

711
code {

0 commit comments

Comments
 (0)