fix firefox hightlighter break lines
parent
4d88daa6c6
commit
58f20263bb
|
@ -59,17 +59,29 @@ class WysiwygCodeHightlighterService
|
||||||
if lan
|
if lan
|
||||||
tab.innerText = lan
|
tab.innerText = lan
|
||||||
@.updatePositionCodeTab(code.parentElement, tab)
|
@.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('language-' + lan)
|
||||||
code.classList.add(lan)
|
code.classList.add(lan)
|
||||||
|
|
||||||
document.body.appendChild(tab)
|
document.body.appendChild(tab)
|
||||||
|
|
||||||
code.classList.add(id)
|
|
||||||
code.dataset.tab = tab
|
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('code-language-selector') # styles
|
||||||
tab.classList.add('medium-' + mediumInstance.id) # used to delete
|
tab.classList.add('medium-' + mediumInstance.id) # used to delete
|
||||||
tab.dataset.tabId = id
|
|
||||||
|
|
||||||
@.updatePositionCodeTab(code.parentElement, tab)
|
@.updatePositionCodeTab(code.parentElement, tab)
|
||||||
|
|
||||||
|
@ -158,10 +170,16 @@ class WysiwygCodeHightlighterService
|
||||||
codes.each (index, code) ->
|
codes.each (index, code) ->
|
||||||
code.innerHTML = code.innerText
|
code.innerHTML = code.innerText
|
||||||
|
|
||||||
|
# firefox adds br instead of new lines inside <code>
|
||||||
|
replaceCodeBrToNl: (code) ->
|
||||||
|
$(code).find('br').replaceWith('\n')
|
||||||
|
|
||||||
addHightlighter: (element) ->
|
addHightlighter: (element) ->
|
||||||
codes = $(element).find('code')
|
codes = $(element).find('code')
|
||||||
|
|
||||||
codes.each (index, code) =>
|
codes.each (index, code) =>
|
||||||
|
@.replaceCodeBrToNl(code)
|
||||||
|
|
||||||
lan = @.getLanguageInClassList(code.classList)
|
lan = @.getLanguageInClassList(code.classList)
|
||||||
|
|
||||||
if lan
|
if lan
|
||||||
|
|
|
@ -30,6 +30,9 @@ Medium = ($translate, $confirm, $storage, wysiwygService, animationFrame, tgLoad
|
||||||
isCodeBlockSelected = (range, elm) ->
|
isCodeBlockSelected = (range, elm) ->
|
||||||
return !!$(range.endContainer).parentsUntil('.editor', 'code').length
|
return !!$(range.endContainer).parentsUntil('.editor', 'code').length
|
||||||
|
|
||||||
|
refreshCodeBlockHightlight = (elm) ->
|
||||||
|
wysiwygCodeHightlighterService.refreshCodeLanguageSelectors(elm)
|
||||||
|
|
||||||
removeCodeBlockAndHightlight = (range, elm) ->
|
removeCodeBlockAndHightlight = (range, elm) ->
|
||||||
code = $(range.endContainer).closest('code')[0]
|
code = $(range.endContainer).closest('code')[0]
|
||||||
pre = code.parentNode
|
pre = code.parentNode
|
||||||
|
@ -237,8 +240,16 @@ Medium = ($translate, $confirm, $storage, wysiwygService, animationFrame, tgLoad
|
||||||
$scope.cancel()
|
$scope.cancel()
|
||||||
askResponse.finish()
|
askResponse.finish()
|
||||||
|
|
||||||
|
# firefox adds br instead of new lines inside <code>, taiga must replace the br by \n before sending to the server
|
||||||
|
replaceCodeBrToNl = () ->
|
||||||
|
html = $('<div></div>').html(editorMedium.html())
|
||||||
|
html.find('code br').replaceWith('\n')
|
||||||
|
|
||||||
|
return html.html()
|
||||||
|
|
||||||
updateMarkdownWithCurrentHtml = () ->
|
updateMarkdownWithCurrentHtml = () ->
|
||||||
$scope.markdown = wysiwygService.getMarkdown(editorMedium.html())
|
html = replaceCodeBrToNl()
|
||||||
|
$scope.markdown = wysiwygService.getMarkdown(html)
|
||||||
|
|
||||||
localSave = (markdown) ->
|
localSave = (markdown) ->
|
||||||
if $scope.storageKey
|
if $scope.storageKey
|
||||||
|
|
Loading…
Reference in New Issue