hallo
hallo copied to clipboard
Select Paragraph (<p>) by default
When not in paragraph mode hitting enter inserts empty divs to create spaces in the markdown.
I have the same issue. It happens in chrome (maybe all webkit browsers? In firefox it's ok though.
Oh, and it happens when the editable div is empty as well.
+1. Has anyone worked out how to do this yet?
As far as I can tell this could be done with a plugin like this very basic one:
(function() {
(function(jQuery) {
return jQuery.widget("IKS.hallorequireparagraphs", {
options: {
blockElements: ["p", "h1", "h2", "h3", "h4", "h5"]
},
cleanupContentClone: function(el) {
// if the editable element contains no block-level elements, wrap the whole thing in a P
if(!jQuery(this.options.blockElements.toString(), el).length){
el.wrapInner('<p></p>');
}
}
});
})(jQuery);
}).call(this);
@davecranwell That doesn't seem to work all the time, e.g. if there's some existing content before adding that plugin, and in some other edge cases. The following wraps each text node one by one instead:
jQuery.widget('IKS.hallorequireparagraphs', {
cleanupContentClone: function(el) {
// wrap all immediate text node children in a paragraph
el.contents().each(function(){
if(this.nodeType == 3){
$(this).wrap('<p/>');
}
});
}
});
That isn't actually how I did it eventually: https://github.com/torchbox/wagtail/pull/999/files
That solution may be just as broken though.
Thanks, I didn't see that one. And I've just noticed that my version has some weird issues too: sometimes it starts adding a new paragraph after each keystroke.