about summary refs log tree commit diff
path: root/app/javascript
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-06-06 20:49:53 +0200
committerGitHub <noreply@github.com>2018-06-06 20:49:53 +0200
commitc75493755f482d0506884b1f7b7b44e5306a4d8b (patch)
treec2584348329651d4312cdec33d08c80ae9ab0bac /app/javascript
parentb7b331ad0dd061b55435265009af51cdeef29fdc (diff)
Preserve newlines in delete & redraft and desktop notifications (#7750)
Fix #7748
Diffstat (limited to 'app/javascript')
-rw-r--r--app/javascript/mastodon/reducers/compose.js7
-rw-r--r--app/javascript/mastodon/utils/html.js3
2 files changed, 5 insertions, 5 deletions
diff --git a/app/javascript/mastodon/reducers/compose.js b/app/javascript/mastodon/reducers/compose.js
index e9f6a4902..8524ddb8e 100644
--- a/app/javascript/mastodon/reducers/compose.js
+++ b/app/javascript/mastodon/reducers/compose.js
@@ -36,6 +36,7 @@ import { REDRAFT } from '../actions/statuses';
 import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable';
 import uuid from '../uuid';
 import { me } from '../initial_state';
+import { unescapeHTML } from '../utils/html';
 
 const initialState = ImmutableMap({
   mounted: 0,
@@ -173,14 +174,14 @@ const hydrate = (state, hydratedState) => {
 
 const domParser = new DOMParser();
 
-const htmlToText = status => {
+const expandMentions = status => {
   const fragment = domParser.parseFromString(status.get('content'), 'text/html').documentElement;
 
   status.get('mentions').forEach(mention => {
     fragment.querySelector(`a[href="${mention.get('url')}"]`).textContent = `@${mention.get('acct')}`;
   });
 
-  return fragment.textContent;
+  return fragment.innerHTML;
 };
 
 export default function compose(state = initialState, action) {
@@ -316,7 +317,7 @@ export default function compose(state = initialState, action) {
       }));
   case REDRAFT:
     return state.withMutations(map => {
-      map.set('text', htmlToText(action.status));
+      map.set('text', unescapeHTML(expandMentions(action.status)));
       map.set('in_reply_to', action.status.get('in_reply_to_id'));
       map.set('privacy', action.status.get('visibility'));
       map.set('media_attachments', action.status.get('media_attachments'));
diff --git a/app/javascript/mastodon/utils/html.js b/app/javascript/mastodon/utils/html.js
index 0b646ce58..5159df9db 100644
--- a/app/javascript/mastodon/utils/html.js
+++ b/app/javascript/mastodon/utils/html.js
@@ -1,6 +1,5 @@
 export const unescapeHTML = (html) => {
   const wrapper = document.createElement('div');
-  html = html.replace(/<br \/>|<br>|\n/g, ' ');
-  wrapper.innerHTML = html;
+  wrapper.innerHTML = html.replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n').replace(/<[^>]*>/g, '');
   return wrapper.textContent;
 };