=================================================================== RCS file: /cvs/mandoc/mdoc_markdown.c,v retrieving revision 1.35 retrieving revision 1.40 diff -u -p -r1.35 -r1.40 --- mandoc/mdoc_markdown.c 2020/04/03 11:35:01 1.35 +++ mandoc/mdoc_markdown.c 2025/06/26 17:06:34 1.40 @@ -1,6 +1,6 @@ -/* $Id: mdoc_markdown.c,v 1.35 2020/04/03 11:35:01 schwarze Exp $ */ +/* $Id: mdoc_markdown.c,v 1.40 2025/06/26 17:06:34 schwarze Exp $ */ /* - * Copyright (c) 2017, 2018, 2020 Ingo Schwarze + * Copyright (c) 2017, 2018, 2020, 2025 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,6 +16,8 @@ * * Markdown formatter for mdoc(7) used by mandoc(1). */ +#include "config.h" + #include #include @@ -83,6 +85,7 @@ static int md_pre_Sh(struct roff_node *); static int md_pre_Sm(struct roff_node *); static int md_pre_Vt(struct roff_node *); static int md_pre_Xr(struct roff_node *); +static int md_pre__R(struct roff_node *); static int md_pre__T(struct roff_node *); static int md_pre_br(struct roff_node *); @@ -157,7 +160,7 @@ static const struct md_act md_acts[MDOC_MAX - MDOC_Dd] { NULL, NULL, md_post_pc, NULL, NULL }, /* %N */ { NULL, NULL, md_post_pc, NULL, NULL }, /* %O */ { NULL, NULL, md_post_pc, NULL, NULL }, /* %P */ - { NULL, NULL, md_post_pc, NULL, NULL }, /* %R */ + { NULL, md_pre__R, md_post_pc, NULL, NULL }, /* %R */ { NULL, md_pre__T, md_post__T, NULL, NULL }, /* %T */ { NULL, NULL, md_post_pc, NULL, NULL }, /* %V */ { NULL, NULL, NULL, NULL, NULL }, /* Ac */ @@ -289,6 +292,14 @@ markdown_mdoc(void *arg, const struct roff_meta *mdoc) md_word(mdoc->os); md_word("-"); md_word(mdoc->date); + md_word("-"); + md_word(mdoc->title); + if (mdoc->msec != NULL) { + outflags &= ~MD_spc; + md_word("("); + md_word(mdoc->msec); + md_word(")"); + } putchar('\n'); } @@ -601,16 +612,18 @@ md_word(const char *s) md_rawword("markdown"); continue; case ESCAPE_FONTBOLD: + case ESCAPE_FONTCB: nextfont = "**"; break; case ESCAPE_FONTITALIC: + case ESCAPE_FONTCI: nextfont = "*"; break; case ESCAPE_FONTBI: nextfont = "***"; break; case ESCAPE_FONT: - case ESCAPE_FONTCW: + case ESCAPE_FONTCR: case ESCAPE_FONTROMAN: nextfont = ""; break; @@ -746,7 +759,7 @@ md_pre_raw(struct roff_node *n) if ((prefix = md_act(n->tok)->prefix) != NULL) { md_rawword(prefix); outflags &= ~MD_spc; - if (*prefix == '`') + if (strchr(prefix, '`') != NULL) code_blocks++; } return 1; @@ -760,7 +773,7 @@ md_post_raw(struct roff_node *n) if ((suffix = md_act(n->tok)->suffix) != NULL) { outflags &= ~(MD_spc | MD_nl); md_rawword(suffix); - if (*suffix == '`') + if (strchr(suffix, '`') != NULL) code_blocks--; } } @@ -1573,6 +1586,34 @@ md_pre_Xr(struct roff_node *n) md_word("("); md_node(n); md_word(")"); + return 0; +} + +static int +md_pre__R(struct roff_node *n) +{ + const unsigned char *cp; + const char *arg; + + arg = n->child->string; + + if (strncmp(arg, "RFC ", 4) != 0) + return 1; + cp = arg += 4; + while (isdigit(*cp)) + cp++; + if (*cp != '\0') + return 1; + + md_rawword("[RFC "); + outflags &= ~MD_spc; + md_rawword(arg); + outflags &= ~MD_spc; + md_rawword("](http://www.rfc-editor.org/rfc/rfc"); + outflags &= ~MD_spc; + md_rawword(arg); + outflags &= ~MD_spc; + md_rawword(".html)"); return 0; }