medium-editor icon indicating copy to clipboard operation
medium-editor copied to clipboard

main wrapping element

Open mattgi opened this issue 10 years ago • 14 comments

By default, the editor will use <p> tags to contain content and support carriage returns, etc. Alt., the disableReturn option can be used to force plain text, thereby removing all wrapping <p> tags.

I have a requirement to support formatting inside block elements like Headers and Blockquotes, but I need to also support carriage returns and do not want <p> tags to be used.

Standard:

<div class="editor">
  <p>this is the <i>first</i> line</p>
  <p>this is a <b>second</b> line</p>
</div>

Requirement:

<h1 class="editor">
  this is the <i>first</i> line<br />this is a <b>second</b> line
</h1>

Perhaps an option like disableParagraphReturn: true is what I am looking for - where it would use <br>'s instead of <p>'s when set to true.

Another option may be to simply consider the element that has been used for the editor - where it exhibits a behavior without an option being passed (e.g. <div> means that <p> tags will be used; <h1>..<h6>, <blockquote> will use <br>'s).

I will start to investigate how this may be implemented if it is a feature that others may want.

mattgi avatar Jul 01 '14 08:07 mattgi

Just looking further in to semantic HTML guidelines...

When the editor element is a block like a <H1>, using <p> is not permitted and <br> should be used to indicate a line break. This lends itself to suggest that the editor should be aware of the main element and use permissible content within it.

Relevant Links: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content

mattgi avatar Jul 01 '14 21:07 mattgi

I want! I want all p tags and all divs disabled, and only br tags when hitting Return.

thomstark avatar Apr 20 '15 23:04 thomstark

This would also be useful if the containing element were itself a paragraph, e.g.

<p class="editor">
  this is the <i>first</i> line<br />this is a <b>second</b> line
</p>

...which is sort of how I'm using it right now. (It still tries to insert extraneous <p> tags, see https://github.com/yabwe/medium-editor/issues/149#issuecomment-124893705 )

nelsonpecora avatar Jul 22 '15 14:07 nelsonpecora

Very interested on seeing this behavior too.

alvarotrigo avatar Apr 18 '16 14:04 alvarotrigo

Interesting... using display:inline-block forces <br> on enter press. Not a medium-editor issue but a contenteditable one. I found it out here.

Reproduction online

alvarotrigo avatar Apr 21 '16 11:04 alvarotrigo

This behavior is totally different in Firefox. It seems Firefox doesn't even create new p elements in any way.

Firefox requires a block wrapper to create p elements:

<div class="editable">
     <p>
        This is just a demo
   </p>
</div>

alvarotrigo avatar Apr 21 '16 12:04 alvarotrigo

@alvarotrigo Thanks for the tip! And it's not blocking the creation of LI elements (with the code from medium.js demo) if you put a UL/OL around. I needed to be able to edit headers and paragraphs without creating new ones, but also lists and creating new <li> elements in it.

regislutter avatar Apr 27 '16 20:04 regislutter

I am also interested in this feature and would love to see some progress here.

dypsilon avatar Oct 15 '16 10:10 dypsilon

Same. I don't want wrapping of anything, maybe just standard <br> for new lines.

mscreenie avatar Oct 18 '16 20:10 mscreenie

Anyone found a solution for this?

volumetric avatar Mar 29 '17 14:03 volumetric

I also agree that have < br> for new lines by default is better. Generate new < p> for every line break create problems.

skiokko avatar Feb 27 '18 09:02 skiokko

In the medium-editor.js file, around like 6822, or search this and replace that last p tag with blank.

        // Firefox thrown an error when calling 'formatBlock' on an empty editable blockContainer that's not a <div>
        if (MediumEditor.util.isMediumEditorElement(node) && node.children.length === 0 && !MediumEditor.util.isBlockContainer(node)) {
            this.options.ownerDocument.execCommand('formatBlock', false, 'p');
        }

ghost avatar Jun 02 '18 06:06 ghost

Thanks ghost, apparently firefox fixed it: https://github.com/yabwe/medium-editor/issues/994

alvarotrigo avatar Apr 29 '20 23:04 alvarotrigo

Any updates on this ? How do you get brs instead of ps ?

DavidGeismarLtd avatar Feb 05 '22 06:02 DavidGeismarLtd