mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
Preserve newlines in delete & redraft and desktop notifications (#7750)
Fix #7748
This commit is contained in:
parent
b7b331ad0d
commit
c75493755f
@ -36,6 +36,7 @@ import { REDRAFT } from '../actions/statuses';
|
|||||||
import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable';
|
import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable';
|
||||||
import uuid from '../uuid';
|
import uuid from '../uuid';
|
||||||
import { me } from '../initial_state';
|
import { me } from '../initial_state';
|
||||||
|
import { unescapeHTML } from '../utils/html';
|
||||||
|
|
||||||
const initialState = ImmutableMap({
|
const initialState = ImmutableMap({
|
||||||
mounted: 0,
|
mounted: 0,
|
||||||
@ -173,14 +174,14 @@ const hydrate = (state, hydratedState) => {
|
|||||||
|
|
||||||
const domParser = new DOMParser();
|
const domParser = new DOMParser();
|
||||||
|
|
||||||
const htmlToText = status => {
|
const expandMentions = status => {
|
||||||
const fragment = domParser.parseFromString(status.get('content'), 'text/html').documentElement;
|
const fragment = domParser.parseFromString(status.get('content'), 'text/html').documentElement;
|
||||||
|
|
||||||
status.get('mentions').forEach(mention => {
|
status.get('mentions').forEach(mention => {
|
||||||
fragment.querySelector(`a[href="${mention.get('url')}"]`).textContent = `@${mention.get('acct')}`;
|
fragment.querySelector(`a[href="${mention.get('url')}"]`).textContent = `@${mention.get('acct')}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
return fragment.textContent;
|
return fragment.innerHTML;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function compose(state = initialState, action) {
|
export default function compose(state = initialState, action) {
|
||||||
@ -316,7 +317,7 @@ export default function compose(state = initialState, action) {
|
|||||||
}));
|
}));
|
||||||
case REDRAFT:
|
case REDRAFT:
|
||||||
return state.withMutations(map => {
|
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('in_reply_to', action.status.get('in_reply_to_id'));
|
||||||
map.set('privacy', action.status.get('visibility'));
|
map.set('privacy', action.status.get('visibility'));
|
||||||
map.set('media_attachments', action.status.get('media_attachments'));
|
map.set('media_attachments', action.status.get('media_attachments'));
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
export const unescapeHTML = (html) => {
|
export const unescapeHTML = (html) => {
|
||||||
const wrapper = document.createElement('div');
|
const wrapper = document.createElement('div');
|
||||||
html = html.replace(/<br \/>|<br>|\n/g, ' ');
|
wrapper.innerHTML = html.replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n').replace(/<[^>]*>/g, '');
|
||||||
wrapper.innerHTML = html;
|
|
||||||
return wrapper.textContent;
|
return wrapper.textContent;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user