Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pleroma-fe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pleroma
pleroma-fe
Commits
50dc9df8
Commit
50dc9df8
authored
5 years ago
by
HJ
Browse files
Options
Downloads
Patches
Plain Diff
adds greentext, also small fixes
parent
3dae1cf3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!1028
`master` refresh with `develop`
,
!994
⑨ Added greentext support ⑨
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/status/status.js
+40
-9
40 additions, 9 deletions
src/components/status/status.js
src/services/tiny_post_html_processor/tiny_post_html_processor.service.js
+84
-0
84 additions, 0 deletions
...y_post_html_processor/tiny_post_html_processor.service.js
with
124 additions
and
9 deletions
src/components/status/status.js
+
40
−
9
View file @
50dc9df8
...
...
@@ -13,10 +13,11 @@ import Timeago from '../timeago/timeago.vue'
import
StatusPopover
from
'
../status_popover/status_popover.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
{
processHtml
}
from
'
src/services/tiny_post_html_processor/tiny_post_html_processor.service.js
'
import
{
highlightClass
,
highlightStyle
}
from
'
../../services/user_highlighter/user_highlighter.js
'
import
{
mentionMatchesUrl
,
extractTagFromUrl
}
from
'
src/services/matcher/matcher.service.js
'
import
{
filter
,
unescape
,
uniqBy
}
from
'
lodash
'
import
{
mapGetters
}
from
'
vuex
'
import
{
mapGetters
,
mapState
}
from
'
vuex
'
const
Status
=
{
name
:
'
Status
'
,
...
...
@@ -42,8 +43,8 @@ const Status = {
showingTall
:
this
.
inConversation
&&
this
.
focused
,
showingLongSubject
:
false
,
error
:
null
,
// Initial state
expandingSubject
:
!
this
.
$store
.
getters
.
mergedConfig
.
collapseMessageWithSubject
,
betterShadow
:
this
.
$store
.
state
.
interface
.
browserSupport
.
cssFilter
}
},
computed
:
{
...
...
@@ -103,7 +104,7 @@ const Status = {
return
this
.
$store
.
state
.
statuses
.
allStatusesObject
[
this
.
status
.
id
]
},
loggedIn
()
{
return
!!
this
.
$store
.
state
.
users
.
currentUser
return
!!
this
.
currentUser
},
muteWordHits
()
{
const
statusText
=
this
.
status
.
text
.
toLowerCase
()
...
...
@@ -163,7 +164,7 @@ const Status = {
if
(
this
.
inConversation
||
!
this
.
isReply
)
{
return
false
}
if
(
this
.
status
.
user
.
id
===
this
.
$store
.
state
.
users
.
currentUser
.
id
)
{
if
(
this
.
status
.
user
.
id
===
this
.
currentUser
.
id
)
{
return
false
}
if
(
this
.
status
.
type
===
'
retweet
'
)
{
...
...
@@ -178,7 +179,7 @@ const Status = {
if
(
checkFollowing
&&
taggedUser
&&
taggedUser
.
following
)
{
return
false
}
if
(
this
.
status
.
attentions
[
i
].
id
===
this
.
$store
.
state
.
users
.
currentUser
.
id
)
{
if
(
this
.
status
.
attentions
[
i
].
id
===
this
.
currentUser
.
id
)
{
return
false
}
}
...
...
@@ -255,11 +256,37 @@ const Status = {
maxThumbnails
()
{
return
this
.
mergedConfig
.
maxThumbnails
},
postBodyHtml
()
{
const
html
=
this
.
status
.
statusnet_html
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
}
},
contentHtml
()
{
if
(
!
this
.
status
.
summary_html
)
{
return
this
.
status
.
statusnet_h
tml
return
this
.
postBodyH
tml
}
return
this
.
status
.
summary_html
+
'
<br />
'
+
this
.
status
.
statusnet_h
tml
return
this
.
status
.
summary_html
+
'
<br />
'
+
this
.
postBodyH
tml
},
combinedFavsAndRepeatsUsers
()
{
// Use the status from the global status repository since favs and repeats are saved in it
...
...
@@ -270,7 +297,7 @@ const Status = {
return
uniqBy
(
combinedUsers
,
'
id
'
)
},
ownStatus
()
{
return
this
.
status
.
user
.
id
===
this
.
$store
.
state
.
users
.
currentUser
.
id
return
this
.
status
.
user
.
id
===
this
.
currentUser
.
id
},
tags
()
{
return
this
.
status
.
tags
.
filter
(
tagObj
=>
tagObj
.
hasOwnProperty
(
'
name
'
)).
map
(
tagObj
=>
tagObj
.
name
).
join
(
'
'
)
...
...
@@ -278,7 +305,11 @@ const Status = {
hidePostStats
()
{
return
this
.
mergedConfig
.
hidePostStats
},
...
mapGetters
([
'
mergedConfig
'
])
...
mapGetters
([
'
mergedConfig
'
]),
...
mapState
({
betterShadow
:
state
=>
state
.
interface
.
browserSupport
.
cssFilter
,
currentUser
:
state
=>
state
.
users
.
currentUser
})
},
components
:
{
Attachment
,
...
...
This diff is collapsed.
Click to expand it.
src/services/tiny_post_html_processor/tiny_post_html_processor.service.js
0 → 100644
+
84
−
0
View file @
50dc9df8
/**
* This is a tiny purpose-built HTML parser/processor. This basically detects any type of visual newline and
* allows it to be processed, useful for greentexting, mostly
*
* @param {Object} input - input data
* @param {(string) => string} processor - function that will be called on every line
* @return {string} processed html
*/
export
const
processHtml
=
(
html
,
processor
)
=>
{
const
handledTags
=
new
Set
([
'
p
'
,
'
br
'
,
'
div
'
])
const
openCloseTags
=
new
Set
([
'
p
'
,
'
div
'
])
const
tagRegex
=
/
(?:
<
\/(\w
+
)
>|<
(\w
+
)\s?[^/]
*
?\/?
>
)
/gi
let
buffer
=
''
// Current output buffer
const
level
=
[]
// 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
// Extracts tagname from tag, i.e. <span a="b"> => span
const
getTagName
=
(
tag
)
=>
{
// eslint-disable-next-line no-unused-vars
const
result
=
tagRegex
.
exec
(
tag
)
return
result
&&
(
result
[
1
]
||
result
[
2
])
}
const
flush
=
()
=>
{
// Processes current line buffer, adds it to output buffer and clears line buffer
buffer
+=
processor
(
textBuffer
)
textBuffer
=
''
}
const
handleBr
=
(
tag
)
=>
{
// handles single newlines/linebreaks
flush
()
buffer
+=
tag
}
const
handleOpen
=
(
tag
)
=>
{
// handles opening tags
flush
()
buffer
+=
tag
level
.
push
(
tag
)
}
const
handleClose
=
(
tag
)
=>
{
// handles closing tags
flush
()
buffer
+=
tag
if
(
level
[
level
.
length
-
1
]
===
tag
)
{
level
.
pop
()
}
}
for
(
let
i
=
0
;
i
<
html
.
length
;
i
++
)
{
const
char
=
html
[
i
]
if
(
char
===
'
<
'
&&
tagBuffer
!==
null
)
{
tagBuffer
=
char
}
else
if
(
char
!==
'
>
'
&&
tagBuffer
!==
null
)
{
tagBuffer
+=
char
}
else
if
(
char
===
'
>
'
&&
tagBuffer
!==
null
)
{
tagBuffer
+=
char
const
tagName
=
getTagName
(
tagBuffer
)
if
(
handledTags
.
has
(
tagName
))
{
if
(
tagName
===
'
br
'
)
{
handleBr
(
tagBuffer
)
}
if
(
openCloseTags
.
has
(
tagBuffer
))
{
if
(
tagBuffer
[
1
]
===
'
/
'
)
{
handleClose
(
tagBuffer
)
}
else
{
handleOpen
(
tagBuffer
)
}
}
}
else
{
textBuffer
+=
tagBuffer
}
tagBuffer
=
null
}
else
if
(
char
===
'
\n
'
)
{
handleBr
(
char
)
}
else
{
textBuffer
+=
char
}
}
flush
()
return
buffer
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment