Skip to content

Commit

Permalink
Add --template to -tman, -tms.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapsdz committed Dec 10, 2024
1 parent a7ff58c commit 554237d
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 8 deletions.
28 changes: 24 additions & 4 deletions man/lowdown-diff.1
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ See
.Sx Templates .
This is experimental functionality.
Currently only for
.Fl t Ns Ar html
.Fl t Ns Ar html ,
.Fl t Ns Ar latex ,
.Fl t Ns Ar man ,
and
.Fl t Ns Ar latex .
.Fl t Ns Ar ms .
.El
.Pp
What follows are per-output long options.
Expand Down Expand Up @@ -905,10 +907,18 @@ If transforms are invalid, they will transform into an empty list.
The following transformations are available:
.Bl -tag -width Ds
.It Li escapehtml , escapehtmlattr , escapehtmlurl
Escape list items for HTML body content, attributes, and URL attributes,
Escape list items for HTML
.Pq Fl t Ns Ar html
body content, attributes, and URL attributes,
respectively.
.It Li escapelatex
Escape list items for LaTeX body content.
Escape list items for LaTeX
.Pq Fl t Ns Ar latex
body content.
.It Li escaperoff , esaperoffline
Escape list items for roff
.Pq Fl t Ns Ar ms , Fl t Ns Ar man ,
either for multiple lines or compressed to a single line.
.It Li join
Join a list into a singleton list using two spaces as a join delimiter.
.It Li lowercase
Expand Down Expand Up @@ -951,6 +961,16 @@ The default template used if
.Fl -template
is not provided to
.Fl t Ns Ar latex .
.It Pa share/man/default.man
The default template used if
.Fl -template
is not provided to
.Fl t Ns Ar man .
.It Pa share/man/default.ms
The default template used if
.Fl -template
is not provided to
.Fl t Ns Ar ms .
.It Pa share/odt/styles.xml
Default styles used when generating standalone
.Fl t Ns Ar fodt
Expand Down
28 changes: 24 additions & 4 deletions man/lowdown.1
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,11 @@ See
.Sx Templates .
This is experimental functionality.
Currently only for
.Fl t Ns Ar html
.Fl t Ns Ar html ,
.Fl t Ns Ar latex ,
.Fl t Ns Ar man ,
and
.Fl t Ns Ar latex .
.Fl t Ns Ar ms .
.El
.Pp
What follows are per-output long options.
Expand Down Expand Up @@ -898,10 +900,18 @@ If transforms are invalid, they will transform into an empty list.
The following transformations are available:
.Bl -tag -width Ds
.It Li escapehtml , escapehtmlattr , escapehtmlurl
Escape list items for HTML body content, attributes, and URL attributes,
Escape list items for HTML
.Pq Fl t Ns Ar html
body content, attributes, and URL attributes,
respectively.
.It Li escapelatex
Escape list items for LaTeX body content.
Escape list items for LaTeX
.Pq Fl t Ns Ar latex
body content.
.It Li escaperoff , esaperoffline
Escape list items for roff
.Pq Fl t Ns Ar ms , Fl t Ns Ar man ,
either for multiple lines or compressed to a single line.
.It Li join
Join a list into a singleton list using two spaces as a join delimiter.
.It Li lowercase
Expand Down Expand Up @@ -944,6 +954,16 @@ The default template used if
.Fl -template
is not provided to
.Fl t Ns Ar latex .
.It Pa share/man/default.man
The default template used if
.Fl -template
is not provided to
.Fl t Ns Ar man .
.It Pa share/man/default.ms
The default template used if
.Fl -template
is not provided to
.Fl t Ns Ar ms .
.It Pa share/odt/styles.xml
Default styles used when generating standalone
.Fl t Ns Ar fodt
Expand Down
6 changes: 6 additions & 0 deletions share/man/default.man
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.\" -*- mode: troff; coding: utf-8 -*-"
$ifdef(manheader)--$
$manheader$
$endif--$
.TH "$title.escaperoffline$" "$section.escaperoffline$" "$date.escaperoffline$" $ifdef(or(source,volume))$"$source.escaperoffline$" "$volume.escaperoffline$"$endif$
$body--$
21 changes: 21 additions & 0 deletions share/ms/default.ms
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.\" -*- mode: troff; coding: utf-8 -*-"
$ifdef(copyright)--$
.ds LF Copyright \(co $copyright.escaperoffline$
$endif--$
$ifdef(and(date,copyright))--$
.ds RF $date.escaperoffline$
$endif--$
$ifdef(and(date,not(copyright)))--$
.DA $date.escaperoffline$
$endif--$
$ifdef(msheader)--$
$msheader$
$endif--$
.TL $title.escaperoffline$
$for(author.split())--$
.AU $this.escaperoffline$
$endfor--$
$for(affiliation.split())--$
.AI $this.escaperoffline$
$endfor--$
$body--$
43 changes: 43 additions & 0 deletions template.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,45 @@ op_eval_function_escape_latex(const struct lowdown_metaq *mq,
return NULL;
}

/*
* HTML-escape (for general content) all characters in all list items.
* Returns NULL on allocation failure.
*/
static struct op_resq *
op_eval_function_escape_roff(const struct lowdown_metaq *mq,
const struct op_resq *input, int oneline)
{
struct op_resq *nq = NULL;
struct op_res *nres;
const struct op_res *res;
struct lowdown_buf *buf;

if ((buf = hbuf_new(32)) == NULL)
goto err;
if ((nq = malloc(sizeof(struct op_resq))) == NULL)
goto err;
TAILQ_INIT(nq);

TAILQ_FOREACH(res, input, entries) {
hbuf_truncate(buf);
if (!lowdown_nroff_esc(buf, res->res, strlen(res->res),
oneline, 0))
goto err;
if ((nres = calloc(1, sizeof(struct op_res))) == NULL)
goto err;
TAILQ_INSERT_TAIL(nq, nres, entries);
nres->res = strndup(buf->data, buf->size);
if (nres->res == NULL)
goto err;
}
hbuf_free(buf);
return nq;
err:
hbuf_free(buf);
op_resq_free(nq);
return NULL;
}

/*
* HTML-escape (for general content) all characters in all list items.
* Returns NULL on allocation failure.
Expand Down Expand Up @@ -678,6 +717,10 @@ op_eval_function(const char *expr, size_t exprsz, const char *args,
nq = op_eval_function_escape_htmlattr(mq, input);
else if (exprsz == 13 && strncasecmp(expr, "escapehtmlurl", 13) == 0)
nq = op_eval_function_escape_htmlurl(mq, input);
else if (exprsz == 10 && strncasecmp(expr, "escaperoff", 10) == 0)
nq = op_eval_function_escape_roff(mq, input, 0);
else if (exprsz == 14 && strncasecmp(expr, "escaperoffline", 14) == 0)
nq = op_eval_function_escape_roff(mq, input, 1);
else if ((nq = malloc(sizeof(struct op_resq))) != NULL)
TAILQ_INIT(nq);

Expand Down

0 comments on commit 554237d

Please sign in to comment.