SCEditor icon indicating copy to clipboard operation
SCEditor copied to clipboard

editor.insert starts unrequired new paragraph

Open TillCity opened this issue 4 years ago • 0 comments

I am using SCEditor in a webapp used by authors to create travel guides. One of the features I want to put in is to allow the author to cross reference their guides - i.e. link to one of their other guides from the current one. The individual guides are identified via their unique identifier, referred to as einzig in my code. By dint of much trial and error - and reading other threads here - I have managed to get things (mostly)

Here is my code

sceditor.formats.bbcode.set('guide', { tags:{a:{'data-einzig':null}}, allowedChildren:[], allowEmpty:false, isSelfClosing:false, isInline:true, isHTMLInline:true, format:(e,c)=>{return[guide einzig=${e.dataset.einzig}]${e.innerHTML}[/guide];}, html:(t,a,c) =>{return ``<a class='guideJump' href='${a.einzig}' data-einzig='${a.einzig}'>${c}</a>``;}, });

sceditor.formats.bbcode.set('url',{format:(e,c)=>{return c;}})

function jumpToGuide(e) { const editor = this, tgt = e.target; editor.insert([guide einzig='${tgt.dataset.einzig}']Gudie[/guide]); editor.closeDropDown(true);
e.stopPropagation();
}

where the process of inserting an external guide reference is triggered by the author selecting a guide name from a dropdown in the toolbar (that part of the code not shown here)

Everything works just fine - but for one issue. My call to editor.insert above appears to close the current paragraph, inserts a few <br> tags and new lines for good measure and then starts a new paragarph. Here, for example, is what I get

<p>Betty bought a bit <br /></p>\n<p><a class='guideJump' href='KJQiZBVvqOuC' data-einzig='KJQiZBVvqOuC'>Gudie</a> of butter but the bit of butter was bitter<br /><br /></p>\n

Why is this happening and how can I prevent it? That apart what is with all those unrequired break tags and newline characters?

TillCity avatar Mar 01 '22 14:03 TillCity