How to disabled wysihtml5 HTML Clean Up in Editor?

前端 未结 2 723
忘了有多久
忘了有多久 2021-02-08 18:39

How to disable HTML Clean Up while in the editor mode? I\'m in a need of allowing css format & inline html in code. The idea is to disable parser and html clean up action wh

2条回答
  •  一向
    一向 (楼主)
    2021-02-08 19:08

    Actually, this is what the parser rules are for.

    You can attach your custom rules to the included var wysihtml5ParserRules before instantiate the editor object or just create your own rules object and give to the editor's constructor.

    For example, to allow the h1 and h3 tag in addition to the tags allowed in the distributed simple example rules, you'd need to set up as follows:

      

    Now, when you enter/paste test into the editor, while you're in the editor mode, and then switch to html view, you'll get <title>test</title>. And when you switch back to editor view, you'll get test again.


    That was the general part.

    Now, in your case, I'm not sure if it's the best idea to work with 121 custom parser rules (the count of HTML tags to handle) or if it wouldn't be better to take the time and dig into the source code to find a more performant solution (doesn't make much sense to tell a parser to actualy just return the input string anyway, right?). Furthermore, you said you want to allow CSS as well. So your custom parser rules will even extend.

    Anyway, as a starting point, feel free to use my custom parser rule set from here: https://github.com/eyecatchup/wysihtml5/blob/master/parser_rules/allow-all-html5.js.

提交回复
热议问题