=================================================================== RCS file: /cvs/docbook2mdoc/parse.c,v retrieving revision 1.44 retrieving revision 1.45 diff -u -p -r1.44 -r1.45 --- docbook2mdoc/parse.c 2019/04/14 22:37:56 1.44 +++ docbook2mdoc/parse.c 2019/04/16 14:58:19 1.45 @@ -1,4 +1,4 @@ -/* $Id: parse.c,v 1.44 2019/04/14 22:37:56 schwarze Exp $ */ +/* $Id: parse.c,v 1.45 2019/04/16 14:58:19 schwarze Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * Copyright (c) 2019 Ingo Schwarze @@ -56,6 +56,7 @@ struct parse { int nline; /* Line number of next token. */ int ncol; /* Column number of next token. */ int del; /* Levels of nested nodes being deleted. */ + int nofill; /* Levels of open no-fill displays. */ int flags; #define PFLAG_WARN (1 << 0) /* Print warning messages. */ #define PFLAG_SPC (1 << 1) /* Whitespace before the next element. */ @@ -284,6 +285,7 @@ xml_text(struct parse *p, const char *word, int sz) case CLASS_VOID: case CLASS_TEXT: case CLASS_BLOCK: + case CLASS_NOFILL: np = NULL; break; case CLASS_TRANS: @@ -525,6 +527,9 @@ xml_elem_start(struct parse *p, const char *name) case CLASS_ENCL: n->spc = (p->flags & PFLAG_SPC) != 0; break; + case CLASS_NOFILL: + p->nofill++; + /* FALLTHROUGH */ default: n->spc = 1; break; @@ -649,6 +654,8 @@ xml_elem_end(struct parse *p, const char *name) warn_msg(p, "element not open: ", name); break; } + if (pnode_class(node) == CLASS_NOFILL) + p->nofill--; /* * Refrain from actually closing the document element. @@ -756,11 +763,12 @@ parse_string(struct parse *p, char *b, size_t rlen, enum pstate *pstate, int refill) { char *cp; + size_t pws; /* Parse offset including whitespace. */ size_t poff; /* Parse offset in b[]. */ size_t pend; /* Offset of the end of the current word. */ int elem_end; - pend = 0; + pend = pws = 0; for (;;) { /* Proceed to the next token, skipping whitespace. */ @@ -773,6 +781,8 @@ parse_string(struct parse *p, char *b, size_t rlen, break; if (isspace((unsigned char)b[pend])) { p->flags |= PFLAG_SPC; + if (b[pend] == '\n') + pws = pend + 1; increment(p, b, &pend, refill); continue; } @@ -934,10 +944,13 @@ parse_string(struct parse *p, char *b, size_t rlen, advance(p, b, rlen, &pend, p->ncur == NODE_DOCTYPE ? "<&]\n" : "<&\n", refill); + if (p->nofill) + poff = pws; xml_text(p, b + poff, pend - poff); if (b[pend] == '\n') pnode_closetext(p, 0); } + pws = pend; } return poff; }