AmendHub

Download:

jcs

/

wikipedia

/

amendments

/

25

wikipedia: Basic support for {{convert}}

There are hundreds of possible conversions, so just print the
value and unit and hope it makes sense. For things like "9|in"
we print "9 in", but there are a lot of possible conversions that
won't print nicely. Oh well.
 
Also recognize {| and |} for tables, treated like {{ and }}.

jcs made amendment 25 about 1 year ago
--- wikipedia.c Mon Sep 5 22:53:18 2022 +++ wikipedia.c Mon Sep 5 23:27:57 2022 @@ -205,6 +205,9 @@ get_char: c = req->chunk[req->chunk_off]; last = wpr->buf + wpr->buf_len - 1; + if (c == '<' || c == '\0') + goto done_parsing; + /* character conversions */ if (c == ';') { @@ -289,12 +292,12 @@ get_char: /* check for style changes */ - if (last[0] == '{' && c == '{') { + if (last[0] == '{' && (c == '{' || c == '|')) { wpr->curlys++; wpr->buf_len--; wpr->style |= STYLE_TEMPLATE; c = 0; - } else if (last[0] == '}' && c == '}') { + } else if ((last[0] == '}' || last[0] == '|') && c == '}') { if (wpr->curlys) wpr->curlys--; wpr->buf_len--; @@ -384,9 +387,29 @@ get_char: */ if (wpr->style != wpr->last_style) { - if (wpr->last_style & (STYLE_REF | STYLE_TEMPLATE)) - wpr->buf_len = 0; + if (wpr->last_style & STYLE_TEMPLATE) { + if (strncmp(wpr->buf, "convert|", 8) == 0) { + /* convert|5.1|lb|... */ + /* convert|9|in|cm|adj=on */ + char *conv = xmalloc(wpr->buf_len, "convert"); + char *conv2 = xmalloc(wpr->buf_len, "convert"); + size_t len; + wpr->buf[wpr->buf_len] = '\0'; + if (sscanf(wpr->buf, "convert|%[^|]|%[^|]|%n", conv, conv2, + &len) == 2 && len >= 13) + wpr->buf_len = sprintf(wpr->buf, "%s %s ", conv, conv2); + else + wpr->buf_len = 0; + xfree(&conv); + xfree(&conv2); + } else + wpr->buf_len = 0; + } + /* maybe we can do something with these later */ + if (wpr->last_style & STYLE_REF) + wpr->buf_len = 0; + if (wpr->last_style & (STYLE_TEMPLATE | STYLE_H1 | STYLE_H2 | STYLE_H3 | STYLE_H4 | STYLE_H5)) wpr->trim_whitespace = true;