Skip to content

Commit c2f23b1

Browse files
authored
Fix nocopy and noheader behavior (#253)
Fixes an issue where adding `role=nocopy` to a code block was also removing the header. It is now possible to use: - `role=nocopy` to not display the copy icon - `role=noheader` to not display the header - `role=nocopy noheader` to not display both
1 parent 087859e commit c2f23b1

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

preview-src/index.adoc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,23 +521,31 @@ CREATE (n:Node {id: id, test: true, str: 'ing'})
521521
RETURN collect(n) AS ns
522522
----
523523

524-
.noheader
524+
.Codeblock with role=noheader
525525
[source,cypher,role=noheader]
526526
----
527527
UNWIND range(0, 100) AS id
528528
CREATE (n:Node {id: id, test: true, str: 'ing'})
529529
RETURN collect(n) AS ns
530530
----
531531

532-
.nocopy
532+
.Codeblock with role=nocopy
533533
[source,cypher,role=nocopy]
534534
----
535535
UNWIND range(0, 100) AS id
536536
CREATE (n:Node {id: id, test: true, str: 'ing'})
537537
RETURN collect(n) AS ns
538538
----
539539

540+
.Codeblock with role=nocopy noheader
541+
[source,cypher,role=nocopy noheader]
542+
----
543+
UNWIND range(0, 100) AS id
544+
CREATE (n:Node {id: id, test: true, str: 'ing'})
545+
RETURN collect(n) AS ns
546+
----
540547

548+
.Just some pre
541549
....
542550
pom.xml
543551
src/

src/js/06-code.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ document.addEventListener('DOMContentLoaded', function () {
131131

132132
listingBlock.classList.add('has-header')
133133

134-
if (originalTitle) {
134+
if (originalTitle && !listingBlock.classList.contains('noheader')) {
135135
listingBlock.classList.add('has-title')
136136
var titleDiv = document.createElement('div')
137137
titleDiv.className = 'code-title'
@@ -140,6 +140,8 @@ document.addEventListener('DOMContentLoaded', function () {
140140
headerDivs.push(titleDiv)
141141
}
142142

143+
var inset = createElement('div', 'code-inset')
144+
143145
if (addCopyButton) {
144146
var copyButton = createElement('span', 'btn btn-copy fa fa-copy')
145147

@@ -168,22 +170,13 @@ document.addEventListener('DOMContentLoaded', function () {
168170
}, 1000)
169171
})
170172

171-
var inset = createElement('div', 'code-inset', copyButton)
172-
if (language !== 'none' && language) inset.dataset.lang = casedLang(language)
173-
173+
inset.appendChild(copyButton)
174174
inset.appendChild(copySuccess)
175-
176-
// if (originalTitle) {
177-
// div.insertBefore(inset, pre)
178-
// } else {
179-
// pre.appendChild(inset)
180-
// }
181-
182-
// pre.appendChild(inset)
183-
184-
headerDivs.push(inset)
185175
}
186176

177+
if (language !== 'none' && language) inset.dataset.lang = casedLang(language)
178+
headerDivs.push(inset)
179+
187180
var header = createElement('div', 'code-header', headerDivs)
188181
div.insertBefore(header, pre)
189182
}

0 commit comments

Comments
 (0)