2 var dom = wysihtml5.dom;
4 function _removeFormat(composer, anchors) {
5 var length = anchors.length,
10 for (; i<length; i++) {
12 codeElement = dom.getParentElement(anchor, { nodeName: "code" });
13 textContent = dom.getTextContent(anchor);
15 // if <a> contains url-like text content, rename it to <code> to prevent re-autolinking
16 // else replace <a> with its childNodes
17 if (textContent.match(dom.autoLink.URL_REG_EXP) && !codeElement) {
18 // <code> element is used to prevent later auto-linking of the content
19 codeElement = dom.renameElement(anchor, "code");
21 dom.replaceWithChildNodes(anchor);
26 wysihtml5.commands.removeLink = {
28 * If selection is a link, it removes the link and wraps it with a <code> element
29 * The <code> element is needed to avoid auto linking
32 * wysihtml5.commands.createLink.exec(composer, "removeLink");
35 exec: function(composer, command) {
36 var anchors = this.state(composer, command);
38 composer.selection.executeAndRestore(function() {
39 _removeFormat(composer, anchors);
44 state: function(composer, command) {
45 return wysihtml5.commands.formatInline.state(composer, command, "A");