From 8fe5ea70b1f233d4b7b7a3bf967969ed128669e8 Mon Sep 17 00:00:00 2001 From: Juanfran Date: Wed, 22 Mar 2017 10:37:43 +0100 Subject: [PATCH] search wiki links in the wysiwyg --- .../components/wysiwyg/wysiwyg.service.coffee | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/modules/components/wysiwyg/wysiwyg.service.coffee b/app/modules/components/wysiwyg/wysiwyg.service.coffee index 218a0fc1..509091c6 100644 --- a/app/modules/components/wysiwyg/wysiwyg.service.coffee +++ b/app/modules/components/wysiwyg/wysiwyg.service.coffee @@ -93,6 +93,23 @@ class WysiwygService return el.innerHTML + searchWikiLinks: (html) -> + el = document.createElement( 'html' ) + el.innerHTML = html + + links = el.querySelectorAll('a') + + for link in links + if link.getAttribute('href').indexOf('/') == -1 + url = @navurls.resolve('project-wiki-page', { + project: @projectService.project.get('slug'), + slug: link.getAttribute('href') + }) + + link.setAttribute('href', url) + + return el.innerHTML + removeTrailingListBr: (text) -> return text.replace(/
  • (.*?)
    <\/li>/g, '
  • $1
  • ') @@ -166,6 +183,8 @@ class WysiwygService md.use(window.markdownitLazyHeaders) result = md.render(text) + result = @.searchWikiLinks(result) + result = @.autoLinkHTML(result) return result