diff --git a/app/containers/codeArea/highlighting.js b/app/containers/codeArea/highlighting.js
index c68b7780..e2911a08 100644
--- a/app/containers/codeArea/highlighting.js
+++ b/app/containers/codeArea/highlighting.js
@@ -1,5 +1,19 @@
import HighlightJS from 'highlight.js'
+// Highlight.js emits escaped text and spans. Keep each table cell's markup
+// balanced while carrying all active scopes (including nested ones) across lines.
+export function splitHighlightedLines (html) {
+ const openSpans = []
+ return html.split(/\r?\n/).map(line => {
+ const prefix = openSpans.join('')
+ for (const [tag] of line.matchAll(/]*>|<\/span>/g)) {
+ if (tag === '') openSpans.pop()
+ else openSpans.push(tag)
+ }
+ return prefix + line + ''.repeat(openSpans.length)
+ })
+}
+
function shouldUsePhpTemplate (content, language) {
return typeof language === 'string' &&
language.toLowerCase() === 'php' &&
diff --git a/app/containers/codeArea/index.js b/app/containers/codeArea/index.js
index 35289610..d897564f 100644
--- a/app/containers/codeArea/index.js
+++ b/app/containers/codeArea/index.js
@@ -5,7 +5,7 @@ import AsciiDoc from '../../utilities/asciidoc'
import Markdown from '../../utilities/markdown'
import React, { Component } from 'react'
import electronBridge from '../../utilities/electronBridge'
-import { adaptedLanguage, highlightContent } from './highlighting'
+import { adaptedLanguage, highlightContent, splitHighlightedLines } from './highlighting'
import { getHighlightTheme } from '../../utilities/themeManager'
import { t } from '../../utilities/i18n'
@@ -252,22 +252,7 @@ export default class CodeArea extends Component {
let lineNumber = 0
const highlightedContent = highlightContent(content, language)
- /*
- Highlight.js wraps comment blocks inside .
- However, when the multi-line comment block is broken down into different
- table rows, only the first row, which is appended by the tag, is
- highlighted. The following code fixes it by appending to each line
- of the comment block.
- */
- const commentPattern = /
- return "\n