mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-10-01 17:31:13 +00:00
Remove line breaks after embedded media
This commit is contained in:
parent
f0d1b8f777
commit
025255af67
@ -39,7 +39,7 @@ import { useMediaContext } from '../../contexts/MediaContext';
|
|||||||
import { hookForDev } from '../../lib/devTools';
|
import { hookForDev } from '../../lib/devTools';
|
||||||
import { getMediaUrl as getMediaUrlDefault } from "../../lib/media";
|
import { getMediaUrl as getMediaUrlDefault } from "../../lib/media";
|
||||||
import NoteImage from '../NoteImage/NoteImage';
|
import NoteImage from '../NoteImage/NoteImage';
|
||||||
import { createStore } from 'solid-js/store';
|
import { createStore, unwrap } from 'solid-js/store';
|
||||||
import { linebreakRegex, shortMentionInWords, shortNoteWords, specialCharsRegex, urlExtractRegex } from '../../constants';
|
import { linebreakRegex, shortMentionInWords, shortNoteWords, specialCharsRegex, urlExtractRegex } from '../../constants';
|
||||||
import { useIntl } from '@cookbook/solid-intl';
|
import { useIntl } from '@cookbook/solid-intl';
|
||||||
import { actions } from '../../translations';
|
import { actions } from '../../translations';
|
||||||
@ -218,19 +218,28 @@ const ParsedNote: Component<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
let lastSignificantContent = 'text';
|
let lastSignificantContent = 'text';
|
||||||
|
let isAfterEmbed = false;
|
||||||
|
|
||||||
const parseToken = (token: string) => {
|
const parseToken = (token: string) => {
|
||||||
if (token === '__LB__') {
|
if (token === '__LB__') {
|
||||||
lastSignificantContent !== 'image' && updateContent(content, 'linebreak', token);
|
if (isAfterEmbed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateContent(content, 'linebreak', token);
|
||||||
lastSignificantContent = 'LB';
|
lastSignificantContent = 'LB';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token === '__SP__') {
|
if (token === '__SP__') {
|
||||||
!['image', 'LB'].includes(lastSignificantContent) && updateContent(content, 'text', ' ');
|
if (!['image', 'video', 'link', 'LB'].includes(lastSignificantContent)) {
|
||||||
|
updateContent(content, 'text', ' ');
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isAfterEmbed = false;
|
||||||
|
|
||||||
if (isInterpunction(token)) {
|
if (isInterpunction(token)) {
|
||||||
lastSignificantContent = 'text';
|
lastSignificantContent = 'text';
|
||||||
updateContent(content, 'text', token);
|
updateContent(content, 'text', token);
|
||||||
@ -260,78 +269,70 @@ const ParsedNote: Component<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!props.ignoreMedia) {
|
if (!props.ignoreMedia) {
|
||||||
|
removeLinebreaks();
|
||||||
|
isAfterEmbed = true;
|
||||||
|
|
||||||
if (isImage(token)) {
|
if (isImage(token)) {
|
||||||
removeLinebreaks();
|
|
||||||
lastSignificantContent = 'image';
|
lastSignificantContent = 'image';
|
||||||
updateContent(content, 'image', token);
|
updateContent(content, 'image', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMp4Video(token)) {
|
if (isMp4Video(token)) {
|
||||||
removeLinebreaks();
|
|
||||||
lastSignificantContent = 'video';
|
lastSignificantContent = 'video';
|
||||||
updateContent(content, 'video', token, { videoType: 'video/mp4'});
|
updateContent(content, 'video', token, { videoType: 'video/mp4'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOggVideo(token)) {
|
if (isOggVideo(token)) {
|
||||||
removeLinebreaks();
|
|
||||||
lastSignificantContent = 'video';
|
lastSignificantContent = 'video';
|
||||||
updateContent(content, 'video', token, { videoType: 'video/ogg'});
|
updateContent(content, 'video', token, { videoType: 'video/ogg'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isWebmVideo(token)) {
|
if (isWebmVideo(token)) {
|
||||||
removeLinebreaks();
|
|
||||||
lastSignificantContent = 'video';
|
lastSignificantContent = 'video';
|
||||||
updateContent(content, 'video', token, { videoType: 'video/webm'});
|
updateContent(content, 'video', token, { videoType: 'video/webm'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isYouTube(token)) {
|
if (isYouTube(token)) {
|
||||||
removeLinebreaks();
|
|
||||||
lastSignificantContent = 'youtube';
|
lastSignificantContent = 'youtube';
|
||||||
updateContent(content, 'youtube', token);
|
updateContent(content, 'youtube', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSpotify(token)) {
|
if (isSpotify(token)) {
|
||||||
removeLinebreaks();
|
|
||||||
lastSignificantContent = 'spotify';
|
lastSignificantContent = 'spotify';
|
||||||
updateContent(content, 'spotify', token);
|
updateContent(content, 'spotify', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTwitch(token)) {
|
if (isTwitch(token)) {
|
||||||
removeLinebreaks();
|
|
||||||
lastSignificantContent = 'twitch';
|
lastSignificantContent = 'twitch';
|
||||||
updateContent(content, 'twitch', token);
|
updateContent(content, 'twitch', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMixCloud(token)) {
|
if (isMixCloud(token)) {
|
||||||
removeLinebreaks();
|
|
||||||
lastSignificantContent = 'mixcloud';
|
lastSignificantContent = 'mixcloud';
|
||||||
updateContent(content, 'mixcloud', token);
|
updateContent(content, 'mixcloud', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSoundCloud(token)) {
|
if (isSoundCloud(token)) {
|
||||||
removeLinebreaks();
|
|
||||||
lastSignificantContent = 'soundcloud';
|
lastSignificantContent = 'soundcloud';
|
||||||
updateContent(content, 'soundcloud', token);
|
updateContent(content, 'soundcloud', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAppleMusic(token)) {
|
if (isAppleMusic(token)) {
|
||||||
removeLinebreaks();
|
|
||||||
lastSignificantContent = 'applemusic';
|
lastSignificantContent = 'applemusic';
|
||||||
updateContent(content, 'applemusic', token);
|
updateContent(content, 'applemusic', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isWavelake(token)) {
|
if (isWavelake(token)) {
|
||||||
removeLinebreaks();
|
|
||||||
lastSignificantContent = 'wavelake';
|
lastSignificantContent = 'wavelake';
|
||||||
updateContent(content, 'wavelake', token);
|
updateContent(content, 'wavelake', token);
|
||||||
return;
|
return;
|
||||||
@ -345,7 +346,9 @@ const ParsedNote: Component<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeLinebreaks();
|
removeLinebreaks();
|
||||||
|
isAfterEmbed = true;
|
||||||
lastSignificantContent = 'link';
|
lastSignificantContent = 'link';
|
||||||
|
|
||||||
updateContent(content, 'link', token);
|
updateContent(content, 'link', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -353,6 +356,7 @@ const ParsedNote: Component<{
|
|||||||
if (isNoteMention(token)) {
|
if (isNoteMention(token)) {
|
||||||
removeLinebreaks();
|
removeLinebreaks();
|
||||||
lastSignificantContent = 'notemention';
|
lastSignificantContent = 'notemention';
|
||||||
|
isAfterEmbed = true;
|
||||||
updateContent(content, 'notemention', token);
|
updateContent(content, 'notemention', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user