samclarke / SCEditor

A lightweight HTML and BBCode WYSIWYG editor
http://www.sceditor.com/
Other
657 stars 187 forks source link

fromBBCode doesn't support emoticons #719

Open adiantek opened 5 years ago

adiantek commented 5 years ago

Calling sceditor.instance(textarea).fromBBCode("as :) df") returns <div>as :) df</div> instead of HTML code with emoticon.

brunoais commented 5 years ago

By design. See: https://www.sceditor.com/documentation/formats/bbcode/ If you think the design is wrong, ask for a change of the design but I think, due to the inherit current architecture, you cannot do BBCode + emote using such function. It may be possible to make a new one for that, instead.

Doidel commented 5 years ago

What is the suggested way then to load bbcode e.g. from a database and display it? Would it be to load the bbcode into a textarea and create a readonly editor instance? Or is there a seperate "parse emoticons" function?

Doidel commented 5 years ago

Well, this is my hack for now:

Copy/paste emoticons from https://github.com/samclarke/SCEditor/blob/master/src/lib/defaultOptions.js:

var emoticons = { ':)': 'emoticons/smile.png', '8-)': 'emoticons/cool.png', ':\'(': 'emoticons/cwy.png', ... };

function convertEmoticons(text) { $.each(emoticons, function (key, src) { text = text.replace(key, '<img src="/lib/sceditor/' + src + '" title="' + key + '" alt="' + key + '" />') }); return text; }

convertEmoticons(yourSceditorInstance.fromBBCode(bbtext))

brunoais commented 5 years ago

I can't think of any alternatives.....

adiantek commented 5 years ago

I made the pull request to this https://github.com/samclarke/SCEditor/pull/721 It's not a perfect solution, but better than nothing.