From b2081866fd6d5e03cc672d7f0c71e35446a07747 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 13 Feb 2021 16:51:48 +0100 Subject: Improve description list rendering --- file.c | 30 ++++++++++++++++++++++-------- html.c | 3 ++- html.h | 2 ++ tagtable.tab | 2 ++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/file.c b/file.c index 79f140a..0cf9b4e 100644 --- a/file.c +++ b/file.c @@ -4662,7 +4662,6 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) do_blankline(h_env, obuf, envs[h_env->envc].indent, 0, h_env->limit); } - PUSH_ENV(cmd); if (parsedtag_exists(tag, ATTR_COMPACT)) envs[h_env->envc].env = HTML_DL_COMPACT; obuf->flag |= RB_IGNORE_P; @@ -4754,15 +4753,14 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) return 1; case HTML_DT: CLOSE_A; - if (h_env->envc == 0 || - (h_env->envc_real < h_env->nenv && - envs[h_env->envc].env != HTML_DL && - envs[h_env->envc].env != HTML_DL_COMPACT)) { - PUSH_ENV(HTML_DL); + if (h_env->envc > 0 && + (envs[h_env->envc].env == HTML_DL || + envs[h_env->envc].env == HTML_DL_COMPACT)) { + POP_ENV; } - if (h_env->envc > 0) { + if (h_env->envc >= 0) { flushline(h_env, obuf, - envs[h_env->envc - 1].indent, 0, h_env->limit); + envs[h_env->envc].indent, 0, h_env->limit); } if (!(obuf->flag & RB_IN_DT)) { HTMLlineproc1("", h_env); @@ -4770,6 +4768,14 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) } obuf->flag |= RB_IGNORE_P; return 1; + case HTML_N_DT: + if (!(obuf->flag & RB_IN_DT)) + return 1; + obuf->flag &= ~RB_IN_DT; + HTMLlineproc1("", h_env); + flushline(h_env, obuf, envs[h_env->envc].indent, 0, + h_env->limit); + return 1; case HTML_DD: CLOSE_A; CLOSE_DT; @@ -4790,6 +4796,14 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) flushline(h_env, obuf, envs[h_env->envc].indent, 0, h_env->limit); /* obuf->flag |= RB_IGNORE_P; */ return 1; + case HTML_N_DD: + if (h_env->envc > 0 && + (envs[h_env->envc].env == HTML_DL || + envs[h_env->envc].env == HTML_DL_COMPACT)) { + POP_ENV; + flushline(h_env, obuf, envs[h_env->envc].indent, 0, h_env->limit); + } + return 1; case HTML_TITLE: close_anchor(h_env, obuf); process_title(tag); diff --git a/html.c b/html.c index 7499191..5d25cd3 100644 --- a/html.c +++ b/html.c @@ -274,8 +274,9 @@ TagInfo TagMAP[MAX_HTMLTAG] = { {"/figcaption", NULL, 0, TFLG_END}, /* 144 HTML_N_FIGCAPTION */ {"section", ALST_NOP, MAXA_NOP, 0}, /* 145 HTML_SECTION */ {"/section", NULL, 0, TFLG_END}, /* 146 HTML_N_SECTION */ + {"/dt", NULL, 0, TFLG_END}, /* 147 HTML_N_DT */ + {"/dd", NULL, 0, TFLG_END}, /* 147 HTML_N_DD */ - {NULL, NULL, 0, 0}, /* 147 Undefined */ {NULL, NULL, 0, 0}, /* 148 Undefined */ {NULL, NULL, 0, 0}, /* 149 Undefined */ {NULL, NULL, 0, 0}, /* 150 Undefined */ diff --git a/html.h b/html.h index a03df19..749e7ef 100644 --- a/html.h +++ b/html.h @@ -238,6 +238,8 @@ typedef struct { #define HTML_N_FIGCAPTION 144 #define HTML_SECTION 145 #define HTML_N_SECTION 146 +#define HTML_N_DT 147 +#define HTML_N_DD 148 /* pseudo tag */ #define HTML_SELECT_INT 160 diff --git a/tagtable.tab b/tagtable.tab index cc94942..774fde9 100644 --- a/tagtable.tab +++ b/tagtable.tab @@ -203,6 +203,8 @@ select_int HTML_SELECT_INT option_int HTML_OPTION_INT section HTML_SECTION /section HTML_N_SECTION +/dt HTML_N_DT +/dd HTML_N_DD textarea_int HTML_TEXTAREA_INT /textarea_int HTML_N_TEXTAREA_INT pre_plain HTML_PRE_PLAIN -- cgit v1.2.3 From ef34bf837c90b124fe5d8f0a058fda3b2d1da170 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 13 Feb 2021 16:53:01 +0100 Subject:
test --- tests/dl.expected | 18 ++++++++++++++++++ tests/dl.html | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tests/dl.expected create mode 100644 tests/dl.html diff --git a/tests/dl.expected b/tests/dl.expected new file mode 100644 index 0000000..f411a5e --- /dev/null +++ b/tests/dl.expected @@ -0,0 +1,18 @@ +w3m +WWW wo miru + A pager with web browsing capabilities, + maintained for Debian. + +Firefox +(linebreak) + +FF +. + A free, open source, cross-platform, + graphical web browser developed by the + Mozilla Corporation and hundreds of + volunteers. + The Red Panda also known as the Lesser + Panda, Wah, Bear Cat or Firefox, is a + mostly herbivorous mammal, slightly larger + than a domestic cat (60 cm long). diff --git a/tests/dl.html b/tests/dl.html new file mode 100644 index 0000000..c60e6e1 --- /dev/null +++ b/tests/dl.html @@ -0,0 +1,23 @@ +
+
w3m
+
WWW wo miru
+
+ A pager with web browsing capabilities,
+ maintained for Debian. +
+

Firefox
(linebreak)

+
FF
+ . +
+ A free, open source, cross-platform,
+ graphical web browser developed by the
+ Mozilla Corporation and hundreds of
+ volunteers. +
+
+ The Red Panda also known as the Lesser
+ Panda, Wah, Bear Cat or Firefox, is a
+ mostly herbivorous mammal, slightly larger
+ than a domestic cat (60 cm long). +
+
-- cgit v1.2.3 From 77ecf9b46b4b3ff7f1bafe3c0a914ba74527af47 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 13 Feb 2021 17:26:30 +0100 Subject: Fix
--- file.c | 46 +++++++++++++++++++++++++++++++--------------- tests/dl.expected | 19 ++++++++++++++++++- tests/dl.html | 24 +++++++++++++++++++++++- 3 files changed, 72 insertions(+), 17 deletions(-) diff --git a/file.c b/file.c index 0cf9b4e..9473993 100644 --- a/file.c +++ b/file.c @@ -4399,6 +4399,13 @@ process_idattr(struct readbuffer *obuf, int cmd, struct parsed_tag *tag) envs[h_env->envc].indent = envs[h_env->envc - 1].indent; \ } +#define PUSH_ENV_NOINDENT(cmd) \ + if (++h_env->envc_real < h_env->nenv) { \ + ++h_env->envc; \ + envs[h_env->envc].env = cmd; \ + envs[h_env->envc].count = 0; \ + } + #define POP_ENV \ if (h_env->envc_real-- < h_env->nenv) \ h_env->envc--; @@ -4662,6 +4669,7 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) do_blankline(h_env, obuf, envs[h_env->envc].indent, 0, h_env->limit); } + PUSH_ENV_NOINDENT(cmd); if (parsedtag_exists(tag, ATTR_COMPACT)) envs[h_env->envc].env = HTML_DL_COMPACT; obuf->flag |= RB_IGNORE_P; @@ -4753,14 +4761,15 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) return 1; case HTML_DT: CLOSE_A; - if (h_env->envc > 0 && - (envs[h_env->envc].env == HTML_DL || - envs[h_env->envc].env == HTML_DL_COMPACT)) { - POP_ENV; + if (h_env->envc == 0 || + (h_env->envc_real < h_env->nenv && + envs[h_env->envc].env != HTML_DL && + envs[h_env->envc].env != HTML_DL_COMPACT)) { + PUSH_ENV_NOINDENT(HTML_DL); } - if (h_env->envc >= 0) { + if (h_env->envc > 0) { flushline(h_env, obuf, - envs[h_env->envc].indent, 0, h_env->limit); + envs[h_env->envc - 1].indent, 0, h_env->limit); } if (!(obuf->flag & RB_IN_DT)) { HTMLlineproc1("", h_env); @@ -4769,12 +4778,14 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) obuf->flag |= RB_IGNORE_P; return 1; case HTML_N_DT: - if (!(obuf->flag & RB_IN_DT)) + if (!(obuf->flag & RB_IN_DT)) { return 1; + } obuf->flag &= ~RB_IN_DT; HTMLlineproc1("", h_env); - flushline(h_env, obuf, envs[h_env->envc].indent, 0, - h_env->limit); + if (h_env->envc > 0 && envs[h_env->envc].env == HTML_DL) + flushline(h_env, obuf, + envs[h_env->envc - 1].indent, 0, h_env->limit); return 1; case HTML_DD: CLOSE_A; @@ -4785,6 +4796,11 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) envs[h_env->envc].env != HTML_DL_COMPACT)) { PUSH_ENV(HTML_DL); } + if (h_env->envc <= MAX_INDENT_LEVEL) + envs[h_env->envc].indent = envs[h_env->envc - 1].indent + INDENT_INCR; + else + envs[h_env->envc].indent = envs[h_env->envc - 1].indent; + if (envs[h_env->envc].env == HTML_DL_COMPACT) { if (obuf->pos > envs[h_env->envc].indent) flushline(h_env, obuf, envs[h_env->envc].indent, 0, @@ -4797,12 +4813,12 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) /* obuf->flag |= RB_IGNORE_P; */ return 1; case HTML_N_DD: - if (h_env->envc > 0 && - (envs[h_env->envc].env == HTML_DL || - envs[h_env->envc].env == HTML_DL_COMPACT)) { - POP_ENV; - flushline(h_env, obuf, envs[h_env->envc].indent, 0, h_env->limit); - } + if (h_env->envc == 0 || + (h_env->envc_real < h_env->nenv && + envs[h_env->envc].env != HTML_DL && + envs[h_env->envc].env != HTML_DL_COMPACT)) + return 1; + envs[h_env->envc].indent = envs[h_env->envc - 1].indent - INDENT_INCR; return 1; case HTML_TITLE: close_anchor(h_env, obuf); diff --git a/tests/dl.expected b/tests/dl.expected index f411a5e..4e828ea 100644 --- a/tests/dl.expected +++ b/tests/dl.expected @@ -3,11 +3,27 @@ WWW wo miru A pager with web browsing capabilities, maintained for Debian. +Firefox +(linebreak) +FF A free, open source, cross-platform, + graphical web browser developed by the + Mozilla Corporation and hundreds of + volunteers. + The Red Panda also known as the Lesser + Panda, Wah, Bear Cat or Firefox, is a + mostly herbivorous mammal, slightly larger + than a domestic cat (60 cm long). + +Non-compact dl +w3m +WWW wo miru + A pager with web browsing capabilities, + maintained for Debian. + Firefox (linebreak) FF -. A free, open source, cross-platform, graphical web browser developed by the Mozilla Corporation and hundreds of @@ -16,3 +32,4 @@ FF Panda, Wah, Bear Cat or Firefox, is a mostly herbivorous mammal, slightly larger than a domestic cat (60 cm long). + diff --git a/tests/dl.html b/tests/dl.html index c60e6e1..4824a8a 100644 --- a/tests/dl.html +++ b/tests/dl.html @@ -1,4 +1,27 @@ +
+
w3m
+
WWW wo miru
+
+ A pager with web browsing capabilities,
+ maintained for Debian. +
+

Firefox
(linebreak)

+
FF
+
+ A free, open source, cross-platform,
+ graphical web browser developed by the
+ Mozilla Corporation and hundreds of
+ volunteers. +
+
+ The Red Panda also known as the Lesser
+ Panda, Wah, Bear Cat or Firefox, is a
+ mostly herbivorous mammal, slightly larger
+ than a domestic cat (60 cm long). +
+
+ Non-compact dl
w3m
WWW wo miru
@@ -7,7 +30,6 @@

Firefox
(linebreak)

FF
- .
A free, open source, cross-platform,
graphical web browser developed by the
-- cgit v1.2.3 From 116e10749c42b4e073239c71fc44a4eaedd9c042 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 13 Feb 2021 18:02:26 +0100 Subject: Nested
s --- file.c | 13 ++++++++----- tests/dl.expected | 2 ++ tests/dl.html | 11 +++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/file.c b/file.c index 9473993..55f115a 100644 --- a/file.c +++ b/file.c @@ -4404,6 +4404,7 @@ process_idattr(struct readbuffer *obuf, int cmd, struct parsed_tag *tag) ++h_env->envc; \ envs[h_env->envc].env = cmd; \ envs[h_env->envc].count = 0; \ + envs[h_env->envc].indent = envs[h_env->envc - 1].indent; \ } #define POP_ENV \ @@ -4652,7 +4653,7 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) h_env->limit); POP_ENV; if (!(obuf->flag & RB_PREMODE) && - (h_env->envc == 0 || cmd == HTML_N_DL || cmd == HTML_N_BLQ)) { + (h_env->envc == 0 || cmd == HTML_N_BLQ)) { do_blankline(h_env, obuf, envs[h_env->envc].indent, INDENT_INCR, h_env->limit); @@ -4665,7 +4666,9 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) CLOSE_A; if (!(obuf->flag & RB_IGNORE_P)) { flushline(h_env, obuf, envs[h_env->envc].indent, 0, h_env->limit); - if (!(obuf->flag & RB_PREMODE)) + if (!(obuf->flag & RB_PREMODE) && envs[h_env->envc].env != HTML_DL + && envs[h_env->envc].env != HTML_DL_COMPACT + && envs[h_env->envc].env != HTML_DD) do_blankline(h_env, obuf, envs[h_env->envc].indent, 0, h_env->limit); } @@ -4796,10 +4799,9 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) envs[h_env->envc].env != HTML_DL_COMPACT)) { PUSH_ENV(HTML_DL); } + if (h_env->envc <= MAX_INDENT_LEVEL) envs[h_env->envc].indent = envs[h_env->envc - 1].indent + INDENT_INCR; - else - envs[h_env->envc].indent = envs[h_env->envc - 1].indent; if (envs[h_env->envc].env == HTML_DL_COMPACT) { if (obuf->pos > envs[h_env->envc].indent) @@ -4818,7 +4820,8 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) envs[h_env->envc].env != HTML_DL && envs[h_env->envc].env != HTML_DL_COMPACT)) return 1; - envs[h_env->envc].indent = envs[h_env->envc - 1].indent - INDENT_INCR; + envs[h_env->envc].indent = envs[h_env->envc].indent - INDENT_INCR; + flushline(h_env, obuf, envs[h_env->envc].indent, 0, h_env->limit); return 1; case HTML_TITLE: close_anchor(h_env, obuf); diff --git a/tests/dl.expected b/tests/dl.expected index 4e828ea..b7af148 100644 --- a/tests/dl.expected +++ b/tests/dl.expected @@ -28,6 +28,8 @@ FF graphical web browser developed by the Mozilla Corporation and hundreds of volunteers. + nested + com item The Red Panda also known as the Lesser Panda, Wah, Bear Cat or Firefox, is a mostly herbivorous mammal, slightly larger diff --git a/tests/dl.html b/tests/dl.html index 4824a8a..618eef4 100644 --- a/tests/dl.html +++ b/tests/dl.html @@ -35,6 +35,17 @@ graphical web browser developed by the
Mozilla Corporation and hundreds of
volunteers. +
+
nested
+
+
+
com
+
+ item +
+
+
+
The Red Panda also known as the Lesser
-- cgit v1.2.3 From c8eb20b9510221172879e698b76dcd32238b378b Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 13 Feb 2021 21:49:25 +0100 Subject: Fix a mistake I made with
and tags --- html.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/html.c b/html.c index 5d25cd3..3573ef6 100644 --- a/html.c +++ b/html.c @@ -275,9 +275,8 @@ TagInfo TagMAP[MAX_HTMLTAG] = { {"section", ALST_NOP, MAXA_NOP, 0}, /* 145 HTML_SECTION */ {"/section", NULL, 0, TFLG_END}, /* 146 HTML_N_SECTION */ {"/dt", NULL, 0, TFLG_END}, /* 147 HTML_N_DT */ - {"/dd", NULL, 0, TFLG_END}, /* 147 HTML_N_DD */ + {"/dd", NULL, 0, TFLG_END}, /* 148 HTML_N_DD */ - {NULL, NULL, 0, 0}, /* 148 Undefined */ {NULL, NULL, 0, 0}, /* 149 Undefined */ {NULL, NULL, 0, 0}, /* 150 Undefined */ {NULL, NULL, 0, 0}, /* 151 Undefined */ -- cgit v1.2.3