Skip to content

Commit

Permalink
previewAdv.js, add BLACKLIST
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio-Emmolo committed Jul 4, 2024
1 parent 4c000e0 commit 0569c55
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/previewAdv.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ tinymce.PluginManager.add('previewAdv', (editor, url) => {
editor.on('init', function () {
const params = editor.getParam('previewAdv')
const thresholds = params.thresholds
const blacklist = params.blacklist

let pCount = 0 // Counter for <p> tags
let advCount = 1 // Counter for adv divs
Expand Down Expand Up @@ -69,10 +70,12 @@ tinymce.PluginManager.add('previewAdv', (editor, url) => {

// === FUNCTIONS ===
function insertAdv () {
// REMOVE OLD ADV FOR LOAD NEW
const advDivs = editor.getBody().querySelectorAll('.adv-preview')
for (let i = 0; i < advDivs.length; i++) {
advDivs[i].remove()
}

const body = editor.getBody()
const paragraphs = body.getElementsByTagName('p')

Expand All @@ -82,6 +85,30 @@ tinymce.PluginManager.add('previewAdv', (editor, url) => {
continue
}

// === BLACKLIST ===
const bfBlacklist = blacklist.before.slice(1, -1).split('|')
const afBlacklist = blacklist.after.slice(1, -1).split('|')

bfBlacklist.push('<br', '\\[[^\\]]')
afBlacklist.push('<br', '\\[[^\\]]')

// AFTER BEFORE
// if (bfBlacklist.some(item => paragraphs[i].innerHTML.includes(item))) {
// continue
// }
if (bfBlacklist.some(item => new RegExp(item).test(paragraphs[i].innerHTML))) {
continue
}

// AFTER BLACKLIST
// if (afBlacklist.some(item => paragraphs[i + 1].innerHTML.includes(item))) {
// continue
// }
if (afBlacklist.some(item => new RegExp(item).test(paragraphs[i + 1].innerHTML))) {
continue
}
// === END BLACKLIST ===

const div = editor.dom.create('div', { class: 'adv-preview', contenteditable: 'false' })
div.style.backgroundColor = '#f3f3f3'
div.style.color = '#666'
Expand Down

0 comments on commit 0569c55

Please sign in to comment.