fun restrained

This commit is contained in:
Henry Jameson 2022-11-26 23:38:06 +02:00
parent 045a222183
commit 7fed35a627
2 changed files with 8 additions and 6 deletions

View File

@ -179,7 +179,7 @@ export default {
break break
} }
case 'span': case 'span':
if (this.handleLinks && attrs['class'] && attrs['class'].includes('h-card')) { if (this.handleLinks && attrs.class && attrs.class.includes('h-card')) {
return ['', children.map(processItem), ''] return ['', children.map(processItem), '']
} }
} }
@ -213,13 +213,13 @@ export default {
const [opener, children] = item const [opener, children] = item
const Tag = opener === '' ? '' : getTagName(opener) const Tag = opener === '' ? '' : getTagName(opener)
switch (Tag) { switch (Tag) {
case 'a': // replace mentions with MentionLink case 'a': { // replace mentions with MentionLink
if (!this.handleLinks) break if (!this.handleLinks) break
const attrs = getAttrs(opener) const attrs = getAttrs(opener)
// should only be this // should only be this
if ( if (
(attrs['class'] && attrs['class'].includes('hashtag')) || // Pleroma style (attrs.class && attrs.class.includes('hashtag')) || // Pleroma style
(attrs['rel'] === 'tag') // Mastodon style (attrs.rel === 'tag') // Mastodon style
) { ) {
return renderHashtag(attrs, children, encounteredTextReverse) return renderHashtag(attrs, children, encounteredTextReverse)
} else { } else {
@ -230,6 +230,7 @@ export default {
{ newChildren } { newChildren }
</a> </a>
} }
}
case '': case '':
return [...children].reverse().map(processItemReverse).reverse() return [...children].reverse().map(processItemReverse).reverse()
} }

View File

@ -16,7 +16,7 @@ export const getTagName = (tag) => {
* @return {Object} - map of attributes key = attribute name, value = attribute value * @return {Object} - map of attributes key = attribute name, value = attribute value
* attributes without values represented as boolean true * attributes without values represented as boolean true
*/ */
export const getAttrs = tag => { export const getAttrs = (tag, filter) => {
const innertag = tag const innertag = tag
.substring(1, tag.length - 1) .substring(1, tag.length - 1)
.replace(new RegExp('^' + getTagName(tag)), '') .replace(new RegExp('^' + getTagName(tag)), '')
@ -28,7 +28,8 @@ export const getAttrs = tag => {
if (!v) return [k, true] if (!v) return [k, true]
return [k, v.substring(1, v.length - 1)] return [k, v.substring(1, v.length - 1)]
}) })
return Object.fromEntries(attrs) const defaultFilter = ([k, v]) => (k.toLowerCase() !== 'class' && k.toLowerCase() !== 'style')
return Object.fromEntries(attrs.filter(filter || defaultFilter))
} }
/** /**