Compare commits

...

2 Commits

Author SHA1 Message Date
eal 6b98434067 Make tests pass. 2017-08-25 11:59:46 +03:00
eal 3c8cf27d34 Add >greentext and <cyantext.
I cannot recommend running it yet.
2017-08-25 11:44:03 +03:00
2 changed files with 28 additions and 0 deletions

View File

@ -83,6 +83,24 @@ export const defaultState = {
}
}
const greentextify = (shtml) => {
let rows = []
const removeMastodon = shtml.replace(/<br>/g, '<br />')
.replace(/<p>/g, '')
.replace(/<\/p>/g, '<br />')
each(removeMastodon.split('<br />'), (row) => {
row = row.replace('\n', '').replace('<span>', '').replace('</span>', '')
if (row.match(/^[ ]?&gt;/)) {
rows.push(`<span class="base0B">${row}</span><br />`)
} else if (row.match(/^[ ]?&lt;/)) {
rows.push(`<span class="base0D">${row}</span><br />`)
} else {
rows.push(`${row}<br />`)
}
})
return rows.join('').replace('<br /><br />', '<br />')
}
const isNsfw = (status) => {
const nsfwRegex = /#nsfw/i
return includes(status.tags, 'nsfw') || !!status.text.match(nsfwRegex)
@ -94,6 +112,12 @@ export const prepareStatus = (status) => {
status.nsfw = isNsfw(status)
}
// add greentext
if (!status.greentextified) {
status.statusnet_html = greentextify(status.statusnet_html)
status.greentextified = true
}
// Set deleted flag
status.deleted = false
@ -137,10 +161,13 @@ const mergeOrAdd = (arr, obj, item) => {
const oldItem = obj[item.id]
if (oldItem) {
// save the greentext to avoid re-processing
const greentext = oldItem.statusnet_html
// We already have this, so only merge the new info.
merge(oldItem, item)
// Reactivity fix.
oldItem.attachments.splice(oldItem.attachments.length)
oldItem.statusnet_html = greentext
return {item: oldItem, new: false}
} else {
// This is a new item, prepare it

View File

@ -8,6 +8,7 @@ const makeMockStatus = ({id, text, is_post_verb = true}) => {
user: {id: 0},
name: 'status',
text: text || `Text number ${id}`,
statusnet_html: `<p> ${text} </p>`,
fave_num: 0,
uri: '',
is_post_verb,