Use converse-rich-text
component to render unfurl descriptions
This commit is contained in:
parent
f897596215
commit
c2a6b09a25
@ -7,7 +7,7 @@ export default (o) => {
|
||||
${ o.image && u.isImageDomainAllowed(o.image) ? html`<a href="${o.url}" target="_blank" rel="noopener"><img class="card-img-top" src="${o.image}" @load=${o.onload}/></a>` : '' }
|
||||
<div class="card-body">
|
||||
<a href="${o.url}" target="_blank" rel="noopener"><h5 class="card-title">${o.title}</h5></a>
|
||||
<p class="card-text">${u.addHyperlinks(o.description)}</p>
|
||||
<p class="card-text"><converse-rich-text text=${o.description}></converse-rich-text></p>
|
||||
<p class="card-text"><a href="${o.url}" target="_blank" rel="noopener">${u.getURI(o.url).domain()}</a></p>
|
||||
</div>
|
||||
</div>`;
|
||||
|
@ -356,38 +356,6 @@ u.filterQueryParamsFromURL = function (url) {
|
||||
return parsed_uri.removeQuery(paramsArray).toString();
|
||||
};
|
||||
|
||||
u.addHyperlinks = function (text) {
|
||||
const objs = [];
|
||||
const parse_options = { 'start': /\b(?:([a-z][a-z0-9.+-]*:\/\/)|xmpp:|mailto:|www\.)/gi };
|
||||
try {
|
||||
URI.withinString(text, (url, start, end) => {
|
||||
objs.push({url, start, end})
|
||||
return url;
|
||||
} , parse_options);
|
||||
} catch (error) {
|
||||
log.debug(error);
|
||||
return [text];
|
||||
}
|
||||
|
||||
let list = [text];
|
||||
if (objs.length) {
|
||||
objs.sort((a, b) => b.start - a.start)
|
||||
.forEach(url_obj => {
|
||||
const text = list.shift();
|
||||
const url_text = text.slice(url_obj.start, url_obj.end);
|
||||
list = [
|
||||
text.slice(0, url_obj.start),
|
||||
u.convertUrlToHyperlink(url_text),
|
||||
text.slice(url_obj.end),
|
||||
...list
|
||||
];
|
||||
});
|
||||
} else {
|
||||
list = [text];
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
u.httpToGeoUri = function(text, _converse) {
|
||||
const replacement = 'geo:$1,$2';
|
||||
return text.replace(_converse.api.settings.get("geouri_regex"), replacement);
|
||||
|
Loading…
Reference in New Issue
Block a user