我使用了 wysihtml5 bootstrap 提供的标准解析器,只是链接没有提供正确的 href 属性。我如何使用他们给你的解析器来改变它。
使用脚本...
<link rel="stylesheet" type="text/css" href="/css/bootstrap-wysihtml5.css"></link>
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css"></link>
<script src="js/wysihtml5-0.3.0.js"></script>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-wysihtml5.js"></script>
解析器来源:https ://github.com/xing/wysihtml5/blob/master/parser_rules/advanced.js
解析器摘录:
* The following options are available:
*
* - add_class: converts and deletes the given HTML4 attribute (align, clear, ...) via the given method to a css class
* The following methods are implemented in wysihtml5.dom.parse:
* - align_text: converts align attribute values (right/left/center/justify) to their corresponding css class "wysiwyg-text-align-*")
* <p align="center">foo</p> ... becomes ... <p> class="wysiwyg-text-align-center">foo</p>
* - clear_br: converts clear attribute values left/right/all/both to their corresponding css class "wysiwyg-clear-*"
* <br clear="all"> ... becomes ... <br class="wysiwyg-clear-both">
* - align_img: converts align attribute values (right/left) on <img> to their corresponding css class "wysiwyg-float-*"
*
* - remove: removes the element and its content
*
* - rename_tag: renames the element to the given tag
*
* - set_class: adds the given class to the element (note: make sure that the class is in the "classes" white list above)
*
* - set_attributes: sets/overrides the given attributes
*
* - check_attributes: checks the given HTML attribute via the given method
* - url: allows only valid urls (starting with http:// or https://)
* - src: allows something like "/foobar.jpg", "http://google.com", ...
* - href: allows something like "mailto:bert@foo.com", "http://google.com", "/foobar.jpg"
* - alt: strips unwanted characters. if the attribute is not set, then it gets set (to ensure valid and compatible HTML)
* - numbers: ensures that the attribute only contains numeric characters
"a": {
"check_attributes": {
"href": "href"
},
"set_attributes": {
"rel": "nofollow",
"target": "_blank"
}
},
所以基本上我要做的是获取所有的 a 标签并将它们的 href 属性设置为它们的内容。或禁用解析器删除我的 href 属性的倾向。这可能是一个错误吗?