From f5856270cc260068258e45fbe135815d949c71f3 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 18 Jul 2018 10:48:54 +0100 Subject: [PATCH] undo removal of stripping
s as it breaks HTML `/me`s
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
---
src/HtmlUtils.js | 27 +++++++++++++++++++
src/Markdown.js | 8 +++---
.../views/rooms/MessageComposerInput.js | 3 +--
3 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/src/HtmlUtils.js b/src/HtmlUtils.js
index e07c6eb72b..b6a2bd0acb 100644
--- a/src/HtmlUtils.js
+++ b/src/HtmlUtils.js
@@ -112,6 +112,33 @@ export function charactersToImageNode(alt, useSvg, ...unicode) {
/>;
}
+export function processHtmlForSending(html: string): string {
+ const contentDiv = document.createElement('div');
+ contentDiv.innerHTML = html;
+
+ if (contentDiv.children.length === 0) {
+ return contentDiv.innerHTML;
+ }
+
+ let contentHTML = "";
+ for (let i=0; i < contentDiv.children.length; i++) {
+ const element = contentDiv.children[i];
+ if (element.tagName.toLowerCase() === 'p') {
+ contentHTML += element.innerHTML;
+ // Don't add a
for the last
+ if (i !== contentDiv.children.length - 1) {
+ contentHTML += '
';
+ }
+ } else {
+ const temp = document.createElement('div');
+ temp.appendChild(element.cloneNode(true));
+ contentHTML += temp.innerHTML;
+ }
+ }
+
+ return contentHTML;
+}
+
/*
* Given an untrusted HTML string, return a React node with an sanitized version
* of that HTML.
diff --git a/src/Markdown.js b/src/Markdown.js
index dc0d5962fd..acfea52100 100644
--- a/src/Markdown.js
+++ b/src/Markdown.js
@@ -111,7 +111,7 @@ export default class Markdown {
// you can nest them.
//
// Let's try sending with