Is there a way to automatically add a classes to html tags created by 
ckeditor? Specifically I want the links created by ckeditor to have the 
class "tc-tiddlylink" so they has the same formatting as links created in 
tiddlers using tiddlywiki5 syntax.

I was trying without success to add some javascript that would add the 
class to any <a> element without the class. I couldn't figure out how/where 
to save a script along these lines:

// Function to add a class to all <a> tags
function addClassToLinks() {
    document.querySelectorAll('a').forEach(function(link) {
        if (!link.classList.contains('your-custom-class')) {
            link.classList.add('your-custom-class');
        }
    });
}

// Create a new MutationObserver instance
const observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
        if (mutation.type === 'childList') {
            addClassToLinks();
        }
    });
});

// Configuration object for the observer
const config = { childList: true, subtree: true };

// Start observing the document body for DOM mutations
observer.observe(document.body, config);

// Initial application of the class to all links
addClassToLinks();

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/553d2643-5c7d-4cad-9910-f4898aaecf63n%40googlegroups.com.

Reply via email to