// transformer les balises [...] en
si ça correspond aux classes prédéfinies let baliseWords = [ 'labeur', 'free', 'temps', 'moment', 'latour', 'latour_nohead', 'lampe', 'lampe_nohead', 'bibliographie', 'imgsmall', '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'); 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) { contentToParse.push(encart); 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')) { 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'; } } 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(' min', ' min'); } } } // 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}
`; }); } } let dessinsPreH3 = document.querySelectorAll('h3 + p img'); for (let dessin of dessinsPreH3) { dessin.style.width = '0px'; dessin.style.height = '0px'; }