centaur54dev / ckeditor5-custom-element Goto Github PK
View Code? Open in Web Editor NEWInsert custom elements (html tags) in ckeditor5
Insert custom elements (html tags) in ckeditor5
Hi,
I'm working on an Angular project in which I need to implement a html-text-editor. I'm using the CKEditor. I've created a custom build so I can use your plugin in my project. Everything works fine until I try to add the property 'attributes' to my custom tag. This gives the following error in my console:
ckeditor-ckeditor5-angular.js:326 ReferenceError: attributeToAttribute is not defined
at Zg.init (ckeditor.js:5)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:150)
at zone.js:889
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
at drainMicroTaskQueue (zone.js:601)
My CustomElement implementation is like this:
ClassicEditor.defaultConfig = {
toolbar: {
items: [
'custom-element-tagname1'
]
},
CustomElement:{
items:[
{tag: 'tagname1', placeholder: 'some text', attributes:{name:'foo'}, inline:true, editable:false}
]
},
}
Originally posted by @novayadi85 in #10 (comment)
I have another problem, how to check if the element is still exsist?
Now even if using toolbar, every click the toolbar that always create new element.
I have created an element:
CustomElement:{
items:[
{tag: 'div', placeholder: 'placeholder text',
attributes:{class: 'bg-light' },
inline:true, editable:false},
]
},
The class bg-light
is simply to test with a background color.
All works when inserting and when I save the first time. However, when I want to edit again, my element is removed and in return I get:
<p><br data-cke-filler="true"></p>
<p>placeholder text</p>
<p><br data-cke-filler="true"></p>
I have been banging my head on this one. I cannot import an Icon as documented in Typescript, it is not valid code. It seems importing an svg as an object is not supported...
Hello and thanks for the amazing package
im using ckeditor with laravel, and building it with webpack (i know, maybe im kinda masochistic) and im having problem of duplicate packages when configuring my ckeditor.js.
`CKEditorError: ckeditor-duplicated-modules: Some CKEditor 5 modules are duplicated. Read more: https://ckeditor.com/docs/ckeditor5/latest/framework/guides/support/error-codes.html#error-ckeditor-duplicated-modules
at Module.<anonymous> (https://localhost/0.js:97925:9)
at Module../node_modules/ckeditor5-custom-element/node_modules/@ckeditor/ckeditor5-utils/src/version.js (https://localhost/0.js:97929:30)
at __webpack_require__ (https://localhost/js/app.js:64:30)
at Module../node_modules/ckeditor5-custom-element/node_modules/@ckeditor/ckeditor5-utils/src/emittermixin.js (https://localhost/0.js:95406:66)
at __webpack_require__ (https://localhost/js/app.js:64:30)
at Module../node_modules/ckeditor5-custom-element/node_modules/@ckeditor/ckeditor5-utils/src/observablemixin.js (https://localhost/0.js:96739:71)
at __webpack_require__ (https://localhost/js/app.js:64:30)
at Module../node_modules/ckeditor5-custom-element/node_modules/@ckeditor/ckeditor5-core/src/plugin.js (https://localhost/0.js:89797:103)
at __webpack_require__ (https://localhost/js/app.js:64:30)
at Module../node_modules/ckeditor5-custom-element/src/customelement.js (https://localhost/0.js:98199:93)`
my ckeditor works if removing the custom plugin, the problem seems related on how node reference the ck-editor libs defined into the plugin.
any insight on this?
At the moment you cannot add attributes to tags.
It is because you wrongly mapped attributes to tags
for (let a=0; a<attrkeys.length; a++){
editor.conversion.for( 'downcast' ).attributeToAttribute( ( {
model: attrkeys[a],
view: attrkeys[a],
converterPriority: 'low'
}));
editor.conversion.for( 'upcast' ).add(attributeToAttribute({
view: attrkeys[a],
model: attrkeys[a],
converterPriority: 'low'
}));
}
In order to make it work, you should change it to
for (let a=0; a<attrkeys.length; a++){
editor.conversion.for( 'downcast' ).attributeToAttribute({
model: attrkeys[a],
view: attrkeys[a],
converterPriority: 'low'
});
editor.conversion.for( 'upcast' ).attributeToAttribute({
view: attrkeys[a],
model: attrkeys[a],
converterPriority: 'low'
});
}
When compiling in my webpack project, I get the error Module not found: Error: Can't resolve 'ckeditor5-custom-element'
I am importing the same as any node_module:
import CustomElementPlugin from 'ckeditor5-custom-element'
I noticed that your package.json points to 'customelement.js' as your main. However, you don't have a top level customelement.js, it's in 'src/customelement.js'. When I manually change your package.json in node_modules to use 'src/customelement.js' for main, I can use your library as normal.
"main": "src/customelement.js",
Hi,
I tried yours, but I dont find any allowed attributes working.
items: [
{
tag: 'tagname1',
placeholder: 'some text',
attributes: {
name:'ABCD',
},
inline: true ,
editable: false
},
.....
and I try to insert text by
var viewFragment = editor.data.processor.toView( content );
var modelFragment = editor.data.toModel( viewFragment );
editor.model.insertContent( modelFragment );
Could you please help me, what is wrong?
Thanks
I'm trying to create a pagebreak element that has an html placeholder with an FA Icon to display nicely to the user. Unfortunately the plugin is designed to always treat the placeholder as unsafe and escape it.
I propose that there be a flag to indicate that the placeholder should be treated as safeHTML.
For reference, this is the output I need to achieve:
<pagebreak><p style="text-align:center">--- <i class="fa fa-file-text-o"></i> ---</p></pagebreak>
This is the config I'm using:
public ckEditorConfig = {
toolbar: [
'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'code', 'alignment', 'custom-element-pagebreak',
'|', 'undo', 'redo',
'|', 'removeFormat'
],
placeholder: 'This is where you type the body of your writing. Use the controls above for formatting.',
CustomElement: {
items: [
{
tag: 'pagebreak',
placeholder: '<p style="text-align:center">--- <i class="fa fa-file-text-o"></i> ---</p>',
inline: false,
}
]
}
};
And this is what I get in the output currently:
<pagebreak><p style="text-align:center">--- <i class="fa fa-file-text-o"></i> ---</p></pagebreak>
I'd propose a boolean for this like safePlaceholder
that defaults to false.
This plugin needs a requirements update in order to be included in the newest release of ckeditor5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.