mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-12-24 16:43:36 +00:00
More work in not_really_markdown().
This commit is contained in:
parent
25258ed379
commit
4f3b70d997
4 changed files with 64 additions and 4 deletions
4
Makefile
4
Makefile
|
@ -17,11 +17,11 @@ dep:
|
|||
activitypub.o: activitypub.c xs.h xs_encdec.h xs_json.h xs_curl.h \
|
||||
xs_mime.h xs_openssl.h snac.h
|
||||
data.o: data.c xs.h xs_io.h xs_json.h xs_openssl.h snac.h
|
||||
html.o: html.c xs.h xs_io.h xs_json.h snac.h
|
||||
html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h snac.h
|
||||
http.o: http.c xs.h xs_io.h xs_encdec.h xs_openssl.h xs_curl.h snac.h
|
||||
httpd.o: httpd.c xs.h xs_io.h xs_encdec.h xs_json.h xs_socket.h \
|
||||
xs_httpd.h snac.h
|
||||
main.o: main.c xs.h xs_io.h xs_encdec.h xs_json.h snac.h
|
||||
snac.o: snac.c xs.h xs_io.h xs_encdec.h xs_json.h xs_curl.h xs_openssl.h \
|
||||
xs_socket.h xs_httpd.h xs_mime.h snac.h
|
||||
xs_socket.h xs_httpd.h xs_mime.h xs_regex.h snac.h
|
||||
webfinger.o: webfinger.c xs.h xs_encdec.h xs_json.h xs_curl.h snac.h
|
||||
|
|
60
html.c
60
html.c
|
@ -4,6 +4,7 @@
|
|||
#include "xs.h"
|
||||
#include "xs_io.h"
|
||||
#include "xs_json.h"
|
||||
#include "xs_regex.h"
|
||||
|
||||
#include "snac.h"
|
||||
|
||||
|
@ -15,11 +16,66 @@ d_char *not_really_markdown(char *content, d_char **f_content)
|
|||
int in_blq = 0;
|
||||
xs *list;
|
||||
char *p, *v;
|
||||
xs *wrk = xs_dup(content);
|
||||
|
||||
/* global changes */
|
||||
{
|
||||
/* backticks */
|
||||
xs *ml = xs_regex_matchall(wrk, "`[^`]+`");
|
||||
p = ml;
|
||||
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
xs *s1 = xs_crop(xs_dup(v), 1, -1);
|
||||
xs *s2 = xs_fmt("<code>%s</code>", s1);
|
||||
|
||||
wrk = xs_replace_i(wrk, v, s2);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
/* double asterisks */
|
||||
xs *ml = xs_regex_matchall(wrk, "\\*\\*[^\\*]+\\*\\*");
|
||||
p = ml;
|
||||
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
xs *s1 = xs_crop(xs_dup(v), 2, -2);
|
||||
xs *s2 = xs_fmt("<b>%s</b>", s1);
|
||||
|
||||
wrk = xs_replace_i(wrk, v, s2);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
/* single asterisks */
|
||||
xs *ml = xs_regex_matchall(wrk, "\\*[^\\*]+\\*");
|
||||
p = ml;
|
||||
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
xs *s1 = xs_crop(xs_dup(v), 1, -1);
|
||||
xs *s2 = xs_fmt("<i>%s</i>", s1);
|
||||
|
||||
wrk = xs_replace_i(wrk, v, s2);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
/* urls */
|
||||
xs *ml = xs_regex_matchall(wrk, "https?:/" "/[^ ]+");
|
||||
p = ml;
|
||||
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
xs *s2 = xs_fmt("<a href=\"%s\">%s</a>", v, v);
|
||||
|
||||
wrk = xs_replace_i(wrk, v, s2);
|
||||
}
|
||||
}
|
||||
|
||||
/* now work on lines */
|
||||
|
||||
p = list = xs_split(wrk, "\n");
|
||||
|
||||
s = xs_str_new(NULL);
|
||||
|
||||
p = list = xs_split(content, "\n");
|
||||
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
xs *ss = xs_strip(xs_dup(v));
|
||||
|
||||
|
|
3
httpd.c
3
httpd.c
|
@ -79,6 +79,9 @@ int server_get_handler(d_char *req, char *q_path,
|
|||
*ctype = "image/png";
|
||||
}
|
||||
|
||||
if (status != 0)
|
||||
srv_debug(1, xs_fmt("server_get_handler '%s' %d", q_path, status));
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
|
1
snac.c
1
snac.c
|
@ -12,6 +12,7 @@
|
|||
#include "xs_socket.h"
|
||||
#include "xs_httpd.h"
|
||||
#include "xs_mime.h"
|
||||
#include "xs_regex.h"
|
||||
|
||||
#include "snac.h"
|
||||
|
||||
|
|
Loading…
Reference in a new issue