From 0df6c3820360600af47b9c1cda698b9b3c91d915 Mon Sep 17 00:00:00 2001 From: Kevin Putnam Date: Fri, 4 Oct 2019 14:12:11 -0400 Subject: [PATCH] * Adds ability to create code blocks with prepended "$" that won't be copied (wip). (#837) * Fixes behavior and appearance of permalinks in collapsible sections. * Fixes links to collapsible sections so that header is now target. Signed-off-by: Kevin Putnam --- .../otc_tcs_sphinx_theme/static/tcs_theme.css | 34 ++++++++++++++++++- .../otc_tcs_sphinx_theme/static/tcs_theme.js | 28 ++++++++++----- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/source/_themes/otc_tcs_sphinx_theme/static/tcs_theme.css b/source/_themes/otc_tcs_sphinx_theme/static/tcs_theme.css index d327cf1d..9b13c2df 100644 --- a/source/_themes/otc_tcs_sphinx_theme/static/tcs_theme.css +++ b/source/_themes/otc_tcs_sphinx_theme/static/tcs_theme.css @@ -119,6 +119,8 @@ th,td { padding-left: 0 !important; } +/*Begin support for collapsbile sections*/ + .clps1 { font-size: 175%; } @@ -176,6 +178,26 @@ th,td { transition: max-height 0.2s ease-out; } +/*Fix for permalinks to collapsible sections*/ + +button a.headerlink { + visibility: hidden; +} + +button a.headerlink:after { + content: "\f0c1"; + font-size: 14px; + font-family: FontAwesome; + font-weight: normal; +} + +button:hover a.headerlink:after { + visibility: visible; +} + +/*End support for collapsbile sections*/ + +/*Begin support for custom Clear Linux header*/ #header { width: 100%; display: block; @@ -278,6 +300,8 @@ th,td { line-height: 100px; } +/*End support for custom Clear Linux header*/ + /*Adds a bit of spacing after the last paragraph in a bulleted list*/ .wy-plain-list-disc li p:last-child, .rst-content .section ul li p:last-child, .rst-content .toctree-wrapper ul li p:last-child, article ul li p:last-child { margin-bottom: 10px; @@ -291,7 +315,7 @@ div#trademarks { color: gray; } - +/*Adds magnifying glass to search box*/ #clear-docs-search { background: url(./mag-glass.png) left no-repeat; background-size: 15px 15px; @@ -312,3 +336,11 @@ div#trademarks { .pending-delete-status { color:#ce2029; } + +/*Begin support for code blocks with $ signs that aren't copied with content*/ + +.bash-dollar:before { + content: '$ '; +} + +/*End support for code blocks with $ signs that aren't copied with content*/ \ No newline at end of file diff --git a/source/_themes/otc_tcs_sphinx_theme/static/tcs_theme.js b/source/_themes/otc_tcs_sphinx_theme/static/tcs_theme.js index 9064b9f7..b44f33cf 100644 --- a/source/_themes/otc_tcs_sphinx_theme/static/tcs_theme.js +++ b/source/_themes/otc_tcs_sphinx_theme/static/tcs_theme.js @@ -1,21 +1,34 @@ var i; var contents = document.getElementsByClassName("content-collapse section"); +var bashDollarDivs = document.getElementsByClassName("bash-dollars highlight-bash"); + +for (i = 0; i< bashDollarDivs.length; i++) { + _pre = bashDollarDivs[i].querySelectorAll("pre"); + for (j = 0; j < _pre.length; j++) { + console.log(_pre[j]); + _pre[j].innerHTML=""+(_pre[j].textContent.split("\n").filter(Boolean).join("\n"))+""; + } +} + for (i = 0; i < contents.length; i++) { //Make sure the "content-collapse section" class is occurring in
if (contents[i].tagName.toLowerCase() == 'div') { var element = contents[i].children[0]; var element_type = element.tagName.toLowerCase(); - var span_id; - var spanElement; + var btn_id; + var divElement; - //if the next element is a span grab the id and skip to the header + divElement = contents[i]; + btn_id = contents[i].id; + + //if the next element is a span skip to the header if (element_type == 'span') { - span_id = element.id; - element.id = ""; element = contents[i].children[1]; element_type = element.tagName.toLowerCase(); + } else { + divElement.id = ""; } var btn = document.createElement("BUTTON"); @@ -28,7 +41,7 @@ for (i = 0; i < contents.length; i++) { btn.className += " " + newClass; btn.innerHTML = element.innerHTML; btn.className += " collapsible"; - btn.id = span_id; + btn.id = btn_id; btn.addEventListener("click", function() { this.classList.toggle("active"); var content = this.nextElementSibling; @@ -42,9 +55,6 @@ for (i = 0; i < contents.length; i++) { //Add the button to the page and remove the header contents[i].parentNode.insertBefore(btn, contents[i]); contents[i].removeChild(element); - }else{ - //reset span id if it isn't followed by Hx element - spanElement.id = span_id; } } } \ No newline at end of file