[evolution/wip/mcrha/webkit-jsc-api] Use EvoConvert.ToPlainText() to convert content of BLOCKQUOTE elements
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/mcrha/webkit-jsc-api] Use EvoConvert.ToPlainText() to convert content of BLOCKQUOTE elements
- Date: Fri, 13 Mar 2020 14:37:10 +0000 (UTC)
commit a6559c7717e0d683f619caa491753005439f3374
Author: Milan Crha <mcrha redhat com>
Date: Fri Mar 13 15:38:52 2020 +0100
Use EvoConvert.ToPlainText() to convert content of BLOCKQUOTE elements
data/webkit/e-editor.js | 84 ++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 72 insertions(+), 12 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 9ddfea1d37..25f34646f5 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -1742,20 +1742,24 @@ EvoEditor.quoteParagraphWrap = function(node, lineLength, wrapWidth, prefixHtml)
var word = words[ii], wordLen = word.length;
if (lineLength + wordLen > wrapWidth) {
- node.splitText(offset - 1);
- node = node.nextSibling;
+ if (offset > 0) {
+ node.splitText(offset - 1);
+ node = node.nextSibling;
- // erase the space at the end of the line
- node.splitText(1);
- var next = node.nextSibling;
- node.parentElement.removeChild(node);
- node = next;
+ // erase the space at the end of the line
+ node.splitText(1);
+ var next = node.nextSibling;
+ node.parentElement.removeChild(node);
+ node = next;
- var br = document.createElement("BR");
- br.className = "-x-evo-wrap-br";
+ var br = document.createElement("BR");
+ br.className = "-x-evo-wrap-br";
- node.parentElement.insertBefore(br, node);
- br.insertAdjacentHTML("afterend", prefixHtml);
+ node.parentElement.insertBefore(br, node);
+ br.insertAdjacentHTML("afterend", prefixHtml);
+ } else {
+ node.insertAdjacentHTML("beforebegin", prefixHtml);
+ }
offset = 0;
lineLength = 0;
@@ -1802,7 +1806,9 @@ EvoEditor.quoteParagraph = function(paragraph, blockquoteLevel, wrapWidth)
if (node.classList.contains("-x-evo-wrap-br")) {
node.parentElement.removeChild(node);
} else {
- node.insertAdjacentHTML("afterend", prefixHtml);
+ if (node.parentElement.childNodes.length != 1)
+ node.insertAdjacentHTML("afterend", prefixHtml);
+
lineLength = 0;
}
} else if (node.tagName == "A") {
@@ -1825,6 +1831,55 @@ EvoEditor.quoteParagraph = function(paragraph, blockquoteLevel, wrapWidth)
paragraph.insertAdjacentHTML("afterbegin", prefixHtml);
}
+EvoEditor.reBlockquotePlainText = function(plainText)
+{
+ var lines = plainText.replace(/\&/g, "&").split("\n"), ii, html = "", level = 0;
+
+ for (ii = 0; ii < lines.length; ii++) {
+ var line = lines[ii], newLevel = 0, skip = 0;
+
+ // Conversion to Plain Text adds empty line at the end
+ if (ii + 1 >= lines.length && !line[0])
+ break;
+
+ while (line[skip] == '>') {
+ newLevel++;
+ skip++;
+ if (line[skip] == ' ')
+ skip++;
+ }
+
+ while (newLevel > level) {
+ html += "<blockquote type='cite'>";
+ level++;
+ }
+
+ while (newLevel < level) {
+ html += "</blockquote>";
+ level--;
+ }
+
+ html += "<div>";
+
+ while (line[skip] == ' ') {
+ skip++;
+ html += " ";
+ }
+
+ if (skip)
+ line = line.substr(skip);
+
+ html += (line[0] ? line.replace(/</g, "<").replace(/>/g, ">") : "<br>") + "</div>";
+ }
+
+ while (0 < level) {
+ html += "</blockquote>";
+ level--;
+ }
+
+ return html;
+}
+
EvoEditor.convertParagraphs = function(parent, wrapWidth, blockquoteLevel)
{
if (!parent)
@@ -1877,6 +1932,11 @@ EvoEditor.convertParagraphs = function(parent, wrapWidth, blockquoteLevel)
innerWrapWidth = EvoConvert.MIN_PARAGRAPH_WIDTH;
}
+ // replace blockquote content with pure plain text and then re-blockquote it
+ // and do it only on the top level, not recursively (nested citations)
+ if (EvoEditor.mode == EvoEditor.MODE_PLAIN_TEXT && !blockquoteLevel)
+ child.innerHTML =
EvoEditor.reBlockquotePlainText(EvoConvert.ToPlainText(child, -1));
+
EvoEditor.convertParagraphs(child, innerWrapWidth, blockquoteLevel + 1);
} else if (child.tagName == "UL") {
if (wrapWidth == -1) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]