Manually implementing default font does not update getData()
I am trying to manually implement default fonts, since there is no straightforward way to do so. I cannot edit the p tag CSS to be a certain font as I want to keep previous text the same, only new text should be defaulted.
For example, I have code like this:
editor.model.document.on('change:data', event => {
if (element.firstChild.nodeName === 'BR') {
element.setAttribute('style', 'font-family:Helvetica;font-size:24px');
}
})
In the editor and the DOM, this works. However, when I call editor.getData(), the font family and font size are not there. I believe its because the model or view strips out the attributes. I am not sure how I would make it so the attributes stay in the model/view and updates getData as well.
I have tried upcasting and downcasting, but was not able to get it to work. I'm not sure I am doing it right or if its actually needed. I tried using the writer and classes too, but didnt see the changes in getData() or when I opened the Inspector
editor.conversion.for('upcast').attributeToAttribute({
view: {
key: 'font-family'
},
model: {
key: 'fontFamily',
value: true,
},
});
editor.conversion.for('downcast').attributeToAttribute( {
model: 'font-family',
view: {
key: 'style',
value: viewWriter => (attributeValue, viewElement) => {
viewWriter.setStyle('font-family', attributeValue, viewElement);
},
},
});
How would I go about making getData reflect my changes in the UI/DOM? Please and thank you
- Browser: Chrome
- OS: Mac
- CKEditor version: 34
- Installed CKEditor plugins: Font (font family and font size)
Hi! Do you use the Font plugin? When you have the font family configured, you will get it in the getData in the inline span element. Or do you have some different use case?
There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may still be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.
We've closed your issue due to inactivity. We understand that the issue may still be relevant. If so, feel free to open a new one (and link this issue to it).