fix: enable code fold on all code blocks

This commit is contained in:
EnixCoda 2022-06-06 16:29:59 +08:00
parent bbf7f3d7ea
commit fcdef87b2a

View file

@ -13,6 +13,10 @@ const selectorOfLineContent = `.blob-code`
const theCSSClassForToggleElementOnActive = 'gitako-code-fold-active'
function init() {
document.querySelectorAll(tableSelector).forEach(processTable)
}
function processTable(table: Element) {
type LineNumber = number // alias
const blocks: LineNumber[] = [] // startLine -> exclusiveEndLine
/**
@ -34,8 +38,7 @@ function init() {
* 5
*/
const table = document.querySelector(tableSelector)
const lineElements = Array.from(document.querySelectorAll([tableSelector, 'tr'].join(' ')))
const lineElements = Array.from(table.querySelectorAll('tr'))
if (!table || !lineElements.length) return
if (table.classList.contains(theCSSClassMark)) {
if (table.classList.contains(theCSSClassMarkWhenDisabled)) {
@ -124,7 +127,7 @@ function init() {
if (e.target.classList.contains(theCSSClassForToggleElement)) {
const tr = e.target.parentElement?.parentElement
if (tr) {
toggleLine(lineElements.indexOf(tr))
toggleLine(lineElements.indexOf(tr as HTMLTableRowElement))
e.stopPropagation()
}
}
@ -133,8 +136,9 @@ function init() {
}
function cancelToggleFeature() {
const table = document.querySelector(tableSelector)
table?.classList.add(theCSSClassMarkWhenDisabled)
document
.querySelectorAll(tableSelector)
.forEach(table => table.classList.add(theCSSClassMarkWhenDisabled))
}
function getTextLevel(text: string) {