Merge branch 'better-still-emoji' into shigusegubu
* better-still-emoji: moved some post styles into status body since they inferfere with usernames fixed some strange error lint renamed StatusText to StatusBody for clarity, fixed chats new component - StatusText, to separate post's text from its attachments some docs, added richcontent to usernames in status, updated stillImage to allow scale of "gif" label lint, fix warnings made getAttrs correctly handle both ' and " mention link more tests move styles to richcontent fix emoji processor not leaving string as-is if no emoji are found lint fix escaped apostrophes [WIP] MUCH better approach to replacing emojis with still versions
This commit is contained in:
commit
6071301b0c
29 changed files with 1152 additions and 430 deletions
4
.babelrc
4
.babelrc
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"presets": ["@babel/preset-env"],
|
"presets": ["@babel/preset-env", "@vue/babel-preset-jsx"],
|
||||||
"plugins": ["@babel/plugin-transform-runtime", "lodash", "@vue/babel-plugin-transform-vue-jsx"],
|
"plugins": ["@babel/plugin-transform-runtime", "lodash"],
|
||||||
"comments": false
|
"comments": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,8 @@
|
||||||
"@babel/preset-env": "^7.7.6",
|
"@babel/preset-env": "^7.7.6",
|
||||||
"@babel/register": "^7.7.4",
|
"@babel/register": "^7.7.4",
|
||||||
"@ungap/event-target": "^0.1.0",
|
"@ungap/event-target": "^0.1.0",
|
||||||
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
|
"@vue/babel-helper-vue-jsx-merge-props": "^1.2.1",
|
||||||
"@vue/babel-plugin-transform-vue-jsx": "^1.1.2",
|
"@vue/babel-preset-jsx": "^1.2.4",
|
||||||
"@vue/test-utils": "^1.0.0-beta.26",
|
"@vue/test-utils": "^1.0.0-beta.26",
|
||||||
"autoprefixer": "^6.4.0",
|
"autoprefixer": "^6.4.0",
|
||||||
"babel-eslint": "^7.0.0",
|
"babel-eslint": "^7.0.0",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { mapState } from 'vuex'
|
import { mapState } from 'vuex'
|
||||||
import StatusContent from '../status_content/status_content.vue'
|
import StatusBody from '../status_content/status_content.vue'
|
||||||
import fileType from 'src/services/file_type/file_type.service'
|
import fileType from 'src/services/file_type/file_type.service'
|
||||||
import UserAvatar from '../user_avatar/user_avatar.vue'
|
import UserAvatar from '../user_avatar/user_avatar.vue'
|
||||||
import AvatarList from '../avatar_list/avatar_list.vue'
|
import AvatarList from '../avatar_list/avatar_list.vue'
|
||||||
|
@ -16,7 +16,7 @@ const ChatListItem = {
|
||||||
AvatarList,
|
AvatarList,
|
||||||
Timeago,
|
Timeago,
|
||||||
ChatTitle,
|
ChatTitle,
|
||||||
StatusContent
|
StatusBody
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState({
|
||||||
|
@ -38,12 +38,15 @@ const ChatListItem = {
|
||||||
},
|
},
|
||||||
messageForStatusContent () {
|
messageForStatusContent () {
|
||||||
const message = this.chat.lastMessage
|
const message = this.chat.lastMessage
|
||||||
|
const messageEmojis = message ? message.emojis : []
|
||||||
const isYou = message && message.account_id === this.currentUser.id
|
const isYou = message && message.account_id === this.currentUser.id
|
||||||
const content = message ? (this.attachmentInfo || message.content) : ''
|
const content = message ? (this.attachmentInfo || message.content_raw) : ''
|
||||||
const messagePreview = isYou ? `<i>${this.$t('chats.you')}</i> ${content}` : content
|
const messagePreview = isYou ? `<i>${this.$t('chats.you')}</i> ${content}` : content
|
||||||
return {
|
return {
|
||||||
summary: '',
|
summary: '',
|
||||||
|
emojis: messageEmojis,
|
||||||
statusnet_html: messagePreview,
|
statusnet_html: messagePreview,
|
||||||
|
raw_html: messagePreview,
|
||||||
text: messagePreview,
|
text: messagePreview,
|
||||||
attachments: []
|
attachments: []
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,18 +77,15 @@
|
||||||
border-radius: var(--avatarAltRadius, $fallback--avatarAltRadius);
|
border-radius: var(--avatarAltRadius, $fallback--avatarAltRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
.StatusContent {
|
.chat-preview-body {
|
||||||
img.emoji {
|
--emoji-size: 1.4em;
|
||||||
width: 1.4em;
|
|
||||||
height: 1.4em;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.time-wrapper {
|
.time-wrapper {
|
||||||
line-height: 1.4em;
|
line-height: 1.4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.single-line {
|
.chat-preview-body {
|
||||||
padding-right: 1em;
|
padding-right: 1em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="chat-preview">
|
<div class="chat-preview">
|
||||||
<StatusContent
|
<StatusBody
|
||||||
|
class="chat-preview-body"
|
||||||
:status="messageForStatusContent"
|
:status="messageForStatusContent"
|
||||||
:single-line="true"
|
:single-line="true"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -57,6 +57,8 @@ const ChatMessage = {
|
||||||
messageForStatusContent () {
|
messageForStatusContent () {
|
||||||
return {
|
return {
|
||||||
summary: '',
|
summary: '',
|
||||||
|
emojis: this.message.emojis,
|
||||||
|
raw_html: this.message.content_raw,
|
||||||
statusnet_html: this.message.content,
|
statusnet_html: this.message.content,
|
||||||
text: this.message.content,
|
text: this.message.content,
|
||||||
attachments: this.message.attachments
|
attachments: this.message.attachments
|
||||||
|
|
|
@ -89,8 +89,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.without-attachment {
|
.without-attachment {
|
||||||
.status-content {
|
.message-content {
|
||||||
&::after {
|
// TODO figure out how to do it properly
|
||||||
|
.text::after {
|
||||||
margin-right: 5.4em;
|
margin-right: 5.4em;
|
||||||
content: " ";
|
content: " ";
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
@ -162,6 +163,7 @@
|
||||||
.visible {
|
.visible {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat-message-date-separator {
|
.chat-message-date-separator {
|
||||||
|
|
|
@ -71,6 +71,7 @@
|
||||||
</Popover>
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
<StatusContent
|
<StatusContent
|
||||||
|
class="message-content"
|
||||||
:status="messageForStatusContent"
|
:status="messageForStatusContent"
|
||||||
:full-content="true"
|
:full-content="true"
|
||||||
>
|
>
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
|
ref="root"
|
||||||
v-click-outside="onClickOutside"
|
v-click-outside="onClickOutside"
|
||||||
class="emoji-input"
|
class="emoji-input"
|
||||||
:class="{ 'with-picker': !hideEmojiButton }"
|
:class="{ 'with-picker': !hideEmojiButton }"
|
||||||
ref='root'
|
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
<template v-if="enableEmojiPicker">
|
<template v-if="enableEmojiPicker">
|
||||||
|
|
71
src/components/mention_link/mention_link.js
Normal file
71
src/components/mention_link/mention_link.js
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
|
||||||
|
import { getTextColor, rgb2hex } from 'src/services/color_convert/color_convert.js'
|
||||||
|
import { mapGetters, mapState } from 'vuex'
|
||||||
|
import { convert } from 'chromatism'
|
||||||
|
|
||||||
|
const MentionLink = {
|
||||||
|
name: 'MentionLink',
|
||||||
|
props: {
|
||||||
|
url: {
|
||||||
|
required: true,
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
required: true,
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
origattrs: {
|
||||||
|
required: true,
|
||||||
|
type: Object
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onClick () {
|
||||||
|
const link = generateProfileLink(this.user.id, this.user.screen_name)
|
||||||
|
this.$router.push(link)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
user () {
|
||||||
|
return this.$store.getters.findUserByUrl(this.url)
|
||||||
|
},
|
||||||
|
isYou () {
|
||||||
|
// FIXME why user !== currentUser???
|
||||||
|
return this.user.screen_name === this.currentUser.screen_name
|
||||||
|
},
|
||||||
|
userName () {
|
||||||
|
return this.userNameFullUi.split('@')[0]
|
||||||
|
},
|
||||||
|
userNameFull () {
|
||||||
|
return this.user.screen_name
|
||||||
|
},
|
||||||
|
userNameFullUi () {
|
||||||
|
return this.user.screen_name_ui
|
||||||
|
},
|
||||||
|
highlight () {
|
||||||
|
return this.mergedConfig.highlight[this.user.screen_name]
|
||||||
|
},
|
||||||
|
bg () {
|
||||||
|
if (this.highlight) return this.highlight.color
|
||||||
|
},
|
||||||
|
text () {
|
||||||
|
if (this.bg) {
|
||||||
|
const linkColor = this.mergedConfig.customTheme.colors.link
|
||||||
|
const color = getTextColor(convert(this.bg).rgb, convert(linkColor).rgb)
|
||||||
|
return rgb2hex(color)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
style () {
|
||||||
|
return [
|
||||||
|
this.bg && `--mention-bg: ${this.bg}`,
|
||||||
|
this.text && `--mention-text: ${this.text}`
|
||||||
|
].filter(_ => _).join('; ')
|
||||||
|
},
|
||||||
|
...mapGetters(['mergedConfig']),
|
||||||
|
...mapState({
|
||||||
|
currentUser: state => state.users.currentUser
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MentionLink
|
49
src/components/mention_link/mention_link.scss
Normal file
49
src/components/mention_link/mention_link.scss
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
.MentionLink {
|
||||||
|
position: relative;
|
||||||
|
white-space: normal;
|
||||||
|
display: inline-block;
|
||||||
|
|
||||||
|
& .new,
|
||||||
|
& .original,
|
||||||
|
& .full {
|
||||||
|
padding: 0 2px;
|
||||||
|
margin: 0 -2px;
|
||||||
|
display: inline-block;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.original {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.full {
|
||||||
|
pointer-events: none;
|
||||||
|
position: absolute;
|
||||||
|
opacity: 0;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
word-wrap: normal;
|
||||||
|
white-space: nowrap;
|
||||||
|
transition: opacity 0.2s ease;
|
||||||
|
background-color: var(--mention-bg, var(--popover));
|
||||||
|
color: var(--mention-text, var(--link));
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.new {
|
||||||
|
background-color: var(--mention-bg);
|
||||||
|
color: var(--mention-text, var(--link));
|
||||||
|
|
||||||
|
&.-you {
|
||||||
|
& .shortName,
|
||||||
|
& .full {
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover .new .full {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
39
src/components/mention_link/mention_link.vue
Normal file
39
src/components/mention_link/mention_link.vue
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<template>
|
||||||
|
<span class="MentionLink">
|
||||||
|
<!-- eslint-disable vue/no-v-html -->
|
||||||
|
<a
|
||||||
|
v-if="!user"
|
||||||
|
href="url"
|
||||||
|
class="original"
|
||||||
|
v-html="content"
|
||||||
|
/>
|
||||||
|
<!-- eslint-enable vue/no-v-html -->
|
||||||
|
<span
|
||||||
|
v-if="user"
|
||||||
|
class="new"
|
||||||
|
:style="style"
|
||||||
|
:class="{ '-you': isYou }"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
class="button-unstyled short"
|
||||||
|
@click.prevent="onClick"
|
||||||
|
>
|
||||||
|
<!-- eslint-disable vue/no-v-html -->
|
||||||
|
<span class="shortName">@<span v-html="userName" /></span> <span v-if="isYou">(You)</span>
|
||||||
|
<!-- eslint-enable vue/no-v-html -->
|
||||||
|
</button>
|
||||||
|
<span
|
||||||
|
v-if="userName !== userNameFull"
|
||||||
|
class="full"
|
||||||
|
>
|
||||||
|
<!-- eslint-disable vue/no-v-html -->
|
||||||
|
@<span v-html="userNameFull" />
|
||||||
|
<!-- eslint-enable vue/no-v-html -->
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script src="./mention_link.js"/>
|
||||||
|
|
||||||
|
<style lang="scss" src="./mention_link.scss"/>
|
93
src/components/rich_content/rich_content.jsx
Normal file
93
src/components/rich_content/rich_content.jsx
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
import Vue from 'vue'
|
||||||
|
import { unescape, flattenDeep } from 'lodash'
|
||||||
|
import { convertHtml, getTagName, processTextForEmoji, getAttrs } from 'src/services/mini_html_converter/mini_html_converter.service.js'
|
||||||
|
import StillImage from 'src/components/still-image/still-image.vue'
|
||||||
|
import MentionLink from 'src/components/mention_link/mention_link.vue'
|
||||||
|
|
||||||
|
import './rich_content.scss'
|
||||||
|
|
||||||
|
export default Vue.component('RichContent', {
|
||||||
|
name: 'RichContent',
|
||||||
|
props: {
|
||||||
|
// Original html content
|
||||||
|
html: {
|
||||||
|
required: true,
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
// Emoji object, as in status.emojis, note the "s" at the end...
|
||||||
|
emoji: {
|
||||||
|
required: true,
|
||||||
|
type: Array
|
||||||
|
},
|
||||||
|
// Whether to handle links or not (posts: yes, everything else: no)
|
||||||
|
handleLinks: {
|
||||||
|
required: false,
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
render (h) {
|
||||||
|
const renderImage = (tag) => {
|
||||||
|
return <StillImage
|
||||||
|
{...{ attrs: getAttrs(tag) }}
|
||||||
|
class="img"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
const renderMention = (attrs, children) => {
|
||||||
|
return <MentionLink
|
||||||
|
url={attrs.href}
|
||||||
|
content={flattenDeep(children).join('')}
|
||||||
|
origattrs={attrs}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
|
||||||
|
// Processor to use with mini_html_converter
|
||||||
|
const processItem = (item) => {
|
||||||
|
// Handle text noes - just add emoji
|
||||||
|
if (typeof item === 'string') {
|
||||||
|
if (item.includes(':')) {
|
||||||
|
return processTextForEmoji(
|
||||||
|
unescape(item),
|
||||||
|
this.emoji,
|
||||||
|
({ shortcode, url }) => {
|
||||||
|
return <StillImage
|
||||||
|
class="emoji img"
|
||||||
|
src={url}
|
||||||
|
title={`:${shortcode}:`}
|
||||||
|
alt={`:${shortcode}:`}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return unescape(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Handle tag nodes
|
||||||
|
if (Array.isArray(item)) {
|
||||||
|
const [opener, children] = item
|
||||||
|
const Tag = getTagName(opener)
|
||||||
|
switch (Tag) {
|
||||||
|
case 'img': // replace images with StillImage
|
||||||
|
return renderImage(opener)
|
||||||
|
case 'a': // replace mentions with MentionLink
|
||||||
|
if (!this.handleLinks) break
|
||||||
|
const attrs = getAttrs(opener)
|
||||||
|
if (attrs['class'] && attrs['class'].includes('mention')) {
|
||||||
|
return renderMention(attrs, children)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Render tag as is
|
||||||
|
if (children !== undefined) {
|
||||||
|
return <Tag {...{ attrs: getAttrs(opener) }}>
|
||||||
|
{ children.map(processItem) }
|
||||||
|
</Tag>
|
||||||
|
} else {
|
||||||
|
return <Tag/>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return <span class="RichContent">
|
||||||
|
{ convertHtml(this.html).map(processItem) }
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
})
|
63
src/components/rich_content/rich_content.scss
Normal file
63
src/components/rich_content/rich_content.scss
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
.RichContent {
|
||||||
|
blockquote {
|
||||||
|
margin: 0.2em 0 0.2em 2em;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
code,
|
||||||
|
samp,
|
||||||
|
kbd,
|
||||||
|
var,
|
||||||
|
pre {
|
||||||
|
font-family: var(--postCodeFont, monospace);
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 0 0 1em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
p:last-child {
|
||||||
|
margin: 0 0 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 1.1em;
|
||||||
|
line-height: 1.2em;
|
||||||
|
margin: 1.4em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 1.1em;
|
||||||
|
margin: 1em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-size: 1em;
|
||||||
|
margin: 1.2em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
margin: 1.1em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.img {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.emoji {
|
||||||
|
width: var(--emoji-size, 32px);
|
||||||
|
height: var(--emoji-size, 32px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.img,
|
||||||
|
video {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 400px;
|
||||||
|
vertical-align: middle;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
}
|
|
@ -474,7 +474,7 @@ export default {
|
||||||
this.loadThemeFromLocalStorage(false, true)
|
this.loadThemeFromLocalStorage(false, true)
|
||||||
break
|
break
|
||||||
case 'file':
|
case 'file':
|
||||||
console.err('Forcing snapshout from file is not supported yet')
|
console.error('Forcing snapshout from file is not supported yet')
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
this.dismissWarning()
|
this.dismissWarning()
|
||||||
|
|
|
@ -9,6 +9,7 @@ import UserAvatar from '../user_avatar/user_avatar.vue'
|
||||||
import AvatarList from '../avatar_list/avatar_list.vue'
|
import AvatarList from '../avatar_list/avatar_list.vue'
|
||||||
import Timeago from '../timeago/timeago.vue'
|
import Timeago from '../timeago/timeago.vue'
|
||||||
import StatusContent from '../status_content/status_content.vue'
|
import StatusContent from '../status_content/status_content.vue'
|
||||||
|
import RichContent from 'src/components/rich_content/rich_content.jsx'
|
||||||
import StatusPopover from '../status_popover/status_popover.vue'
|
import StatusPopover from '../status_popover/status_popover.vue'
|
||||||
import UserListPopover from '../user_list_popover/user_list_popover.vue'
|
import UserListPopover from '../user_list_popover/user_list_popover.vue'
|
||||||
import EmojiReactions from '../emoji_reactions/emoji_reactions.vue'
|
import EmojiReactions from '../emoji_reactions/emoji_reactions.vue'
|
||||||
|
@ -68,7 +69,8 @@ const Status = {
|
||||||
StatusPopover,
|
StatusPopover,
|
||||||
UserListPopover,
|
UserListPopover,
|
||||||
EmojiReactions,
|
EmojiReactions,
|
||||||
StatusContent
|
StatusContent,
|
||||||
|
RichContent
|
||||||
},
|
},
|
||||||
props: [
|
props: [
|
||||||
'statusoid',
|
'statusoid',
|
||||||
|
@ -136,8 +138,9 @@ const Status = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
retweet () { return !!this.statusoid.retweeted_status },
|
retweet () { return !!this.statusoid.retweeted_status },
|
||||||
|
retweeterUser () { return this.statusoid.user },
|
||||||
retweeter () { return this.statusoid.user.name || this.statusoid.user.screen_name_ui },
|
retweeter () { return this.statusoid.user.name || this.statusoid.user.screen_name_ui },
|
||||||
retweeterHtml () { return this.statusoid.user.name_html },
|
retweeterHtml () { return this.statusoid.user.name },
|
||||||
retweeterProfileLink () { return this.generateUserProfileLink(this.statusoid.user.id, this.statusoid.user.screen_name) },
|
retweeterProfileLink () { return this.generateUserProfileLink(this.statusoid.user.id, this.statusoid.user.screen_name) },
|
||||||
status () {
|
status () {
|
||||||
if (this.retweet) {
|
if (this.retweet) {
|
||||||
|
|
|
@ -93,12 +93,8 @@ $status-margin: 0.75em;
|
||||||
margin-right: 0.4em;
|
margin-right: 0.4em;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
|
||||||
.emoji {
|
--_still_image-label-scale: 0.25;
|
||||||
width: 14px;
|
--emoji-size: 14px;
|
||||||
height: 14px;
|
|
||||||
vertical-align: middle;
|
|
||||||
object-fit: contain;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-favicon {
|
.status-favicon {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<template>
|
<template>
|
||||||
<!-- eslint-disable vue/no-v-html -->
|
|
||||||
<div
|
<div
|
||||||
v-if="!hideStatus"
|
v-if="!hideStatus"
|
||||||
class="Status"
|
class="Status"
|
||||||
|
@ -89,8 +88,12 @@
|
||||||
<router-link
|
<router-link
|
||||||
v-if="retweeterHtml"
|
v-if="retweeterHtml"
|
||||||
:to="retweeterProfileLink"
|
:to="retweeterProfileLink"
|
||||||
v-html="retweeterHtml"
|
>
|
||||||
|
<RichContent
|
||||||
|
:html="retweeterHtml"
|
||||||
|
:emoji="retweeterUser.emoji"
|
||||||
/>
|
/>
|
||||||
|
</router-link>
|
||||||
<router-link
|
<router-link
|
||||||
v-else
|
v-else
|
||||||
:to="retweeterProfileLink"
|
:to="retweeterProfileLink"
|
||||||
|
@ -145,8 +148,12 @@
|
||||||
v-if="status.user.name_html"
|
v-if="status.user.name_html"
|
||||||
class="status-username"
|
class="status-username"
|
||||||
:title="status.user.name"
|
:title="status.user.name"
|
||||||
v-html="status.user.name_html"
|
>
|
||||||
|
<RichContent
|
||||||
|
:html="status.user.name"
|
||||||
|
:emoji="status.user.emoji"
|
||||||
/>
|
/>
|
||||||
|
</h4>
|
||||||
<h4
|
<h4
|
||||||
v-else
|
v-else
|
||||||
class="status-username"
|
class="status-username"
|
||||||
|
@ -402,7 +409,6 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
<!-- eslint-enable vue/no-v-html -->
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script src="./status.js" ></script>
|
<script src="./status.js" ></script>
|
||||||
|
|
147
src/components/status_body/status_body.js
Normal file
147
src/components/status_body/status_body.js
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
import fileType from 'src/services/file_type/file_type.service'
|
||||||
|
import RichContent from 'src/components/rich_content/rich_content.jsx'
|
||||||
|
import { processHtml } from 'src/services/tiny_post_html_processor/tiny_post_html_processor.service.js'
|
||||||
|
import { extractTagFromUrl } from 'src/services/matcher/matcher.service.js'
|
||||||
|
import { mapGetters } from 'vuex'
|
||||||
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
||||||
|
import {
|
||||||
|
faFile,
|
||||||
|
faMusic,
|
||||||
|
faImage,
|
||||||
|
faLink,
|
||||||
|
faPollH
|
||||||
|
} from '@fortawesome/free-solid-svg-icons'
|
||||||
|
|
||||||
|
library.add(
|
||||||
|
faFile,
|
||||||
|
faMusic,
|
||||||
|
faImage,
|
||||||
|
faLink,
|
||||||
|
faPollH
|
||||||
|
)
|
||||||
|
|
||||||
|
const StatusContent = {
|
||||||
|
name: 'StatusContent',
|
||||||
|
props: [
|
||||||
|
'status',
|
||||||
|
'focused',
|
||||||
|
'noHeading',
|
||||||
|
'fullContent',
|
||||||
|
'singleLine'
|
||||||
|
],
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
showingTall: this.fullContent || (this.inConversation && this.focused),
|
||||||
|
showingLongSubject: false,
|
||||||
|
// not as computed because it sets the initial state which will be changed later
|
||||||
|
expandingSubject: !this.$store.getters.mergedConfig.collapseMessageWithSubject
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
localCollapseSubjectDefault () {
|
||||||
|
return this.mergedConfig.collapseMessageWithSubject
|
||||||
|
},
|
||||||
|
// This is a bit hacky, but we want to approximate post height before rendering
|
||||||
|
// so we count newlines (masto uses <p> for paragraphs, GS uses <br> between them)
|
||||||
|
// as well as approximate line count by counting characters and approximating ~80
|
||||||
|
// per line.
|
||||||
|
//
|
||||||
|
// Using max-height + overflow: auto for status components resulted in false positives
|
||||||
|
// very often with japanese characters, and it was very annoying.
|
||||||
|
tallStatus () {
|
||||||
|
const lengthScore = this.status.statusnet_html.split(/<p|<br/).length + this.status.text.length / 80
|
||||||
|
return lengthScore > 20
|
||||||
|
},
|
||||||
|
longSubject () {
|
||||||
|
return this.status.summary.length > 240
|
||||||
|
},
|
||||||
|
// When a status has a subject and is also tall, we should only have one show more/less button. If the default is to collapse statuses with subjects, we just treat it like a status with a subject; otherwise, we just treat it like a tall status.
|
||||||
|
mightHideBecauseSubject () {
|
||||||
|
return !!this.status.summary && this.localCollapseSubjectDefault
|
||||||
|
},
|
||||||
|
mightHideBecauseTall () {
|
||||||
|
return this.tallStatus && !(this.status.summary && this.localCollapseSubjectDefault)
|
||||||
|
},
|
||||||
|
hideSubjectStatus () {
|
||||||
|
return this.mightHideBecauseSubject && !this.expandingSubject
|
||||||
|
},
|
||||||
|
hideTallStatus () {
|
||||||
|
return this.mightHideBecauseTall && !this.showingTall
|
||||||
|
},
|
||||||
|
showingMore () {
|
||||||
|
return (this.mightHideBecauseTall && this.showingTall) || (this.mightHideBecauseSubject && this.expandingSubject)
|
||||||
|
},
|
||||||
|
postBodyHtml () {
|
||||||
|
const html = this.status.raw_html
|
||||||
|
|
||||||
|
if (this.mergedConfig.greentext) {
|
||||||
|
try {
|
||||||
|
if (html.includes('>')) {
|
||||||
|
// This checks if post has '>' at the beginning, excluding mentions so that @mention >impying works
|
||||||
|
return processHtml(html, (string) => {
|
||||||
|
if (string.includes('>') &&
|
||||||
|
string
|
||||||
|
.replace(/<[^>]+?>/gi, '') // remove all tags
|
||||||
|
.replace(/@\w+/gi, '') // remove mentions (even failed ones)
|
||||||
|
.trim()
|
||||||
|
.startsWith('>')) {
|
||||||
|
return `<span class='greentext'>${string}</span>`
|
||||||
|
} else {
|
||||||
|
return string
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to process status html', e)
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
},
|
||||||
|
attachmentTypes () {
|
||||||
|
return this.status.attachments.map(file => fileType.fileType(file.mimetype))
|
||||||
|
},
|
||||||
|
...mapGetters(['mergedConfig'])
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
RichContent
|
||||||
|
},
|
||||||
|
mounted () {
|
||||||
|
this.status.attentions && this.status.attentions.forEach(attn => {
|
||||||
|
const { id } = attn
|
||||||
|
this.$store.dispatch('fetchUserIfMissing', id)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
linkClicked (event) {
|
||||||
|
const target = event.target.closest('.status-content a')
|
||||||
|
if (target) {
|
||||||
|
if (target.rel.match(/(?:^|\s)tag(?:$|\s)/) || target.className.match(/hashtag/)) {
|
||||||
|
// Extract tag name from dataset or link url
|
||||||
|
const tag = target.dataset.tag || extractTagFromUrl(target.href)
|
||||||
|
if (tag) {
|
||||||
|
const link = this.generateTagLink(tag)
|
||||||
|
this.$router.push(link)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.open(target.href, '_blank')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
toggleShowMore () {
|
||||||
|
if (this.mightHideBecauseTall) {
|
||||||
|
this.showingTall = !this.showingTall
|
||||||
|
} else if (this.mightHideBecauseSubject) {
|
||||||
|
this.expandingSubject = !this.expandingSubject
|
||||||
|
}
|
||||||
|
},
|
||||||
|
generateTagLink (tag) {
|
||||||
|
return `/tag/${tag}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default StatusContent
|
123
src/components/status_body/status_body.scss
Normal file
123
src/components/status_body/status_body.scss
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
@import '../../_variables.scss';
|
||||||
|
|
||||||
|
.StatusBody {
|
||||||
|
|
||||||
|
.emoji {
|
||||||
|
--_still_image-label-scale: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .text,
|
||||||
|
& .summary {
|
||||||
|
font-family: var(--postFont, sans-serif);
|
||||||
|
white-space: pre-wrap;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
word-wrap: break-word;
|
||||||
|
word-break: break-word;
|
||||||
|
line-height: 1.4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary {
|
||||||
|
display: block;
|
||||||
|
font-style: italic;
|
||||||
|
padding-bottom: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text {
|
||||||
|
&.-single-line {
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
height: 1.4em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary-wrapper {
|
||||||
|
margin-bottom: 0.5em;
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 0 0 1px 0;
|
||||||
|
border-color: var(--border, $fallback--border);
|
||||||
|
flex-grow: 0;
|
||||||
|
|
||||||
|
&.-tall {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.summary {
|
||||||
|
max-height: 2em;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
|
||||||
|
&.-tall-status {
|
||||||
|
position: relative;
|
||||||
|
height: 220px;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: hidden;
|
||||||
|
z-index: 1;
|
||||||
|
|
||||||
|
.text {
|
||||||
|
min-height: 0;
|
||||||
|
mask:
|
||||||
|
linear-gradient(to top, white, transparent) bottom/100% 70px no-repeat,
|
||||||
|
linear-gradient(to top, white, white);
|
||||||
|
|
||||||
|
/* Autoprefixed seem to ignore this one, and also syntax is different */
|
||||||
|
-webkit-mask-composite: xor;
|
||||||
|
mask-composite: exclude;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& .tall-status-hider,
|
||||||
|
& .tall-subject-hider,
|
||||||
|
& .status-unhider,
|
||||||
|
& .cw-status-hider {
|
||||||
|
display: inline-block;
|
||||||
|
word-break: break-all;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tall-status-hider {
|
||||||
|
position: absolute;
|
||||||
|
height: 70px;
|
||||||
|
margin-top: 150px;
|
||||||
|
line-height: 110px;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tall-subject-hider {
|
||||||
|
// position: absolute;
|
||||||
|
padding-bottom: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .status-unhider,
|
||||||
|
& .cw-status-hider {
|
||||||
|
word-break: break-all;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.greentext {
|
||||||
|
color: $fallback--cGreen;
|
||||||
|
color: var(--postGreentext, $fallback--cGreen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Not sure if this is necessary */
|
||||||
|
video {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 400px;
|
||||||
|
vertical-align: middle;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
95
src/components/status_body/status_body.vue
Normal file
95
src/components/status_body/status_body.vue
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<template>
|
||||||
|
<div class="StatusBody">
|
||||||
|
<div class="body">
|
||||||
|
<div
|
||||||
|
v-if="status.summary_html"
|
||||||
|
class="summary-wrapper"
|
||||||
|
:class="{ '-tall': (longSubject && !showingLongSubject) }"
|
||||||
|
>
|
||||||
|
<RichContent
|
||||||
|
class="media-body summary"
|
||||||
|
:html="status.summary_raw_html"
|
||||||
|
:emoji="status.emojis"
|
||||||
|
@click.prevent="linkClicked"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
v-if="longSubject && showingLongSubject"
|
||||||
|
class="button-unstyled -link tall-subject-hider"
|
||||||
|
@click.prevent="showingLongSubject=false"
|
||||||
|
>
|
||||||
|
{{ $t("status.hide_full_subject") }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
v-else-if="longSubject"
|
||||||
|
class="button-unstyled -link tall-subject-hider"
|
||||||
|
@click.prevent="showingLongSubject=true"
|
||||||
|
>
|
||||||
|
{{ $t("status.show_full_subject") }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
:class="{'-tall-status': hideTallStatus}"
|
||||||
|
class="text-wrapper"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
v-if="hideTallStatus"
|
||||||
|
class="button-unstyled -link tall-status-hider"
|
||||||
|
:class="{ '-focused': focused }"
|
||||||
|
@click.prevent="toggleShowMore"
|
||||||
|
>
|
||||||
|
{{ $t("general.show_more") }}
|
||||||
|
</button>
|
||||||
|
<RichContent
|
||||||
|
v-if="!hideSubjectStatus && !(singleLine && status.summary_html)"
|
||||||
|
:class="{ '-single-line': singleLine }"
|
||||||
|
class="text media-body"
|
||||||
|
:html="postBodyHtml"
|
||||||
|
:emoji="status.emojis"
|
||||||
|
:handle-links="true"
|
||||||
|
@click.prevent="linkClicked"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
v-if="hideSubjectStatus"
|
||||||
|
class="button-unstyled -link cw-status-hider"
|
||||||
|
@click.prevent="toggleShowMore"
|
||||||
|
>
|
||||||
|
{{ $t("status.show_content") }}
|
||||||
|
<FAIcon
|
||||||
|
v-if="attachmentTypes.includes('image')"
|
||||||
|
icon="image"
|
||||||
|
/>
|
||||||
|
<FAIcon
|
||||||
|
v-if="attachmentTypes.includes('video')"
|
||||||
|
icon="video"
|
||||||
|
/>
|
||||||
|
<FAIcon
|
||||||
|
v-if="attachmentTypes.includes('audio')"
|
||||||
|
icon="music"
|
||||||
|
/>
|
||||||
|
<FAIcon
|
||||||
|
v-if="attachmentTypes.includes('unknown')"
|
||||||
|
icon="file"
|
||||||
|
/>
|
||||||
|
<FAIcon
|
||||||
|
v-if="status.poll && status.poll.options"
|
||||||
|
icon="poll-h"
|
||||||
|
/>
|
||||||
|
<FAIcon
|
||||||
|
v-if="status.card"
|
||||||
|
icon="link"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
v-if="showingMore && !fullContent"
|
||||||
|
class="button-unstyled -link status-unhider"
|
||||||
|
@click.prevent="toggleShowMore"
|
||||||
|
>
|
||||||
|
{{ tallStatus ? $t("general.show_less") : $t("status.hide_content") }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<slot v-if="!hideSubjectStatus" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script src="./status_body.js" ></script>
|
||||||
|
<style lang="scss" src="./status_body.scss" />
|
|
@ -1,11 +1,9 @@
|
||||||
import Attachment from '../attachment/attachment.vue'
|
import Attachment from '../attachment/attachment.vue'
|
||||||
import Poll from '../poll/poll.vue'
|
import Poll from '../poll/poll.vue'
|
||||||
import Gallery from '../gallery/gallery.vue'
|
import Gallery from '../gallery/gallery.vue'
|
||||||
|
import StatusBody from 'src/components/status_body/status_body.vue'
|
||||||
import LinkPreview from '../link-preview/link-preview.vue'
|
import LinkPreview from '../link-preview/link-preview.vue'
|
||||||
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
|
|
||||||
import fileType from 'src/services/file_type/file_type.service'
|
import fileType from 'src/services/file_type/file_type.service'
|
||||||
import { processHtml } from 'src/services/tiny_post_html_processor/tiny_post_html_processor.service.js'
|
|
||||||
import { mentionMatchesUrl, extractTagFromUrl } from 'src/services/matcher/matcher.service.js'
|
|
||||||
import { mapGetters, mapState } from 'vuex'
|
import { mapGetters, mapState } from 'vuex'
|
||||||
import { library } from '@fortawesome/fontawesome-svg-core'
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
||||||
import {
|
import {
|
||||||
|
@ -35,52 +33,11 @@ const StatusContent = {
|
||||||
'fullContent',
|
'fullContent',
|
||||||
'singleLine'
|
'singleLine'
|
||||||
],
|
],
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
showingTall: this.fullContent || (this.inConversation && this.focused),
|
|
||||||
showingLongSubject: false,
|
|
||||||
// not as computed because it sets the initial state which will be changed later
|
|
||||||
expandingSubject: !this.$store.getters.mergedConfig.collapseMessageWithSubject
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
localCollapseSubjectDefault () {
|
|
||||||
return this.mergedConfig.collapseMessageWithSubject
|
|
||||||
},
|
|
||||||
hideAttachments () {
|
hideAttachments () {
|
||||||
return (this.mergedConfig.hideAttachments && !this.inConversation) ||
|
return (this.mergedConfig.hideAttachments && !this.inConversation) ||
|
||||||
(this.mergedConfig.hideAttachmentsInConv && this.inConversation)
|
(this.mergedConfig.hideAttachmentsInConv && this.inConversation)
|
||||||
},
|
},
|
||||||
// This is a bit hacky, but we want to approximate post height before rendering
|
|
||||||
// so we count newlines (masto uses <p> for paragraphs, GS uses <br> between them)
|
|
||||||
// as well as approximate line count by counting characters and approximating ~80
|
|
||||||
// per line.
|
|
||||||
//
|
|
||||||
// Using max-height + overflow: auto for status components resulted in false positives
|
|
||||||
// very often with japanese characters, and it was very annoying.
|
|
||||||
tallStatus () {
|
|
||||||
const lengthScore = this.status.statusnet_html.split(/<p|<br/).length + this.status.text.length / 80
|
|
||||||
return lengthScore > 20
|
|
||||||
},
|
|
||||||
longSubject () {
|
|
||||||
return this.status.summary.length > 240
|
|
||||||
},
|
|
||||||
// When a status has a subject and is also tall, we should only have one show more/less button. If the default is to collapse statuses with subjects, we just treat it like a status with a subject; otherwise, we just treat it like a tall status.
|
|
||||||
mightHideBecauseSubject () {
|
|
||||||
return !!this.status.summary && this.localCollapseSubjectDefault
|
|
||||||
},
|
|
||||||
mightHideBecauseTall () {
|
|
||||||
return this.tallStatus && !(this.status.summary && this.localCollapseSubjectDefault)
|
|
||||||
},
|
|
||||||
hideSubjectStatus () {
|
|
||||||
return this.mightHideBecauseSubject && !this.expandingSubject
|
|
||||||
},
|
|
||||||
hideTallStatus () {
|
|
||||||
return this.mightHideBecauseTall && !this.showingTall
|
|
||||||
},
|
|
||||||
showingMore () {
|
|
||||||
return (this.mightHideBecauseTall && this.showingTall) || (this.mightHideBecauseSubject && this.expandingSubject)
|
|
||||||
},
|
|
||||||
nsfwClickthrough () {
|
nsfwClickthrough () {
|
||||||
if (!this.status.nsfw) {
|
if (!this.status.nsfw) {
|
||||||
return false
|
return false
|
||||||
|
@ -118,45 +75,11 @@ const StatusContent = {
|
||||||
file => !fileType.fileMatchesSomeType(this.galleryTypes, file)
|
file => !fileType.fileMatchesSomeType(this.galleryTypes, file)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
attachmentTypes () {
|
|
||||||
return this.status.attachments.map(file => fileType.fileType(file.mimetype))
|
|
||||||
},
|
|
||||||
maxThumbnails () {
|
maxThumbnails () {
|
||||||
return this.mergedConfig.maxThumbnails
|
return this.mergedConfig.maxThumbnails
|
||||||
},
|
},
|
||||||
postBodyHtml () {
|
|
||||||
const html = this.status.statusnet_html
|
|
||||||
|
|
||||||
if (this.mergedConfig.greentext) {
|
|
||||||
try {
|
|
||||||
if (html.includes('>')) {
|
|
||||||
// This checks if post has '>' at the beginning, excluding mentions so that @mention >impying works
|
|
||||||
return processHtml(html, (string) => {
|
|
||||||
if (string.includes('>') &&
|
|
||||||
string
|
|
||||||
.replace(/<[^>]+?>/gi, '') // remove all tags
|
|
||||||
.replace(/@\w+/gi, '') // remove mentions (even failed ones)
|
|
||||||
.trim()
|
|
||||||
.startsWith('>')) {
|
|
||||||
return `<span class='greentext'>${string}</span>`
|
|
||||||
} else {
|
|
||||||
return string
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
return html
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.err('Failed to process status html', e)
|
|
||||||
return html
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return html
|
|
||||||
}
|
|
||||||
},
|
|
||||||
...mapGetters(['mergedConfig']),
|
...mapGetters(['mergedConfig']),
|
||||||
...mapState({
|
...mapState({
|
||||||
betterShadow: state => state.interface.browserSupport.cssFilter,
|
|
||||||
currentUser: state => state.users.currentUser
|
currentUser: state => state.users.currentUser
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -164,48 +87,10 @@ const StatusContent = {
|
||||||
Attachment,
|
Attachment,
|
||||||
Poll,
|
Poll,
|
||||||
Gallery,
|
Gallery,
|
||||||
LinkPreview
|
LinkPreview,
|
||||||
|
StatusBody
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
linkClicked (event) {
|
|
||||||
const target = event.target.closest('.status-content a')
|
|
||||||
if (target) {
|
|
||||||
if (target.className.match(/mention/)) {
|
|
||||||
const href = target.href
|
|
||||||
const attn = this.status.attentions.find(attn => mentionMatchesUrl(attn, href))
|
|
||||||
if (attn) {
|
|
||||||
event.stopPropagation()
|
|
||||||
event.preventDefault()
|
|
||||||
const link = this.generateUserProfileLink(attn.id, attn.screen_name)
|
|
||||||
this.$router.push(link)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (target.rel.match(/(?:^|\s)tag(?:$|\s)/) || target.className.match(/hashtag/)) {
|
|
||||||
// Extract tag name from dataset or link url
|
|
||||||
const tag = target.dataset.tag || extractTagFromUrl(target.href)
|
|
||||||
if (tag) {
|
|
||||||
const link = this.generateTagLink(tag)
|
|
||||||
this.$router.push(link)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
window.open(target.href, '_blank')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toggleShowMore () {
|
|
||||||
if (this.mightHideBecauseTall) {
|
|
||||||
this.showingTall = !this.showingTall
|
|
||||||
} else if (this.mightHideBecauseSubject) {
|
|
||||||
this.expandingSubject = !this.expandingSubject
|
|
||||||
}
|
|
||||||
},
|
|
||||||
generateUserProfileLink (id, name) {
|
|
||||||
return generateProfileLink(id, name, this.$store.state.instance.restrictedNicknames)
|
|
||||||
},
|
|
||||||
generateTagLink (tag) {
|
|
||||||
return `/tag/${tag}`
|
|
||||||
},
|
|
||||||
setMedia () {
|
setMedia () {
|
||||||
const attachments = this.attachmentSize === 'hide' ? this.status.attachments : this.galleryAttachments
|
const attachments = this.attachmentSize === 'hide' ? this.status.attachments : this.galleryAttachments
|
||||||
return () => this.$store.dispatch('setMedia', attachments)
|
return () => this.$store.dispatch('setMedia', attachments)
|
||||||
|
|
|
@ -1,98 +1,16 @@
|
||||||
<template>
|
<template>
|
||||||
<!-- eslint-disable vue/no-v-html -->
|
|
||||||
<div class="StatusContent">
|
<div class="StatusContent">
|
||||||
<slot name="header" />
|
<slot name="header" />
|
||||||
<div
|
<StatusBody
|
||||||
v-if="status.summary_html"
|
:status="status"
|
||||||
class="summary-wrapper"
|
:single-line="singleLine"
|
||||||
:class="{ 'tall-subject': (longSubject && !showingLongSubject) }"
|
|
||||||
>
|
>
|
||||||
<div
|
<div v-if="status.poll && status.poll.options">
|
||||||
class="media-body summary"
|
|
||||||
@click.prevent="linkClicked"
|
|
||||||
v-html="status.summary_html"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
v-if="longSubject && showingLongSubject"
|
|
||||||
class="button-unstyled -link tall-subject-hider"
|
|
||||||
@click.prevent="showingLongSubject=false"
|
|
||||||
>
|
|
||||||
{{ $t("status.hide_full_subject") }}
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
v-else-if="longSubject"
|
|
||||||
class="button-unstyled -link tall-subject-hider"
|
|
||||||
:class="{ 'tall-subject-hider_focused': focused }"
|
|
||||||
@click.prevent="showingLongSubject=true"
|
|
||||||
>
|
|
||||||
{{ $t("status.show_full_subject") }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
:class="{'tall-status': hideTallStatus}"
|
|
||||||
class="status-content-wrapper"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
v-if="hideTallStatus"
|
|
||||||
class="button-unstyled -link tall-status-hider"
|
|
||||||
:class="{ 'tall-status-hider_focused': focused }"
|
|
||||||
@click.prevent="toggleShowMore"
|
|
||||||
>
|
|
||||||
{{ $t("general.show_more") }}
|
|
||||||
</button>
|
|
||||||
<div
|
|
||||||
v-if="!hideSubjectStatus"
|
|
||||||
:class="{ 'single-line': singleLine }"
|
|
||||||
class="status-content media-body"
|
|
||||||
@click.prevent="linkClicked"
|
|
||||||
v-html="postBodyHtml"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
v-if="hideSubjectStatus"
|
|
||||||
class="button-unstyled -link cw-status-hider"
|
|
||||||
@click.prevent="toggleShowMore"
|
|
||||||
>
|
|
||||||
{{ $t("status.show_content") }}
|
|
||||||
<FAIcon
|
|
||||||
v-if="attachmentTypes.includes('image')"
|
|
||||||
icon="image"
|
|
||||||
/>
|
|
||||||
<FAIcon
|
|
||||||
v-if="attachmentTypes.includes('video')"
|
|
||||||
icon="video"
|
|
||||||
/>
|
|
||||||
<FAIcon
|
|
||||||
v-if="attachmentTypes.includes('audio')"
|
|
||||||
icon="music"
|
|
||||||
/>
|
|
||||||
<FAIcon
|
|
||||||
v-if="attachmentTypes.includes('unknown')"
|
|
||||||
icon="file"
|
|
||||||
/>
|
|
||||||
<FAIcon
|
|
||||||
v-if="status.poll && status.poll.options"
|
|
||||||
icon="poll-h"
|
|
||||||
/>
|
|
||||||
<FAIcon
|
|
||||||
v-if="status.card"
|
|
||||||
icon="link"
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
v-if="showingMore && !fullContent"
|
|
||||||
class="button-unstyled -link status-unhider"
|
|
||||||
@click.prevent="toggleShowMore"
|
|
||||||
>
|
|
||||||
{{ tallStatus ? $t("general.show_less") : $t("status.hide_content") }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="status.poll && status.poll.options && !hideSubjectStatus">
|
|
||||||
<poll :base-poll="status.poll" />
|
<poll :base-poll="status.poll" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="status.attachments.length !== 0 && (!hideSubjectStatus || showingLongSubject)"
|
v-if="status.attachments.length !== 0"
|
||||||
class="attachments media-body"
|
class="attachments media-body"
|
||||||
>
|
>
|
||||||
<attachment
|
<attachment
|
||||||
|
@ -116,7 +34,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="status.card && !hideSubjectStatus && !noHeading"
|
v-if="status.card && !noHeading"
|
||||||
class="link-preview media-body"
|
class="link-preview media-body"
|
||||||
>
|
>
|
||||||
<link-preview
|
<link-preview
|
||||||
|
@ -125,9 +43,9 @@
|
||||||
:nsfw="nsfwClickthrough"
|
:nsfw="nsfwClickthrough"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
</StatusBody>
|
||||||
<slot name="footer" />
|
<slot name="footer" />
|
||||||
</div>
|
</div>
|
||||||
<!-- eslint-enable vue/no-v-html -->
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script src="./status_content.js" ></script>
|
<script src="./status_content.js" ></script>
|
||||||
|
@ -139,156 +57,5 @@ $status-margin: 0.75em;
|
||||||
.StatusContent {
|
.StatusContent {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
|
||||||
.status-content-wrapper {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
flex-wrap: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tall-status {
|
|
||||||
position: relative;
|
|
||||||
height: 220px;
|
|
||||||
overflow-x: hidden;
|
|
||||||
overflow-y: hidden;
|
|
||||||
z-index: 1;
|
|
||||||
.status-content {
|
|
||||||
min-height: 0;
|
|
||||||
mask: linear-gradient(to top, white, transparent) bottom/100% 70px no-repeat,
|
|
||||||
linear-gradient(to top, white, white);
|
|
||||||
/* Autoprefixed seem to ignore this one, and also syntax is different */
|
|
||||||
-webkit-mask-composite: xor;
|
|
||||||
mask-composite: exclude;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.tall-status-hider {
|
|
||||||
display: inline-block;
|
|
||||||
word-break: break-all;
|
|
||||||
position: absolute;
|
|
||||||
height: 70px;
|
|
||||||
margin-top: 150px;
|
|
||||||
width: 100%;
|
|
||||||
text-align: center;
|
|
||||||
line-height: 110px;
|
|
||||||
z-index: 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-unhider, .cw-status-hider {
|
|
||||||
width: 100%;
|
|
||||||
text-align: center;
|
|
||||||
display: inline-block;
|
|
||||||
word-break: break-all;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
img, video {
|
|
||||||
max-width: 100%;
|
|
||||||
max-height: 400px;
|
|
||||||
vertical-align: middle;
|
|
||||||
object-fit: contain;
|
|
||||||
|
|
||||||
&.emoji {
|
|
||||||
width: 32px;
|
|
||||||
height: 32px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.summary-wrapper {
|
|
||||||
margin-bottom: 0.5em;
|
|
||||||
border-style: solid;
|
|
||||||
border-width: 0 0 1px 0;
|
|
||||||
border-color: var(--border, $fallback--border);
|
|
||||||
flex-grow: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.summary {
|
|
||||||
font-style: italic;
|
|
||||||
padding-bottom: 0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tall-subject {
|
|
||||||
position: relative;
|
|
||||||
.summary {
|
|
||||||
max-height: 2em;
|
|
||||||
overflow: hidden;
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.tall-subject-hider {
|
|
||||||
display: inline-block;
|
|
||||||
word-break: break-all;
|
|
||||||
// position: absolute;
|
|
||||||
width: 100%;
|
|
||||||
text-align: center;
|
|
||||||
padding-bottom: 0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-content {
|
|
||||||
font-family: var(--postFont, sans-serif);
|
|
||||||
line-height: 1.4em;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
overflow-wrap: break-word;
|
|
||||||
word-wrap: break-word;
|
|
||||||
word-break: break-word;
|
|
||||||
|
|
||||||
blockquote {
|
|
||||||
margin: 0.2em 0 0.2em 2em;
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
pre {
|
|
||||||
overflow: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
code, samp, kbd, var, pre {
|
|
||||||
font-family: var(--postCodeFont, monospace);
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
|
||||||
margin: 0 0 1em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
p:last-child {
|
|
||||||
margin: 0 0 0 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 1.1em;
|
|
||||||
line-height: 1.2em;
|
|
||||||
margin: 1.4em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
font-size: 1.1em;
|
|
||||||
margin: 1.0em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
h3 {
|
|
||||||
font-size: 1em;
|
|
||||||
margin: 1.2em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
h4 {
|
|
||||||
margin: 1.1em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.single-line {
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
overflow: hidden;
|
|
||||||
height: 1.4em;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.greentext {
|
|
||||||
color: $fallback--cGreen;
|
|
||||||
color: var(--postGreentext, $fallback--cGreen);
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
position: relative;
|
position: relative;
|
||||||
line-height: 0;
|
line-height: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
display: flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
canvas {
|
canvas {
|
||||||
|
@ -53,6 +53,7 @@
|
||||||
|
|
||||||
&.animated {
|
&.animated {
|
||||||
&::before {
|
&::before {
|
||||||
|
zoom: var(--_still_image-label-scale, 1);
|
||||||
content: 'gif';
|
content: 'gif';
|
||||||
position: absolute;
|
position: absolute;
|
||||||
line-height: 10px;
|
line-height: 10px;
|
||||||
|
|
|
@ -246,6 +246,11 @@ export const getters = {
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
},
|
},
|
||||||
|
findUserByUrl: state => query => {
|
||||||
|
return state.users
|
||||||
|
.find(u => u.statusnet_profile_url &&
|
||||||
|
u.statusnet_profile_url.toLowerCase() === query.toLowerCase())
|
||||||
|
},
|
||||||
relationship: state => id => {
|
relationship: state => id => {
|
||||||
const rel = id && state.relationships[id]
|
const rel = id && state.relationships[id]
|
||||||
return rel || { id, loading: true }
|
return rel || { id, loading: true }
|
||||||
|
|
|
@ -54,6 +54,7 @@ export const parseUser = (data) => {
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output.emoji = data.emojis
|
||||||
output.name = data.display_name
|
output.name = data.display_name
|
||||||
output.name_html = addEmojis(escape(data.display_name), data.emojis)
|
output.name_html = addEmojis(escape(data.display_name), data.emojis)
|
||||||
|
|
||||||
|
@ -267,6 +268,8 @@ export const parseStatus = (data) => {
|
||||||
output.nsfw = data.sensitive
|
output.nsfw = data.sensitive
|
||||||
|
|
||||||
output.statusnet_html = addEmojis(data.content, data.emojis)
|
output.statusnet_html = addEmojis(data.content, data.emojis)
|
||||||
|
output.raw_html = data.content
|
||||||
|
output.emojis = data.emojis
|
||||||
|
|
||||||
output.tags = data.tags
|
output.tags = data.tags
|
||||||
|
|
||||||
|
@ -293,6 +296,7 @@ export const parseStatus = (data) => {
|
||||||
output.retweeted_status = parseStatus(data.reblog)
|
output.retweeted_status = parseStatus(data.reblog)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output.summary_raw_html = escape(data.spoiler_text)
|
||||||
output.summary_html = addEmojis(escape(data.spoiler_text), data.emojis)
|
output.summary_html = addEmojis(escape(data.spoiler_text), data.emojis)
|
||||||
output.external_url = data.url
|
output.external_url = data.url
|
||||||
output.poll = data.poll
|
output.poll = data.poll
|
||||||
|
@ -444,6 +448,8 @@ export const parseChatMessage = (message) => {
|
||||||
output.id = message.id
|
output.id = message.id
|
||||||
output.created_at = new Date(message.created_at)
|
output.created_at = new Date(message.created_at)
|
||||||
output.chat_id = message.chat_id
|
output.chat_id = message.chat_id
|
||||||
|
output.emojis = message.emojis
|
||||||
|
output.content_raw = message.content
|
||||||
if (message.content) {
|
if (message.content) {
|
||||||
output.content = addEmojis(message.content, message.emojis)
|
output.content = addEmojis(message.content, message.emojis)
|
||||||
} else {
|
} else {
|
||||||
|
|
138
src/services/mini_html_converter/mini_html_converter.service.js
Normal file
138
src/services/mini_html_converter/mini_html_converter.service.js
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
/**
|
||||||
|
* This is a not-so-tiny purpose-built HTML parser/processor. It was made for use
|
||||||
|
* with StatusBody component for purpose of replacing tags with vue components
|
||||||
|
*
|
||||||
|
* known issue: doesn't handle CDATA so nested CDATA might not work well
|
||||||
|
*
|
||||||
|
* @param {Object} input - input data
|
||||||
|
* @param {(string) => string} lineProcessor - function that will be called on every line
|
||||||
|
* @param {{ key[string]: (string) => string}} tagProcessor - map of processors for tags
|
||||||
|
* @return {string} processed html
|
||||||
|
*/
|
||||||
|
export const convertHtml = (html) => {
|
||||||
|
// Elements that are implicitly self-closing
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Glossary/empty_element
|
||||||
|
const emptyElements = new Set([
|
||||||
|
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
|
||||||
|
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'
|
||||||
|
])
|
||||||
|
// TODO For future - also parse HTML5 multi-source components?
|
||||||
|
|
||||||
|
const buffer = [] // Current output buffer
|
||||||
|
const levels = [['', buffer]] // How deep we are in tags and which tags were there
|
||||||
|
let textBuffer = '' // Current line content
|
||||||
|
let tagBuffer = null // Current tag buffer, if null = we are not currently reading a tag
|
||||||
|
|
||||||
|
const getCurrentBuffer = () => {
|
||||||
|
return levels[levels.length - 1][1]
|
||||||
|
}
|
||||||
|
|
||||||
|
const flushText = () => { // Processes current line buffer, adds it to output buffer and clears line buffer
|
||||||
|
if (textBuffer === '') return
|
||||||
|
getCurrentBuffer().push(textBuffer)
|
||||||
|
textBuffer = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSelfClosing = (tag) => {
|
||||||
|
getCurrentBuffer().push([tag])
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOpen = (tag) => {
|
||||||
|
const curBuf = getCurrentBuffer()
|
||||||
|
const newLevel = [tag, []]
|
||||||
|
levels.push(newLevel)
|
||||||
|
curBuf.push(newLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleClose = (tag) => {
|
||||||
|
const currentTag = levels[levels.length - 1]
|
||||||
|
if (getTagName(levels[levels.length - 1][0]) === getTagName(tag)) {
|
||||||
|
currentTag.push(tag)
|
||||||
|
levels.pop()
|
||||||
|
} else {
|
||||||
|
getCurrentBuffer().push(tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < html.length; i++) {
|
||||||
|
const char = html[i]
|
||||||
|
if (char === '<' && tagBuffer === null) {
|
||||||
|
flushText()
|
||||||
|
tagBuffer = char
|
||||||
|
} else if (char !== '>' && tagBuffer !== null) {
|
||||||
|
tagBuffer += char
|
||||||
|
} else if (char === '>' && tagBuffer !== null) {
|
||||||
|
tagBuffer += char
|
||||||
|
const tagFull = tagBuffer
|
||||||
|
tagBuffer = null
|
||||||
|
const tagName = getTagName(tagFull)
|
||||||
|
if (tagFull[1] === '/') {
|
||||||
|
handleClose(tagFull)
|
||||||
|
} else if (emptyElements.has(tagName) || tagFull[tagFull.length - 2] === '/') {
|
||||||
|
// self-closing
|
||||||
|
handleSelfClosing(tagFull)
|
||||||
|
} else {
|
||||||
|
handleOpen(tagFull)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
textBuffer += char
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tagBuffer) {
|
||||||
|
textBuffer += tagBuffer
|
||||||
|
}
|
||||||
|
|
||||||
|
flushText()
|
||||||
|
return buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extracts tag name from tag, i.e. <span a="b"> => span
|
||||||
|
export const getTagName = (tag) => {
|
||||||
|
const result = /(?:<\/(\w+)>|<(\w+)\s?.*?\/?>)/gi.exec(tag)
|
||||||
|
return result && (result[1] || result[2])
|
||||||
|
}
|
||||||
|
|
||||||
|
export const processTextForEmoji = (text, emojis, processor) => {
|
||||||
|
const buffer = []
|
||||||
|
let textBuffer = ''
|
||||||
|
for (let i = 0; i < text.length; i++) {
|
||||||
|
const char = text[i]
|
||||||
|
if (char === ':') {
|
||||||
|
const next = text.slice(i + 1)
|
||||||
|
let found = false
|
||||||
|
for (let emoji of emojis) {
|
||||||
|
if (next.slice(0, emoji.shortcode.length + 1) === (emoji.shortcode + ':')) {
|
||||||
|
found = emoji
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
buffer.push(textBuffer)
|
||||||
|
textBuffer = ''
|
||||||
|
buffer.push(processor(found))
|
||||||
|
i += found.shortcode.length + 1
|
||||||
|
} else {
|
||||||
|
textBuffer += char
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
textBuffer += char
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (textBuffer) buffer.push(textBuffer)
|
||||||
|
return buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getAttrs = tag => {
|
||||||
|
const innertag = tag
|
||||||
|
.substring(1, tag.length - 1)
|
||||||
|
.replace(new RegExp('^' + getTagName(tag)), '')
|
||||||
|
.replace(/\/?$/, '')
|
||||||
|
.trim()
|
||||||
|
const attrs = Array.from(innertag.matchAll(/([a-z0-9-]+)(?:=("[^"]+?"|'[^']+?'))?/gi))
|
||||||
|
.map(([trash, key, value]) => [key, value])
|
||||||
|
.map(([k, v]) => {
|
||||||
|
if (!v) return [k, true]
|
||||||
|
return [k, v.substring(1, v.length - 1)]
|
||||||
|
})
|
||||||
|
return Object.fromEntries(attrs)
|
||||||
|
}
|
|
@ -0,0 +1,166 @@
|
||||||
|
import { convertHtml, processTextForEmoji, getAttrs } from 'src/services/mini_html_converter/mini_html_converter.service.js'
|
||||||
|
|
||||||
|
describe('MiniHtmlConverter', () => {
|
||||||
|
describe('convertHtml', () => {
|
||||||
|
it('converts html into a tree structure', () => {
|
||||||
|
const input = '1 <p>2</p> <b>3<img src="a">4</b>5'
|
||||||
|
expect(convertHtml(input)).to.eql([
|
||||||
|
'1 ',
|
||||||
|
[
|
||||||
|
'<p>',
|
||||||
|
['2'],
|
||||||
|
'</p>'
|
||||||
|
],
|
||||||
|
' ',
|
||||||
|
[
|
||||||
|
'<b>',
|
||||||
|
[
|
||||||
|
'3',
|
||||||
|
['<img src="a">'],
|
||||||
|
'4'
|
||||||
|
],
|
||||||
|
'</b>'
|
||||||
|
],
|
||||||
|
'5'
|
||||||
|
])
|
||||||
|
})
|
||||||
|
it('converts html to tree while preserving tag formatting', () => {
|
||||||
|
const input = '1 <p >2</p><b >3<img src="a">4</b>5'
|
||||||
|
expect(convertHtml(input)).to.eql([
|
||||||
|
'1 ',
|
||||||
|
[
|
||||||
|
'<p >',
|
||||||
|
['2'],
|
||||||
|
'</p>'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'<b >',
|
||||||
|
[
|
||||||
|
'3',
|
||||||
|
['<img src="a">'],
|
||||||
|
'4'
|
||||||
|
],
|
||||||
|
'</b>'
|
||||||
|
],
|
||||||
|
'5'
|
||||||
|
])
|
||||||
|
})
|
||||||
|
it('converts semi-broken html', () => {
|
||||||
|
const input = '1 <br> 2 <p> 42'
|
||||||
|
expect(convertHtml(input)).to.eql([
|
||||||
|
'1 ',
|
||||||
|
['<br>'],
|
||||||
|
' 2 ',
|
||||||
|
[
|
||||||
|
'<p>',
|
||||||
|
[' 42']
|
||||||
|
]
|
||||||
|
])
|
||||||
|
})
|
||||||
|
it('realistic case 1', () => {
|
||||||
|
const input = '<p><span class="h-card"><a class="u-url mention" data-user="9wRC6T2ZZiKWJ0vUi8" href="https://cawfee.club/users/benis" rel="ugc">@<span>benis</span></a></span> <span class="h-card"><a class="u-url mention" data-user="194" href="https://shigusegubu.club/users/hj" rel="ugc">@<span>hj</span></a></span> nice</p>'
|
||||||
|
expect(convertHtml(input)).to.eql([
|
||||||
|
[
|
||||||
|
'<p>',
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'<span class="h-card">',
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'<a class="u-url mention" data-user="9wRC6T2ZZiKWJ0vUi8" href="https://cawfee.club/users/benis" rel="ugc">',
|
||||||
|
[
|
||||||
|
'@',
|
||||||
|
[
|
||||||
|
'<span>',
|
||||||
|
[
|
||||||
|
'benis'
|
||||||
|
],
|
||||||
|
'</span>'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'</a>'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'</span>'
|
||||||
|
],
|
||||||
|
' ',
|
||||||
|
[
|
||||||
|
'<span class="h-card">',
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'<a class="u-url mention" data-user="194" href="https://shigusegubu.club/users/hj" rel="ugc">',
|
||||||
|
[
|
||||||
|
'@',
|
||||||
|
[
|
||||||
|
'<span>',
|
||||||
|
[
|
||||||
|
'hj'
|
||||||
|
],
|
||||||
|
'</span>'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'</a>'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'</span>'
|
||||||
|
],
|
||||||
|
' nice'
|
||||||
|
],
|
||||||
|
'</p>'
|
||||||
|
]
|
||||||
|
])
|
||||||
|
})
|
||||||
|
it('realistic case 2', () => {
|
||||||
|
const inputOutput = 'Country improv: give me a city<br/>Audience: Memphis<br/>Improv troupe: come on, a better one<br/>Audience: el paso'
|
||||||
|
expect(convertHtml(inputOutput)).to.eql([
|
||||||
|
'Country improv: give me a city',
|
||||||
|
[
|
||||||
|
'<br/>'
|
||||||
|
],
|
||||||
|
'Audience: Memphis',
|
||||||
|
[
|
||||||
|
'<br/>'
|
||||||
|
],
|
||||||
|
'Improv troupe: come on, a better one',
|
||||||
|
[
|
||||||
|
'<br/>'
|
||||||
|
],
|
||||||
|
'Audience: el paso'
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('processTextForEmoji', () => {
|
||||||
|
it('processes all emoji in text', () => {
|
||||||
|
const input = 'Hello from finland! :lol: We have best water! :lmao:'
|
||||||
|
const emojis = [
|
||||||
|
{ shortcode: 'lol', src: 'LOL' },
|
||||||
|
{ shortcode: 'lmao', src: 'LMAO' }
|
||||||
|
]
|
||||||
|
const processor = ({ shortcode, src }) => ({ shortcode, src })
|
||||||
|
expect(processTextForEmoji(input, emojis, processor)).to.eql([
|
||||||
|
'Hello from finland! ',
|
||||||
|
{ shortcode: 'lol', src: 'LOL' },
|
||||||
|
' We have best water! ',
|
||||||
|
{ shortcode: 'lmao', src: 'LMAO' }
|
||||||
|
])
|
||||||
|
})
|
||||||
|
it('leaves text as is', () => {
|
||||||
|
const input = 'Number one: that\'s terror'
|
||||||
|
const emojis = []
|
||||||
|
const processor = ({ shortcode, src }) => ({ shortcode, src })
|
||||||
|
expect(processTextForEmoji(input, emojis, processor)).to.eql([
|
||||||
|
'Number one: that\'s terror'
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('getAttrs', () => {
|
||||||
|
it('extracts arguments from tag', () => {
|
||||||
|
const input = '<img src="boop" cool ebin=\'true\'>'
|
||||||
|
const output = { src: 'boop', cool: true, ebin: 'true' }
|
||||||
|
|
||||||
|
expect(getAttrs(input)).to.eql(output)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
81
yarn.lock
81
yarn.lock
|
@ -1011,23 +1011,86 @@
|
||||||
resolved "https://registry.yarnpkg.com/@ungap/event-target/-/event-target-0.1.0.tgz#88d527d40de86c4b0c99a060ca241d755999915b"
|
resolved "https://registry.yarnpkg.com/@ungap/event-target/-/event-target-0.1.0.tgz#88d527d40de86c4b0c99a060ca241d755999915b"
|
||||||
integrity sha512-W2oyj0Fe1w/XhPZjkI3oUcDUAmu5P4qsdT2/2S8aMhtAWM/CE/jYWtji0pKNPDfxLI75fa5gWSEmnynKMNP/oA==
|
integrity sha512-W2oyj0Fe1w/XhPZjkI3oUcDUAmu5P4qsdT2/2S8aMhtAWM/CE/jYWtji0pKNPDfxLI75fa5gWSEmnynKMNP/oA==
|
||||||
|
|
||||||
"@vue/babel-helper-vue-jsx-merge-props@^1.0.0":
|
"@vue/babel-helper-vue-jsx-merge-props@^1.2.1":
|
||||||
version "1.0.0"
|
version "1.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.0.0.tgz#048fe579958da408fb7a8b2a3ec050b50a661040"
|
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.2.1.tgz#31624a7a505fb14da1d58023725a4c5f270e6a81"
|
||||||
integrity sha512-6tyf5Cqm4m6v7buITuwS+jHzPlIPxbFzEhXR5JGZpbrvOcp1hiQKckd305/3C7C36wFekNTQSxAtgeM0j0yoUw==
|
integrity sha512-QOi5OW45e2R20VygMSNhyQHvpdUwQZqGPc748JLGCYEy+yp8fNFNdbNIGAgZmi9e+2JHPd6i6idRuqivyicIkA==
|
||||||
|
|
||||||
"@vue/babel-plugin-transform-vue-jsx@^1.1.2":
|
"@vue/babel-plugin-transform-vue-jsx@^1.2.1":
|
||||||
version "1.1.2"
|
version "1.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/@vue/babel-plugin-transform-vue-jsx/-/babel-plugin-transform-vue-jsx-1.1.2.tgz#c0a3e6efc022e75e4247b448a8fc6b86f03e91c0"
|
resolved "https://registry.yarnpkg.com/@vue/babel-plugin-transform-vue-jsx/-/babel-plugin-transform-vue-jsx-1.2.1.tgz#646046c652c2f0242727f34519d917b064041ed7"
|
||||||
integrity sha512-YfdaoSMvD1nj7+DsrwfTvTnhDXI7bsuh+Y5qWwvQXlD24uLgnsoww3qbiZvWf/EoviZMrvqkqN4CBw0W3BWUTQ==
|
integrity sha512-HJuqwACYehQwh1fNT8f4kyzqlNMpBuUK4rSiSES5D4QsYncv5fxFsLyrxFPG2ksO7t5WP+Vgix6tt6yKClwPzA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/helper-module-imports" "^7.0.0"
|
"@babel/helper-module-imports" "^7.0.0"
|
||||||
"@babel/plugin-syntax-jsx" "^7.2.0"
|
"@babel/plugin-syntax-jsx" "^7.2.0"
|
||||||
"@vue/babel-helper-vue-jsx-merge-props" "^1.0.0"
|
"@vue/babel-helper-vue-jsx-merge-props" "^1.2.1"
|
||||||
html-tags "^2.0.0"
|
html-tags "^2.0.0"
|
||||||
lodash.kebabcase "^4.1.1"
|
lodash.kebabcase "^4.1.1"
|
||||||
svg-tags "^1.0.0"
|
svg-tags "^1.0.0"
|
||||||
|
|
||||||
|
"@vue/babel-preset-jsx@^1.2.4":
|
||||||
|
version "1.2.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/@vue/babel-preset-jsx/-/babel-preset-jsx-1.2.4.tgz#92fea79db6f13b01e80d3a0099e2924bdcbe4e87"
|
||||||
|
integrity sha512-oRVnmN2a77bYDJzeGSt92AuHXbkIxbf/XXSE3klINnh9AXBmVS1DGa1f0d+dDYpLfsAKElMnqKTQfKn7obcL4w==
|
||||||
|
dependencies:
|
||||||
|
"@vue/babel-helper-vue-jsx-merge-props" "^1.2.1"
|
||||||
|
"@vue/babel-plugin-transform-vue-jsx" "^1.2.1"
|
||||||
|
"@vue/babel-sugar-composition-api-inject-h" "^1.2.1"
|
||||||
|
"@vue/babel-sugar-composition-api-render-instance" "^1.2.4"
|
||||||
|
"@vue/babel-sugar-functional-vue" "^1.2.2"
|
||||||
|
"@vue/babel-sugar-inject-h" "^1.2.2"
|
||||||
|
"@vue/babel-sugar-v-model" "^1.2.3"
|
||||||
|
"@vue/babel-sugar-v-on" "^1.2.3"
|
||||||
|
|
||||||
|
"@vue/babel-sugar-composition-api-inject-h@^1.2.1":
|
||||||
|
version "1.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-composition-api-inject-h/-/babel-sugar-composition-api-inject-h-1.2.1.tgz#05d6e0c432710e37582b2be9a6049b689b6f03eb"
|
||||||
|
integrity sha512-4B3L5Z2G+7s+9Bwbf+zPIifkFNcKth7fQwekVbnOA3cr3Pq71q71goWr97sk4/yyzH8phfe5ODVzEjX7HU7ItQ==
|
||||||
|
dependencies:
|
||||||
|
"@babel/plugin-syntax-jsx" "^7.2.0"
|
||||||
|
|
||||||
|
"@vue/babel-sugar-composition-api-render-instance@^1.2.4":
|
||||||
|
version "1.2.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-composition-api-render-instance/-/babel-sugar-composition-api-render-instance-1.2.4.tgz#e4cbc6997c344fac271785ad7a29325c51d68d19"
|
||||||
|
integrity sha512-joha4PZznQMsxQYXtR3MnTgCASC9u3zt9KfBxIeuI5g2gscpTsSKRDzWQt4aqNIpx6cv8On7/m6zmmovlNsG7Q==
|
||||||
|
dependencies:
|
||||||
|
"@babel/plugin-syntax-jsx" "^7.2.0"
|
||||||
|
|
||||||
|
"@vue/babel-sugar-functional-vue@^1.2.2":
|
||||||
|
version "1.2.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-functional-vue/-/babel-sugar-functional-vue-1.2.2.tgz#267a9ac8d787c96edbf03ce3f392c49da9bd2658"
|
||||||
|
integrity sha512-JvbgGn1bjCLByIAU1VOoepHQ1vFsroSA/QkzdiSs657V79q6OwEWLCQtQnEXD/rLTA8rRit4rMOhFpbjRFm82w==
|
||||||
|
dependencies:
|
||||||
|
"@babel/plugin-syntax-jsx" "^7.2.0"
|
||||||
|
|
||||||
|
"@vue/babel-sugar-inject-h@^1.2.2":
|
||||||
|
version "1.2.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-inject-h/-/babel-sugar-inject-h-1.2.2.tgz#d738d3c893367ec8491dcbb669b000919293e3aa"
|
||||||
|
integrity sha512-y8vTo00oRkzQTgufeotjCLPAvlhnpSkcHFEp60+LJUwygGcd5Chrpn5480AQp/thrxVm8m2ifAk0LyFel9oCnw==
|
||||||
|
dependencies:
|
||||||
|
"@babel/plugin-syntax-jsx" "^7.2.0"
|
||||||
|
|
||||||
|
"@vue/babel-sugar-v-model@^1.2.3":
|
||||||
|
version "1.2.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-v-model/-/babel-sugar-v-model-1.2.3.tgz#fa1f29ba51ebf0aa1a6c35fa66d539bc459a18f2"
|
||||||
|
integrity sha512-A2jxx87mySr/ulAsSSyYE8un6SIH0NWHiLaCWpodPCVOlQVODCaSpiR4+IMsmBr73haG+oeCuSvMOM+ttWUqRQ==
|
||||||
|
dependencies:
|
||||||
|
"@babel/plugin-syntax-jsx" "^7.2.0"
|
||||||
|
"@vue/babel-helper-vue-jsx-merge-props" "^1.2.1"
|
||||||
|
"@vue/babel-plugin-transform-vue-jsx" "^1.2.1"
|
||||||
|
camelcase "^5.0.0"
|
||||||
|
html-tags "^2.0.0"
|
||||||
|
svg-tags "^1.0.0"
|
||||||
|
|
||||||
|
"@vue/babel-sugar-v-on@^1.2.3":
|
||||||
|
version "1.2.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-v-on/-/babel-sugar-v-on-1.2.3.tgz#342367178586a69f392f04bfba32021d02913ada"
|
||||||
|
integrity sha512-kt12VJdz/37D3N3eglBywV8GStKNUhNrsxChXIV+o0MwVXORYuhDTHJRKPgLJRb/EY3vM2aRFQdxJBp9CLikjw==
|
||||||
|
dependencies:
|
||||||
|
"@babel/plugin-syntax-jsx" "^7.2.0"
|
||||||
|
"@vue/babel-plugin-transform-vue-jsx" "^1.2.1"
|
||||||
|
camelcase "^5.0.0"
|
||||||
|
|
||||||
"@vue/test-utils@^1.0.0-beta.26":
|
"@vue/test-utils@^1.0.0-beta.26":
|
||||||
version "1.0.0-beta.28"
|
version "1.0.0-beta.28"
|
||||||
resolved "https://registry.yarnpkg.com/@vue/test-utils/-/test-utils-1.0.0-beta.28.tgz#767c43413df8cde86128735e58923803e444b9a5"
|
resolved "https://registry.yarnpkg.com/@vue/test-utils/-/test-utils-1.0.0-beta.28.tgz#767c43413df8cde86128735e58923803e444b9a5"
|
||||||
|
|
Loading…
Add table
Reference in a new issue