From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: pod2mdoc: Pick out the first B<> as an Nm when in SYNOPSIS.
Date: Wed, 2 Apr 2014 10:50:09 -0400 (EDT) [thread overview]
Message-ID: <201404021450.s32Eo9VW009961@krisdoz.my.domain> (raw)
Log Message:
-----------
Pick out the first B<> as an Nm when in SYNOPSIS.
Document all of these tricks in the manpage.
Modified Files:
--------------
pod2mdoc:
pod2mdoc.1
pod2mdoc.c
Revision Data
-------------
Index: pod2mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/pod2mdoc/pod2mdoc.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -Lpod2mdoc.c -Lpod2mdoc.c -u -p -r1.14 -r1.15
--- pod2mdoc.c
+++ pod2mdoc.c
@@ -239,7 +239,6 @@ trylink(const char *buf, size_t *start,
return(1);
}
-
/*
* Doclifting: if we're a bold "-xx" and we're in the SYNOPSIS section,
* then it's likely that we're a flag.
@@ -315,13 +314,16 @@ again:
* been printed to the current line.
* If "nomacro", then we don't print any macros, just contained data
* (e.g., following "Sh" or "Nm").
+ * "pos" is only significant in SYNOPSIS, and should be 0 when invoked
+ * as the first format code on a line (for decoration as an "Nm"),
+ * non-zero otherwise.
* Return whether we've printed a macro or not--in other words, whether
* this should trigger a subsequent newline (this should be ignored when
* reentrant).
*/
static int
-formatcode(struct state *st, const char *buf,
- size_t *start, size_t end, int reentrant, int nomacro)
+formatcode(struct state *st, const char *buf, size_t *start,
+ size_t end, int reentrant, int nomacro, int pos)
{
enum fmt fmt;
size_t i, j, dsz;
@@ -430,6 +432,8 @@ formatcode(struct state *st, const char
if (SECT_SYNOPSIS == st->sect) {
if (1 == dsz && '-' == buf[*start])
dosynopsisfl(buf, start, end);
+ else if (0 == pos)
+ printf("Nm ");
else
printf("Ar ");
break;
@@ -482,7 +486,7 @@ formatcode(struct state *st, const char
}
}
if (*start + 1 < end && '<' == buf[*start + 1]) {
- formatcode(st, buf, start, end, 1, nomacro);
+ formatcode(st, buf, start, end, 1, nomacro, 1);
continue;
}
@@ -544,7 +548,7 @@ formatcodeln(struct state *st, const cha
last = ' ';
while (*start < end) {
if (*start + 1 < end && '<' == buf[*start + 1]) {
- formatcode(st, buf, start, end, 1, nomacro);
+ formatcode(st, buf, start, end, 1, nomacro, 1);
continue;
}
/*
@@ -873,6 +877,7 @@ static void
ordinary(struct state *st, const char *buf, size_t start, size_t end)
{
size_t i, j, opstack;
+ int seq;
if ( ! st->parsing || st->paused)
return;
@@ -884,8 +889,8 @@ ordinary(struct state *st, const char *b
* To wit, print out a "Nm" and "Nd" in that format.
*/
if (SECT_NAME == st->sect) {
- for (i = end - 1; i > start; i--)
- if ('-' == buf[i])
+ for (i = end - 2; i > start; i--)
+ if ('-' == buf[i] && ' ' == buf[i + 1])
break;
if ('-' == buf[i]) {
j = i;
@@ -893,11 +898,11 @@ ordinary(struct state *st, const char *b
for ( ; i > start; i--)
if ('-' != buf[i])
break;
- printf(".Nm ");
+ fputs(".Nm ", stdout);
formatcodeln(st, buf, &start, i + 1, 1);
putchar('\n');
start = j + 1;
- printf(".Nd ");
+ fputs(".Nd ", stdout);
formatcodeln(st, buf, &start, end, 1);
putchar('\n');
return;
@@ -911,7 +916,7 @@ ordinary(struct state *st, const char *b
last = '\n';
opstack = 0;
- while (start < end) {
+ for (seq = 0; start < end; seq++) {
/*
* Loop til we get either to a newline or escape.
* Escape initial control characters.
@@ -951,7 +956,7 @@ ordinary(struct state *st, const char *b
* Consume all whitespace so we don't
* accidentally start an implicit literal line.
*/
- if (formatcode(st, buf, &start, end, 0, 0)) {
+ if (formatcode(st, buf, &start, end, 0, 0, seq)) {
putchar(last = '\n');
while (start < end && ' ' == buf[start])
start++;
Index: pod2mdoc.1
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/pod2mdoc/pod2mdoc.1,v
retrieving revision 1.6
retrieving revision 1.7
diff -Lpod2mdoc.1 -Lpod2mdoc.1 -u -p -r1.6 -r1.7
--- pod2mdoc.1
+++ pod2mdoc.1
@@ -89,6 +89,73 @@ or, if the input file suffix is
uses
.Ar 3p .
.El
+.Ss Smarts
+Since
+.Xr mdoc 7
+is semantic and
+.Xr perlpod 1
+is not,
+.Nm
+tries to figure out semantic context for some terms.
+Specifically, within each paragraph of the SYNOPSIS section, the
+following occur:
+.Bl -bullet
+.It
+An initial
+.Li B<>
+format code is rendered as
+.Sq \&Nm .
+.It
+Subsequent
+.Li B<>
+format codes are rendered as
+.Sq \&Ar .
+However, if the leading character of a
+.Li B<>
+format code is
+.Sq - ,
+it is rendered as
+.Sq \&Fl .
+Subsequent space-separated terms without leading hyphens, e.g.,
+.Li B<-foo bar> ,
+are rendered as
+.Sq \&Ar .
+.It
+Matching
+.Li \&[
+and
+.Li \&]
+pairs are rendered as
+.Sq \&Oo
+and
+.Sq \&Oc .
+.El
+.Pp
+Thus, the input
+.Li B<foo> [B<-bar baz>]
+is rendered as follows:
+.Bd -literal
+\&.Nm foo
+\&.Oo
+\&.Fl bar Ar baz
+\&.Oc
+.Ed
+.Pp
+In the NAME section, an
+.Sq \&Nm
+and
+.Sq \&Nd
+macro are inferred from text leading and trailing the last hyphen
+followed by a space (there may be any number of hyphens preceding the
+space).
+The space may occur on either side of the hyphen.
+Thus,
+.Li B<foo> - bar
+will be rendered as follows:
+.Bd -literal
+\&.Nm foo
+\&.Nd bar
+.Ed
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2014-04-02 14:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201404021450.s32Eo9VW009961@krisdoz.my.domain \
--to=kristaps@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).