diff --git a/app/modules/components/wysiwyg/wysiwyg-code-hightlighter.service.coffee b/app/modules/components/wysiwyg/wysiwyg-code-hightlighter.service.coffee index b9854a96..06c35b5a 100644 --- a/app/modules/components/wysiwyg/wysiwyg-code-hightlighter.service.coffee +++ b/app/modules/components/wysiwyg/wysiwyg-code-hightlighter.service.coffee @@ -59,17 +59,29 @@ class WysiwygCodeHightlighterService if lan tab.innerText = lan @.updatePositionCodeTab(code.parentElement, tab) + + languageClass = _.find code.classList, (className) -> + return className && className.indexOf('language-') != -1 + + code.classList.remove(languageClass.replace('language-', '')) + code.classList.remove(languageClass) + code.classList.add('language-' + lan) code.classList.add(lan) document.body.appendChild(tab) - code.classList.add(id) code.dataset.tab = tab + + if !code.dataset.tabId + code.dataset.tabId = id + code.classList.add(id) + + tab.dataset.tabId = code.dataset.tabId + tab.classList.add('code-language-selector') # styles tab.classList.add('medium-' + mediumInstance.id) # used to delete - tab.dataset.tabId = id @.updatePositionCodeTab(code.parentElement, tab) @@ -158,10 +170,16 @@ class WysiwygCodeHightlighterService codes.each (index, code) -> code.innerHTML = code.innerText + # firefox adds br instead of new lines inside + replaceCodeBrToNl: (code) -> + $(code).find('br').replaceWith('\n') + addHightlighter: (element) -> codes = $(element).find('code') codes.each (index, code) => + @.replaceCodeBrToNl(code) + lan = @.getLanguageInClassList(code.classList) if lan diff --git a/app/modules/components/wysiwyg/wysiwyg.directive.coffee b/app/modules/components/wysiwyg/wysiwyg.directive.coffee index 25048c00..5568ead1 100644 --- a/app/modules/components/wysiwyg/wysiwyg.directive.coffee +++ b/app/modules/components/wysiwyg/wysiwyg.directive.coffee @@ -30,6 +30,9 @@ Medium = ($translate, $confirm, $storage, wysiwygService, animationFrame, tgLoad isCodeBlockSelected = (range, elm) -> return !!$(range.endContainer).parentsUntil('.editor', 'code').length + refreshCodeBlockHightlight = (elm) -> + wysiwygCodeHightlighterService.refreshCodeLanguageSelectors(elm) + removeCodeBlockAndHightlight = (range, elm) -> code = $(range.endContainer).closest('code')[0] pre = code.parentNode @@ -237,8 +240,16 @@ Medium = ($translate, $confirm, $storage, wysiwygService, animationFrame, tgLoad $scope.cancel() askResponse.finish() + # firefox adds br instead of new lines inside , taiga must replace the br by \n before sending to the server + replaceCodeBrToNl = () -> + html = $('
').html(editorMedium.html()) + html.find('code br').replaceWith('\n') + + return html.html() + updateMarkdownWithCurrentHtml = () -> - $scope.markdown = wysiwygService.getMarkdown(editorMedium.html()) + html = replaceCodeBrToNl() + $scope.markdown = wysiwygService.getMarkdown(html) localSave = (markdown) -> if $scope.storageKey