diff --git a/static/js/index.js b/static/js/index.js index 54f370c..ca289c4 100755 --- a/static/js/index.js +++ b/static/js/index.js @@ -35,9 +35,12 @@ exports.postAceInit = function(hook, context) { } exports.aceAttribsToClasses = function(hook, context) { - if(context.key == 'url'){ - var url = context.value; - return ['url-' + url ]; + if (context.key === 'url'){ + if (/^ ?url-/.test(context.value)) { + return [context.value]; + } else { + return ['url-' + context.value]; + } } } @@ -83,6 +86,6 @@ function doInsertLink(url) { exports.collectContentPre = function(hook,context) { var url = /(?:^| )url-(\S*)/.exec(context.cls); if(url) { - context.cc.doAttrib(context.state,"url::" + url); + context.cc.doAttrib(context.state,"url::" + url[0]); } } diff --git a/static/tests/frontend/specs/embeddedlinks.js b/static/tests/frontend/specs/embeddedlinks.js index 5e20eb5..2cf3cb8 100644 --- a/static/tests/frontend/specs/embeddedlinks.js +++ b/static/tests/frontend/specs/embeddedlinks.js @@ -156,4 +156,32 @@ describe('ep_embedded_hyperlinks2', function () { secondSpan.classList.contains('b'); }); }); + + it('has correct links after copy and paste', async function() { + // FIXME use clipboard API + const html = '1link, \ +2bold\ +, 3link' + helper.linesDiv()[0].html(html); + await helper.waitForPromise(() => helper.commits.length === 1); + + await helper.waitForPromise(() => { + const lineText = helper.textLines()[0]; + const firstSpan = helper.linesDiv()[0][0].children[0]; + const secondSpan = helper.linesDiv()[0][0].children[1]; + const thirdSpan = helper.linesDiv()[0][0].children[2]; + + return lineText === '1link, 2bold, 3link' && + firstSpan.children[0].getAttribute('href') === 'http://beta.etherpad.com/' && + secondSpan.children[0].getAttribute('href') === 'http://beta.etherpad.com/' && + thirdSpan.children[0].getAttribute('href') === 'http://beta.etherpad.com/' && + firstSpan.classList.contains('url-beta.etherpad.com/') && + !firstSpan.classList.contains('url-') && + secondSpan.classList.contains('url-beta.etherpad.com/') && + !secondSpan.classList.contains('url-') && + thirdSpan.classList.contains('url-beta.etherpad.com/') && + !thirdSpan.classList.contains('url-') && + secondSpan.classList.contains('b'); + }); + }); });