Commit 9965eb7b authored by Zéfling's avatar Zéfling 🎨
Browse files

Fix highlight URL except in tags

parent 4c587f33
......@@ -204,10 +204,22 @@ export class TweetsService {
match.forEach(
(m: string) => {
const testInTag = new RegExp(`([<]?[^<>]*${Utils.protectPattern(m)}[^<>]*[>]?)`, 'gi');
tweet.html_text.match(testInTag).forEach(frag => {
const frags = tweet.html_text.match(testInTag);
// protect tags
let i = 0;
frags.forEach(frag => {
if (frag.startsWith('<')) {
copy.html_text = copy.html_text.replace(
new RegExp(Utils.protectPattern(frag)),
`␛␞${i++}␞␛`
);
}
});
// replace excepte in tags
frags.forEach(frag => {
if (!frag.startsWith('<')) {
copy.html_text = copy.html_text.replace(
frag,
new RegExp(Utils.protectPattern(frag)),
frag.replace(
new RegExp(Utils.protectPattern(m), 'gi'),
`<span class="key">${m}</span>`
......@@ -215,6 +227,16 @@ export class TweetsService {
);
}
});
// deprotect tags
i = 0;
frags.forEach(frag => {
if (frag.startsWith('<')) {
copy.html_text = copy.html_text.replace(
new RegExp(Utils.protectPattern(`␛␞${i++}␞␛`)),
frag
);
}
});
}
);
result.push(copy);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment