Skip to content

Commit

Permalink
better link parsing in pleroma
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasConstant committed May 25, 2019
1 parent 9b129ae commit 0418ee6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,12 @@ describe('DatabindedTextComponent', () => {

component.text = sample;
expect(component.processedText).toContain('<p>Bla <a href class="link-httpscloudblogsmicrosoftcomopensource20190521servicemeshinterfacesmirelease" title="open link">cloudblogs.microsoft.com/opens</a></p>');
})
});

it('should parse link 2 - Pleroma', () => {
const sample = `Bla<br /><br /><a href="https://link/">https://link/</a>`;

component.text = sample;
expect(component.processedText).toContain('Bla<br /><br /><a href class="link-httpslink" title="open link">https://link/</a>');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,26 @@ export class DatabindedTextComponent implements OnInit {
this.processHashtag(section);
}
catch (err) {
console.warn('process hashtag');
console.warn(value);
console.error('error processing hashtag');
console.error(value);
}

} else if (section.includes('class="u-url mention"') || section.includes('class="mention"') || section.includes('class="mention status-link"') || section.includes('class="h-card mention')) {
try {
this.processUser(section);
}
catch (err) {
console.warn('process mention');
console.warn(value);
console.error('error processing mention');
console.error(value);
}
} else {
try {
this.processLink(section);
//this.processedText += `<a ${section}`;
}
catch (err) {
console.warn('process link');
console.warn(value);
console.error('error processing link');
console.error(value);
}
}
}
Expand Down Expand Up @@ -133,7 +133,11 @@ export class DatabindedTextComponent implements OnInit {
try {
extractedName = extractedLinkAndNext[0].split(' target="_blank">')[1].split('</span>')[0];
} catch (err) { // Pleroma
extractedName = extractedLinkAndNext[0].split('</span><span>')[1].split('</span>')[0];
try {
extractedName = extractedLinkAndNext[0].split('</span><span>')[1].split('</span>')[0];
} catch (err) {
extractedName = extractedLinkAndNext[0].split('">')[1];
}
}
}
}
Expand Down

0 comments on commit 0418ee6

Please sign in to comment.