* mdocml: implement the roff(7) \p (break output line) escape sequence
@ 2017-06-14 1:31 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-06-14 1:31 UTC (permalink / raw)
To: source
Log Message:
-----------
implement the roff(7) \p (break output line) escape sequence
Modified Files:
--------------
mdocml:
html.c
mandoc.c
mandoc.h
mdoc_markdown.c
roff.7
term.c
mdocml/regress/roff/esc:
Makefile
Added Files:
-----------
mdocml/regress/roff/esc:
p.in
p.out_ascii
Revision Data
-------------
Index: mdoc_markdown.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_markdown.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -Lmdoc_markdown.c -Lmdoc_markdown.c -u -p -r1.22 -r1.23
--- mdoc_markdown.c
+++ mdoc_markdown.c
@@ -493,7 +493,7 @@ md_word(const char *s)
{
const char *seq, *prevfont, *currfont, *nextfont;
char c;
- int bs, sz, uc;
+ int bs, sz, uc, breakline;
/* No spacing before closing delimiters. */
if (s[0] != '\0' && s[1] == '\0' &&
@@ -510,6 +510,7 @@ md_word(const char *s)
if ((s[0] == '(' || s[0] == '[') && s[1] == '\0')
outflags &= ~MD_spc;
+ breakline = 0;
prevfont = currfont = "";
while ((c = *s++) != '\0') {
bs = 0;
@@ -595,6 +596,9 @@ md_word(const char *s)
case ESCAPE_FONTPREV:
nextfont = prevfont;
break;
+ case ESCAPE_BREAK:
+ breakline = 1;
+ break;
case ESCAPE_NOSPACE:
case ESCAPE_SKIPCHAR:
case ESCAPE_OVERSTRIKE:
@@ -642,6 +646,13 @@ md_word(const char *s)
if (bs)
putchar('\\');
md_char(c);
+ if (breakline &&
+ (*s == '\0' || *s == ' ' || *s == ASCII_NBRSP)) {
+ printf(" \n");
+ breakline = 0;
+ while (*s == ' ' || *s == ASCII_NBRSP)
+ s++;
+ }
}
if (*currfont != '\0') {
outflags &= ~MD_spc;
Index: mandoc.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandoc.h,v
retrieving revision 1.229
retrieving revision 1.230
diff -Lmandoc.h -Lmandoc.h -u -p -r1.229 -r1.230
--- mandoc.h
+++ mandoc.h
@@ -423,6 +423,7 @@ enum mandoc_esc {
ESCAPE_FONTPREV, /* previous font mode */
ESCAPE_NUMBERED, /* a numbered glyph */
ESCAPE_UNICODE, /* a unicode codepoint */
+ ESCAPE_BREAK, /* break the output line */
ESCAPE_NOSPACE, /* suppress space if the last on a line */
ESCAPE_HORIZ, /* horizontal movement */
ESCAPE_HLINE, /* horizontal line drawing */
Index: roff.7
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.7,v
retrieving revision 1.87
retrieving revision 1.88
diff -Lroff.7 -Lroff.7 -u -p -r1.87 -r1.88
--- roff.7
+++ roff.7
@@ -1991,6 +1991,8 @@ Overstrike, writing all the characters c
to the same output position.
In terminal and HTML output modes,
only the last one of the characters is visible.
+.Ss \ep
+Break the output line at the end of the current word.
.Ss \eR\(aq Ns Ar name Oo +|- Oc Ns Ar number Ns \(aq
Set number register; ignored by
.Xr mandoc 1 .
Index: mandoc.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandoc.c,v
retrieving revision 1.101
retrieving revision 1.102
diff -Lmandoc.c -Lmandoc.c -u -p -r1.101 -r1.102
--- mandoc.c
+++ mandoc.c
@@ -96,6 +96,8 @@ mandoc_escape(const char **end, const ch
case ',':
case '/':
return ESCAPE_IGNORE;
+ case 'p':
+ return ESCAPE_BREAK;
/*
* The \z escape is supposed to output the following
Index: html.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/html.c,v
retrieving revision 1.213
retrieving revision 1.214
diff -Lhtml.c -Lhtml.c -u -p -r1.213 -r1.214
--- html.c
+++ html.c
@@ -345,16 +345,18 @@ static int
print_encode(struct html *h, const char *p, const char *pend, int norecurse)
{
char numbuf[16];
- size_t sz;
- int c, len, nospace;
+ struct tag *t;
const char *seq;
+ size_t sz;
+ int c, len, breakline, nospace;
enum mandoc_esc esc;
- static const char rejs[9] = { '\\', '<', '>', '&', '"',
+ static const char rejs[10] = { ' ', '\\', '<', '>', '&', '"',
ASCII_NBRSP, ASCII_HYPH, ASCII_BREAK, '\0' };
if (pend == NULL)
pend = strchr(p, '\0');
+ breakline = 0;
nospace = 0;
while (p < pend) {
@@ -365,14 +367,28 @@ print_encode(struct html *h, const char
}
for (sz = strcspn(p, rejs); sz-- && p < pend; p++)
- if (*p == ' ')
- print_endword(h);
- else
- print_byte(h, *p);
+ print_byte(h, *p);
+
+ if (breakline &&
+ (p >= pend || *p == ' ' || *p == ASCII_NBRSP)) {
+ t = print_otag(h, TAG_DIV, "");
+ print_text(h, "\\~");
+ print_tagq(h, t);
+ breakline = 0;
+ while (p < pend && (*p == ' ' || *p == ASCII_NBRSP))
+ p++;
+ continue;
+ }
if (p >= pend)
break;
+ if (*p == ' ') {
+ print_endword(h);
+ p++;
+ continue;
+ }
+
if (print_escape(h, *p++))
continue;
@@ -417,6 +433,9 @@ print_encode(struct html *h, const char
if (c <= 0)
continue;
break;
+ case ESCAPE_BREAK:
+ breakline = 1;
+ continue;
case ESCAPE_NOSPACE:
if ('\0' == *p)
nospace = 1;
Index: term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/term.c,v
retrieving revision 1.269
retrieving revision 1.270
diff -Lterm.c -Lterm.c -u -p -r1.269 -r1.270
--- term.c
+++ term.c
@@ -116,6 +116,7 @@ term_flushln(struct termp *p)
size_t jhy; /* last hyph before overflow w/r/t j */
size_t maxvis; /* output position of visible boundary */
int ntab; /* number of tabs to prepend */
+ int breakline; /* after this word */
vbl = (p->flags & TERMP_NOPAD) || p->tcol->offset < p->viscol ?
0 : p->tcol->offset - p->viscol;
@@ -155,7 +156,13 @@ term_flushln(struct termp *p)
*/
jhy = 0;
+ breakline = 0;
for (j = p->tcol->col; j < p->tcol->lastcol; j++) {
+ if (p->tcol->buf[j] == '\n') {
+ if ((p->flags & TERMP_BRIND) == 0)
+ breakline = 1;
+ continue;
+ }
if (p->tcol->buf[j] == ' ' || p->tcol->buf[j] == '\t')
break;
@@ -221,6 +228,8 @@ term_flushln(struct termp *p)
for ( ; p->tcol->col < p->tcol->lastcol; p->tcol->col++) {
if (vend > bp && jhy > 0 && p->tcol->col > jhy)
break;
+ if (p->tcol->buf[p->tcol->col] == '\n')
+ continue;
if (p->tcol->buf[p->tcol->col] == '\t')
break;
if (p->tcol->buf[p->tcol->col] == ' ') {
@@ -260,6 +269,26 @@ term_flushln(struct termp *p)
p->tcol->buf[p->tcol->col]);
}
vis = vend;
+
+ if (breakline == 0)
+ continue;
+
+ /* Explicitly requested output line break. */
+
+ if (p->flags & TERMP_MULTICOL)
+ return;
+
+ endline(p);
+ breakline = 0;
+ vis = vend = 0;
+
+ /* Re-establish indentation. */
+
+ vbl = p->tcol->offset;
+ maxvis = p->tcol->rmargin > vbl ?
+ p->tcol->rmargin - vbl : 0;
+ bp = !(p->flags & TERMP_NOBREAK) ? maxvis :
+ p->maxrmargin > vbl ? p->maxrmargin - vbl : 0;
}
/*
@@ -486,6 +515,9 @@ term_word(struct termp *p, const char *w
continue;
case ESCAPE_FONTPREV:
term_fontlast(p);
+ continue;
+ case ESCAPE_BREAK:
+ bufferc(p, '\n');
continue;
case ESCAPE_NOSPACE:
if (p->flags & TERMP_BACKAFTER)
--- /dev/null
+++ regress/roff/esc/p.out_ascii
@@ -0,0 +1,19 @@
+ESC-P(1) General Commands Manual ESC-P(1)
+
+N\bNA\bAM\bME\bE
+ e\bes\bsc\bc-\b-p\bp - line break escape sequence
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ no blank: line oneline
+ two
+
+ blank after esc: line one
+ line two
+
+ blank before esc: line one line
+ two
+
+ at eol: line one
+ line two
+
+OpenBSD June 14, 2017 OpenBSD
Index: Makefile
===================================================================
RCS file: /home/cvs/mdocml/mdocml/regress/roff/esc/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/roff/esc/Makefile -Lregress/roff/esc/Makefile -u -p -r1.1 -r1.2
--- regress/roff/esc/Makefile
+++ regress/roff/esc/Makefile
@@ -1,6 +1,6 @@
# $OpenBSD: Makefile,v 1.11 2015/04/29 18:32:57 schwarze Exp $
-REGRESS_TARGETS = one two multi B c c_man e f h o w z ignore
+REGRESS_TARGETS = one two multi B c c_man e f h o p w z ignore
LINT_TARGETS = B h w ignore
.include <bsd.regress.mk>
--- /dev/null
+++ regress/roff/esc/p.in
@@ -0,0 +1,15 @@
+.Dd June 14, 2017
+.Dt ESC-P 1
+.Os OpenBSD
+.Sh NAME
+.Nm esc-p
+.Nd line break escape sequence
+.Sh DESCRIPTION
+no blank: line one\pline two
+.Pp
+blank after esc: line one\p line two
+.Pp
+blank before esc: line one \pline two
+.Pp
+at eol: line one\p
+line two
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-06-14 1:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-14 1:31 mdocml: implement the roff(7) \p (break output line) escape sequence schwarze
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).