redraft fixed, fix #224
This commit is contained in:
parent
0a1156c137
commit
4269ca2700
|
@ -195,4 +195,18 @@ describe('CreateStatusComponent', () => {
|
|||
expect(result[1].length).toBeLessThanOrEqual(527);
|
||||
expect(result[1]).toBe('http://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/');
|
||||
});
|
||||
|
||||
it('should tranform external mentions properly - mastodon', () => {
|
||||
let mastodonMention = '<p>test <span class="h-card"><a href="https://mastodon.social/@sengi_app" class="u-url mention">@<span>sengi_app</span></a></span> qsdqds qsd qsd qsd q <span class="h-card"><a href="https://mastodon.social/@test" class="u-url mention">@<span>test</span></a></span> <span class="h-card"><a href="https://mastodon.social/@no" class="u-url">@<span>no</span></a></span></p>';
|
||||
|
||||
const result = <string>(<any>component).tranformHtmlRepliesToReplies(mastodonMention);
|
||||
expect(result).toBe('<p>test @sengi_app@mastodon.social qsdqds qsd qsd qsd q @test@mastodon.social <span class="h-card"><a href="https://mastodon.social/@no" class="u-url">@<span>no</span></a></span></p>');
|
||||
});
|
||||
|
||||
it('should tranform external mentions properly - pleroma', () => {
|
||||
let pleromaMention = '<p>test <span class="h-card"><a data-user="50504" class="u-url mention" href="https://mastodon.social/@sengi_app" rel="ugc">@<span>sengi_app</span></a></span> qsdqds qsd qsd qsd q <span class="h-card"><a data-user="50504" class="u-url mention" href="https://mastodon.social/@test" rel="ugc">@<span>test</span></a></span> <span class="h-card"><a href="https://mastodon.social/@no" class="u-url">@<span>no</span></a></span></p>';
|
||||
|
||||
const result = <string>(<any>component).tranformHtmlRepliesToReplies(pleromaMention);
|
||||
expect(result).toBe('<p>test @sengi_app@mastodon.social qsdqds qsd qsd qsd q @test@mastodon.social <span class="h-card"><a href="https://mastodon.social/@no" class="u-url">@<span>no</span></a></span></p>');
|
||||
});
|
||||
});
|
|
@ -79,33 +79,23 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
|
||||
@Input('redraftedStatus')
|
||||
set redraftedStatus(value: StatusWrapper) {
|
||||
if (value) {
|
||||
console.warn(value.status.content);
|
||||
if (value) {
|
||||
this.statusLoaded = false;
|
||||
let parser = new DOMParser();
|
||||
|
||||
const newLine = String.fromCharCode(13, 10);
|
||||
let content = value.status.content;
|
||||
|
||||
content = this.tranformHtmlRepliesToReplies(content);
|
||||
|
||||
while (content.includes('<p>') || content.includes('</p>') || content.includes('<br>') || content.includes('<br/>') || content.includes('<br />')) {
|
||||
content = content.replace('<p>', '').replace('</p>', newLine + newLine).replace('<br />', newLine).replace('<br/>', newLine).replace('<br>', newLine);
|
||||
}
|
||||
|
||||
content = this.trim(content, newLine);
|
||||
|
||||
// let splitedContent = content.replace('<p>', '').split('</p>').forEach(x => x.split('<br>'));
|
||||
// let splitedContentRendered = [];
|
||||
// splitedContent.forEach(c => {
|
||||
// var dom = parser.parseFromString(c, 'text/html')
|
||||
// splitedContentRendered.push(dom.body.textContent);
|
||||
// });
|
||||
|
||||
|
||||
let parser = new DOMParser();
|
||||
var dom = parser.parseFromString(content, 'text/html')
|
||||
this.status = dom.body.textContent;
|
||||
// this.status = '';
|
||||
// splitedContentRendered.forEach(element => {
|
||||
// this.status += element + String.fromCharCode(13, 10);
|
||||
// });
|
||||
console.warn(this.status);
|
||||
|
||||
this.statusStateService.setStatusContent(this.status, this.statusReplyingToWrapper);
|
||||
|
||||
|
@ -856,4 +846,19 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
|
|||
this.scheduleIsActive = !this.scheduleIsActive;
|
||||
return false;
|
||||
}
|
||||
|
||||
private tranformHtmlRepliesToReplies(data: string): string {
|
||||
const mastodonMentionRegex = /<span class="h-card"><a href="https:\/\/([a-zA-Z0-9\/.]{0,255})\/@([a-zA-Z0-9_-]{0,255})" class="u-url mention">@<span>[a-zA-Z0-9_-]{0,255}<\/span><\/a><\/span>/gmi;
|
||||
const pleromaMentionRegex = /<span class="h-card"><a data-user="[a-zA-Z0-9]{0,255}" class="u-url mention" href="https:\/\/([a-zA-Z0-9\/.]{0,255})\/@([a-zA-Z0-9_-]{0,255})" rel="ugc">@<span>[a-zA-Z0-9_-]{0,255}<\/span><\/a><\/span>/gmi;
|
||||
|
||||
while(data.match(mastodonMentionRegex)){
|
||||
data = data.replace(mastodonMentionRegex, '@$2@$1');
|
||||
}
|
||||
|
||||
while(data.match(pleromaMentionRegex)){
|
||||
data = data.replace(pleromaMentionRegex, '@$2@$1');
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue