Markdown plugin - no way to prevent output trimming
📝 Provide detailed reproduction steps (if any)
Apologies if this should be a feature request instead of a bug - I wasn't sure if this was expected behavior or not.
It seems that the trim option for the getData method does not work for editors using the Markdown plugin. Opting out of trimming the output still does not respect spaces / newlines in otherwise empty output.
JSFiddle: https://jsfiddle.net/kstinson/egnLhsrz/
Each editor outputs its getData result in the console. You can see the HTML whitespace editor outputs content when only spaces/ newlines are present in the editor, but the Markdown whitespace editor does not.
✔️ Expected result
I would expect this option to work in the Markdown editor
❌ Actual result
The output is still trimmed
If you'd like to see this fixed sooner, add a 👍 reaction to this post.
Hi, thanks for the request.
does not respect spaces / newlines in otherwise empty output.
Hmm, I think it might be related to the behavior of Markdown itself, we most likely return proper HTML but Markdown has its logic of content and white spaces, and the processor skips them anyway, see more in: https://github.com/ckeditor/ckeditor5/issues/14038#issuecomment-1539609348
A workaround could be to configure keepHtml with br for example or the registerRawContentMatcher.
Hello,
I did not success to use the workaround. Could you give me an example?
I share my tries with [email protected] and @ckeditor/[email protected]
import { Heading, Markdown, Plugin, type Editor } from 'ckeditor5';
export class CustomPlugin extends Plugin {
constructor( editor: Editor ) {
super( editor );
editor.data.processor.registerRawContentMatcher({ name: 'br' });
}
static get requires() {
return [ Markdown, Heading ];
}
}
import type GFMDataProcessor from '@ckeditor/ckeditor5-markdown-gfm/src/gfmdataprocessor';
import { Heading, Markdown, Plugin, type Editor } from 'ckeditor5';
export class CustomPlugin extends Plugin {
constructor( editor: Editor ) {
super( editor );
(editor.data.processor as GFMDataProcessor).keepHtml('br');
}
static get requires() {
return [ Markdown, Heading ];
}
}
When I type twice Shift+Enter, I see <br><br> in the editor but it is transformed to \n\n by the GFMDataProcessor.toData method. Then, on set data editor method call, this last value (\n\n) is transformed to a p HTML tag.
I don't see any changes in the behaviour with or without the call of keepHtml or registerRawContentMatcher.
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.