remplace les balises des crochets seulement si ça match une liste de mots
This commit is contained in:
@@ -1,10 +1,51 @@
|
||||
|
||||
// transformer les balises [...] en <div class="...">
|
||||
let bodyContent = $('#body').html()
|
||||
.replace(/\[([^\/\]]+)\]/g, '<div class="$1">')
|
||||
.replace(/\[\/([^\]]+)\]/g, '</div>');
|
||||
// transformer les balises [...] en <div class="..."> si ça correspond aux classes prédéfinies
|
||||
let baliseWords = [
|
||||
'labeur',
|
||||
'free',
|
||||
'temps',
|
||||
'moment',
|
||||
'latour',
|
||||
'lampe',
|
||||
'bibliographie',
|
||||
'imgsmall',
|
||||
'fullpage2imgs',
|
||||
'fullpageimage',
|
||||
'tripleimgs',
|
||||
'tripleimgs_bottom',
|
||||
'tripleimgs2',
|
||||
'tripleimgs2_bottom',
|
||||
'bottomimg',
|
||||
'imgfullspreadleft',
|
||||
'imgfullspreadright',
|
||||
'imgfullspreadright_bleedtop',
|
||||
'imgfullspreadright_bleed',
|
||||
'breakbefore',
|
||||
'breakafter'
|
||||
];
|
||||
|
||||
// Get the HTML content of the "body" element
|
||||
var bodyContent = $('#body').html();
|
||||
|
||||
// Replace text between brackets only if it matches one of the words in the list
|
||||
bodyContent = bodyContent.replace(/\[([^\/\]]+)\]/g, function(match, word) {
|
||||
if (baliseWords.includes(word)) {
|
||||
return '<div class="' + word + '">';
|
||||
} else {
|
||||
return match; // No replacement if the word is not in the list
|
||||
}
|
||||
}).replace(/\[\/([^\]]+)\]/g, function(match, word) {
|
||||
if (baliseWords.includes(word)) {
|
||||
return '</div>';
|
||||
} else {
|
||||
return match; // No replacement if the word is not in the list
|
||||
}
|
||||
});
|
||||
|
||||
// Update the content of the "body" element
|
||||
$('#body').empty().append(bodyContent);
|
||||
|
||||
|
||||
// isoler les chiffres des titres
|
||||
let moments = document.getElementsByClassName("moment");
|
||||
|
||||
@@ -32,7 +73,7 @@ for(let i = 0; i < latours.length; i++) {
|
||||
headerEl.append(iconImg);
|
||||
headerEl.append(headContent);
|
||||
|
||||
latours[i].firstChild.remove();
|
||||
latours[i].firstChild?.remove();
|
||||
latours[i].prepend(headerEl);
|
||||
}
|
||||
|
||||
@@ -48,7 +89,7 @@ for(let i = 0; i < lampes.length; i++) {
|
||||
headerEl.append(iconImg);
|
||||
headerEl.append(headContent);
|
||||
|
||||
lampes[i].firstChild.remove();
|
||||
lampes[i].firstChild?.remove();
|
||||
lampes[i].prepend(headerEl);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user