// transformer les balises [...] en
si ça correspond aux classes prédéfinies let baliseWords = [ 'labeur', 'free', 'temps', 'moment', 'pilote', 'free_left', 'citation', 'latour', 'latour_nohead', 'lampe', 'lampe_nohead', 'bibliographie', 'imgsmall', 'imgsmallsmall', 'imgsmall_bottom', 'fullpage2imgs', 'fullpageimage', 'tripleimgs', 'tripleimgs_bottom', 'tripleimgs2', 'tripleimgs2_bottom', 'bottomimg', 'imgfullspreadleft', 'imgfullspreadright', 'imgfullspreadright_bleedtop', 'imgfullspreadright_bleed', 'breakbefore', 'breakafter', `doublepage_bigright`, `doublepage_bigleft` ]; var bodyContent = $('#body').html(); bodyContent = bodyContent.replace(/\[([^\/\]]+)\]/g, function(match, word) { if (baliseWords.includes(word)) { return '
'; } else { return match; } }).replace(/\[\/([^\]]+)\]/g, function(match, word) { if (baliseWords.includes(word)) { return '
'; } else { return match; } }); $('#body').empty().append(bodyContent); // isoler les chiffres des titres let moments = document.getElementsByClassName("moment"); for(let i = 0; i < moments.length; i++) { moments[i].innerHTML = "" + moments[i].innerHTML.substring(0, moments[i].innerHTML.indexOf('—')) + "" + moments[i].innerHTML.slice(moments[i].innerHTML.indexOf(' —')); } // cleaner le balisage des éléments contenant plusieurs paragraphes let contentToParse = []; let labeurs = document.querySelectorAll('.labeur, .free'); for(let labeur of labeurs) { contentToParse.push(labeur); } // créer header icons pour encarts let encarts = document.querySelectorAll('.latour, .latour_nohead, .lampe, .lampe_nohead'); for(let encart of encarts) { encart.innerHTML = encart.innerHTML.replaceAll(' :', ' :'); encart.innerHTML = encart.innerHTML.replaceAll(' ?', ' ?'); encart.innerHTML = encart.innerHTML.replaceAll(' !', ' !'); encart.innerHTML = encart.innerHTML.replaceAll('« ', '« '); encart.innerHTML = encart.innerHTML.replaceAll(' »', ' »'); encart.innerHTML = encart.innerHTML.replaceAll('(« ', '(« '); encart.innerHTML = encart.innerHTML.replaceAll(' »)', ' »)'); encart.innerHTML = encart.innerHTML.replaceAll('“', '« '); encart.innerHTML = encart.innerHTML.replaceAll('”', ' »'); encart.innerHTML = encart.innerHTML.replaceAll(' min', ' min'); let headContent = encart.firstChild let headerEl = document.createElement('div'); headerEl.setAttribute('class', 'encart-header') let iconImg = document.createElement('img'); if (encart.classList.contains('latour') || encart.classList.contains('latour_nohead')) { iconImg.setAttribute('src', '/user/themes/carnet-atterrissage/assets/map.png'); } else if (encart.classList.contains('lampe') || encart.classList.contains('lampe_nohead')) { iconImg.setAttribute('src', '/user/themes/carnet-atterrissage/assets/lampe.png'); } if (encart.classList.contains('latour_nohead') || encart.classList.contains('lampe_nohead')) { headerEl.style.flexDirection = 'column'; headerEl.style.alignItems = 'flex-start'; headerEl.style.fontWeight = 'normal'; iconImg.style.marginBottom = '2mm'; encart.style.paddingTop = '5mm'; encart.style.paddingBottom = '5mm'; iconImg.style.margin = '0'; iconImg.style.marginBottom = '2.5mm'; } headerEl.append(iconImg); headerEl.append(headContent); encart.firstChild?.remove(); encart.prepend(headerEl); if (encart.querySelector('.encart-header').nextElementSibling == null) { encart.querySelector('.encart-header').style.marginBottom = '0'; } /* console.log(encart.nextElementSibling); if (encart.nextElementSibling?.classList.contains('moment')) { console.log('BAAAAAAAAH'); encart.style.color = 'red'; } */} // clean bibliographie let bibliographies = document.querySelectorAll('.bibliographie'); for (let bibliographie of bibliographies) { contentToParse.push(bibliographie); if (bibliographie.nextElementSibling.innerText === "") { bibliographie.nextElementSibling.remove(); } } for(let i = 0; i < contentToParse.length; i++) { if (contentToParse[i].childNodes.length == 1) { contentToParse[i].innerHTML = '

' + contentToParse[i].innerHTML + '

'; } else { contentToParse[i].innerHTML = "

" + contentToParse[i].innerHTML.replace("

", ""); } // micro-typo for(j = 0; j < contentToParse[i].childNodes.length; j++) { let contentHTML = contentToParse[i].childNodes[j].innerHTML; if (contentHTML != undefined) { contentToParse[i].childNodes[j].innerHTML = contentToParse[i].childNodes[j].innerHTML.replaceAll(' :', ' :'); contentToParse[i].childNodes[j].innerHTML = contentToParse[i].childNodes[j].innerHTML.replaceAll(' ?', ' ?'); contentToParse[i].childNodes[j].innerHTML = contentToParse[i].childNodes[j].innerHTML.replaceAll(' !', ' !'); contentToParse[i].childNodes[j].innerHTML = contentToParse[i].childNodes[j].innerHTML.replaceAll('« ', '« '); contentToParse[i].childNodes[j].innerHTML = contentToParse[i].childNodes[j].innerHTML.replaceAll(' »', ' »'); contentToParse[i].childNodes[j].innerHTML = contentToParse[i].childNodes[j].innerHTML.replaceAll('(« ', '(« '); contentToParse[i].childNodes[j].innerHTML = contentToParse[i].childNodes[j].innerHTML.replaceAll(' »)', ' »)'); contentToParse[i].childNodes[j].innerHTML = contentToParse[i].childNodes[j].innerHTML.replaceAll('“', '« '); contentToParse[i].childNodes[j].innerHTML = contentToParse[i].childNodes[j].innerHTML.replaceAll('”', ' »'); contentToParse[i].childNodes[j].innerHTML = contentToParse[i].childNodes[j].innerHTML.replaceAll(' min', ' min'); } } // data align last split if (contentToParse[i].innerHTML.includes('
')) { if (contentToParse[i].childElementCount > 0) { for (let j = 0; j < contentToParse[i].childElementCount; j++) { let parts = contentToParse[i].children[j].innerHTML.split('
'); let newParts = parts.map(function(part) { return '

' + part + '

'; }); contentToParse[i].children[j].innerHTML = newParts.join(''); } } else { let parts = contentToParse[i].innerHTML.split('
'); let newParts = parts.map(function(part) { return '

' + part + '

'; }); contentToParse[i].innerHTML = newParts.join(''); } } } // PAGES TITRES let h3s = document.querySelectorAll('h3'); for (let h3 of h3s) { if (/^\d/.test(h3.innerText)) { h3.innerHTML = h3.innerHTML.replace(/[^\s]*/, function(match) { return `
${match}
`; }); } h3.innerHTML = h3.innerHTML.replace(/ \«/g, '
«'); } let dessinsPreH3 = document.querySelectorAll('h3 + p img'); for (let dessin of dessinsPreH3) { dessin.style.width = '0px'; dessin.style.height = '0px'; } // pour les serpentins let h4s = document.querySelectorAll('h4'); for (let h4 of h4s) { if (h4.innerText === "Serpentin") { let serpentin = h4.nextElementSibling.nextElementSibling; serpentin.nextElementSibling.remove(); h4.remove(); } }