parent
f4b019eff0
commit
7b35934e18
@ -1 +1 @@
|
||||
Subproject commit c5b4f6e732131995377c1a40b9fba1f86845e519
|
||||
Subproject commit 3bd10ea74624264342c02976abc91a84f87d88ed
|
@ -1,10 +1,64 @@
|
||||
#include "model/status.h"
|
||||
|
||||
#include "model/account.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
#include <ctype.h>
|
||||
|
||||
char* status_render_source( const char* src )
|
||||
char* status_render_source( struct status* s )
|
||||
{
|
||||
return strdup(src);
|
||||
if( s->content ) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
char* result = NULL;
|
||||
size_t size = 0;
|
||||
FILE* f = open_memstream(&result,&size);
|
||||
|
||||
for( char* i = s->source; *i; ++i ) {
|
||||
|
||||
// Handle URLs
|
||||
if( 0 == strncmp( i, "https://", 8 ) ) {
|
||||
char* start = i;
|
||||
while( *i && !index(" ,",*i) ) ++i;
|
||||
|
||||
char* url = strndup( start, i - start );
|
||||
fprintf( f, "<a href='%s' rel='ugc'>%s</a>", url, url );
|
||||
free(url);
|
||||
} else if( isalpha(i[1]) && *i == '@' ) {
|
||||
char* start = i;
|
||||
while( *i && !index(" ,",*i) ) ++i;
|
||||
char* handle = strndup( start, i - start );
|
||||
|
||||
struct account* user = account_from_webfinger( &handle[1] );
|
||||
if( user ) {
|
||||
fprintf( f,
|
||||
"<span class='h-card'>"
|
||||
"<a class='u-url mention' href='%s' rel='ugc'>"
|
||||
"@<span>%s</span>"
|
||||
"</a>"
|
||||
"</span>",
|
||||
user->account_url, user->handle
|
||||
);
|
||||
account_free(user);
|
||||
} else {
|
||||
fprintf( f, "%s", handle );
|
||||
}
|
||||
free(handle);
|
||||
}
|
||||
|
||||
fputc( *i, f );
|
||||
}
|
||||
|
||||
fputc( '\0', f );
|
||||
fclose(f);
|
||||
|
||||
s->content = result;
|
||||
|
||||
done:
|
||||
return s->content;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in new issue