From 554237dafb8f92411f7356e770a8dea97166e933 Mon Sep 17 00:00:00 2001 From: Kristaps Dz Date: Tue, 10 Dec 2024 08:17:33 -0800 Subject: [PATCH] Add --template to -tman, -tms. --- man/lowdown-diff.1 | 28 ++++++++++++++++++++++++---- man/lowdown.1 | 28 ++++++++++++++++++++++++---- share/man/default.man | 6 ++++++ share/ms/default.ms | 21 +++++++++++++++++++++ template.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 8 deletions(-) create mode 100644 share/man/default.man create mode 100644 share/ms/default.ms diff --git a/man/lowdown-diff.1 b/man/lowdown-diff.1 index 0669681..cffe500 100644 --- a/man/lowdown-diff.1 +++ b/man/lowdown-diff.1 @@ -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. @@ -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 @@ -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 diff --git a/man/lowdown.1 b/man/lowdown.1 index d323773..34167b4 100644 --- a/man/lowdown.1 +++ b/man/lowdown.1 @@ -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. @@ -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 @@ -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 diff --git a/share/man/default.man b/share/man/default.man new file mode 100644 index 0000000..02aba20 --- /dev/null +++ b/share/man/default.man @@ -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--$ diff --git a/share/ms/default.ms b/share/ms/default.ms new file mode 100644 index 0000000..e456f1b --- /dev/null +++ b/share/ms/default.ms @@ -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--$ diff --git a/template.c b/template.c index 80759e5..fc71188 100644 --- a/template.c +++ b/template.c @@ -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. @@ -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);