有没有办法让wysithtml5'的链接编辑器允许用户向href标记添加他们喜欢的任何内容
Is there a way to let wysithtml5's link editor let the user add anything they like to the href tag?
我使用的是wysithtml5编辑器,但用户报告在添加链接时遇到了很多问题。用户希望将他们想要的任何内容添加到href属性中。然而,当点击"确定"添加链接时,它会通过某种方式回调修改后的链接。
例如,用户想要添加一个锚标签:
#moo
将要输入的链接是后面跟着ancors的文档url,所以它最终会看起来像这样:
http://stackoverflow.com/#moo
如果他们试图添加液体标签,也会发生同样的情况,例如:
{{name}}
变成…
http://stackoverflow.com/84748/%7B%7Bname%7D%7D
是否有修改wysithtml5的方法,使其不经过修改href属性的回调?我尝试过从语法分析器规则中删除/修改checkAttributes,但没有效果。还有其他东西在处理href。
谢谢!
wysihtml5没有显式执行此转换。这是它为表示锚标记而创建的DOM对象的奇怪行为的结果。基本上,anchor.href
和anchor.getAttribute('href')
不一定返回相同的东西。
下面是一个可以在Javascript控制台上执行的示例:
var anchor = document.createElement('a');
anchor.setAttribute('href', '#foo');
console.log(anchor.href); //prints anchor.baseURI + '#foo'
console.log(anchor.getAttribute('href')); //prints '#foo'
无论如何,我认为这是wysihtml5中的一个错误。据我所知,你只需要更改源代码中的两行就可以修复它。请参阅我在Github上的fork:https://github.com/b3nj4m/wysihtml5/commit/c14d746b2b192b043673d97f79f3f61c23908f8d
编辑:关于在原始html->composer视图转换过程中剥离的href
属性,这是由于解析器规则。我认为处理此问题的最佳方法是添加一个新规则,如not_empty
,并将其用于href
。
例如
"a": {
"check_attributes": {
"href": "url"
},
//...
}
成为
"a": {
"check_attributes": {
"href": "not_empty"
},
//...
}
然后在src/dom/parse.js
中添加not_empty
规则
var attributeCheckMethods = {
not_empty: function(attributeValue) {
return attributeValue || null;
},
//...
};
请在此处查看对src/dom/parse.js
的更改:https://github.com/b3nj4m/wysihtml5/commit/0ef0dad5f0457266057d7e14df42dafe987bdb69#L2R374
- 在单击href链接的同时下载文件
- 从远程脚本获取用户IP
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- d3基于用户选择动态更新节点
- 名称href标签根据用户文本输入JavaScript
- 当用户在选择框中选择选项时,使用window.location.href重定向用户只会更改导航器中URL的最后一位
- 如果用户已登录,则隐藏 href 链接
- 如何根据用户选择的选项更改链接 href(单击)
- 将href更改为电话号码(用户定义)
- 有没有办法让wysithtml5'的链接编辑器允许用户向href标记添加他们喜欢的任何内容
- 如何用Javascript调用PHP页面;当用户单击href链接时进行jQuery
- 如何让用户尝试复制URL以外的URL而不是HREF值
- 选定href用户的Cookie复选框
- 当用户单击禁用的href链接时,如何关注文本字段
- Javascript代码将锚链接的href更改为用户在输入框中输入的内容
- href/button单击将否决下一步,并在不等待用户输入的情况下执行操作
- 当用户单击链接时更改href
- 在<a>在将用户带到href位置之前单击
- 如何通过移动用户的 href 链接模拟 javascript onClick 事件
- 如何调用'点击'当用户点击href