From: Michael Göhler Date: Fri, 26 Dec 2014 21:10:13 +0000 (+0100) Subject: make alignment respect pandoc urls, #63 X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=e9663e348e5e5d36b36ec38a582df7df1fc9126b;p=smdp.git make alignment respect pandoc urls, #63 --- diff --git a/include/url.h b/include/url.h index 9088031..1bd3950 100644 --- a/include/url.h +++ b/include/url.h @@ -39,5 +39,6 @@ int url_get_amount(void); void url_purge(void); void url_dump(void); int url_count_inline(const char *line); +int url_len_inline(const char *text); #endif // !defined( URL_H ) diff --git a/src/url.c b/src/url.c index 6872503..c5ffd4b 100644 --- a/src/url.c +++ b/src/url.c @@ -156,3 +156,25 @@ int url_count_inline(const char *line) { return count; } + +int url_len_inline(const char *text) { + int count = 0; + const char *i = text; + + for (; *i; i++) { + if (*i == '\\') { + i++; + } else if ( *i == '[' && *(i+1) != ']') { + while (*i && *i != ']') i++; + i++; + if (*i == '(' && strchr(i, ')')) { + while (*i && *i != ')') { + count++; + i++; + } + } + } + } + + return count; +} diff --git a/src/viewer.c b/src/viewer.c index fa2ea10..0e2da58 100644 --- a/src/viewer.c +++ b/src/viewer.c @@ -98,6 +98,9 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) { if (line && line->text && line->text->text) lc += url_count_inline(line->text->text); + if (line && line->text && line->text->text) + line->length -= url_len_inline(line->text->text); + if(line->length > COLS) { i = line->length; offset = 0;