GithubHelp home page GithubHelp logo

Comments (1)

matbk49751 avatar matbk49751 commented on September 23, 2024

I tried the below. My tests worked in the console, but I'm still not seeing it work in Ckeditor5 Source Editing Mode.

init() {
		const editor = this.editor;

		editor.on('ready', () => {

			const SourceEditing = editor.plugins.get('SourceEditing');
			console.log(SourceEditing);

			if(SourceEditing) {
				console.log('SourceEditing plugin found!');
				SourceEditing.formatHtml = (input) => {
					console.log('Custom html format found!');
					// const elementNamesToFormat = 'div|p|span|a|img';
					const elementsToFormat = [
						{ name: 'address', isVoid: false },
						{ name: 'article', isVoid: false },
						{ name: 'aside', isVoid: false },
						{ name: 'blockquote', isVoid: false },
						{ name: 'details', isVoid: false },
						{ name: 'dialog', isVoid: false },
						{ name: 'dd', isVoid: false },
						{ name: 'div', isVoid: false },
						{ name: 'dl', isVoid: false },
						{ name: 'dt', isVoid: false },
						{ name: 'fieldset', isVoid: false },
						{ name: 'figcaption', isVoid: false },
						{ name: 'figure', isVoid: false },
						{ name: 'footer', isVoid: false },
						{ name: 'form', isVoid: false },
						{ name: 'h1', isVoid: false },
						{ name: 'h2', isVoid: false },
						{ name: 'h3', isVoid: false },
						{ name: 'h4', isVoid: false },
						{ name: 'h5', isVoid: false },
						{ name: 'h6', isVoid: false },
						{ name: 'header', isVoid: false },
						{ name: 'hgroup', isVoid: false },
						{ name: 'hr', isVoid: false },
						{ name: 'li', isVoid: false },
						{ name: 'main', isVoid: false },
						{ name: 'nav', isVoid: false },
						{ name: 'ol', isVoid: false },
						{ name: 'p', isVoid: false },
						{ name: 'section', isVoid: false },
						{ name: 'table', isVoid: false },
						{ name: 'tbody', isVoid: false },
						{ name: 'td', isVoid: false },
						{ name: 'th', isVoid: false },
						{ name: 'thead', isVoid: false },
						{ name: 'tr', isVoid: false },
						{ name: 'ul', isVoid: false }
					];
					const elementNamesToFormat = elementsToFormat.map(element => element.name).join('|');
					
					const formatted = input.replace(/\n\s*/g, '').replace(/\s{2,}/g, '');
		
					return formatted.replace(new RegExp(`</?(${elementNamesToFormat})( .*?)?>`, 'g'), '$&');
				};

				const testString = 'Hello\nWorld!\nThis\nis\nmy\nstring';
				console.log('Before formatting:', testString);
				const formatted = SourceEditing.formatHtml(testString);
				console.log('After formatting:', formatted);
			} else {
				console.log('SourceEditing plugin not found');
			}
		});
	}

from ckeditor5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.