source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* docbook2mdoc: better handling of <link> and <ulink> elements including
@ 2019-04-07 17:01 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-04-07 17:01 UTC (permalink / raw)
  To: source

Log Message:
-----------
better handling of <link> and <ulink> elements
including endterm=, linkend=, url=, and xlink:href= attributes

Modified Files:
--------------
    docbook2mdoc:
        docbook2mdoc.c
        node.c
        node.h
        parse.c
        statistics.c

Revision Data
-------------
Index: parse.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/parse.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -Lparse.c -Lparse.c -u -p -r1.17 -r1.18
--- parse.c
+++ parse.c
@@ -190,7 +190,7 @@ static	const struct element elements[] =
 	{ "title",		NODE_TITLE },
 	{ "trademark",		NODE_IGNORE },
 	{ "type",		NODE_TYPE },
-	{ "ulink",		NODE_ULINK },
+	{ "ulink",		NODE_LINK },
 	{ "userinput",		NODE_LITERAL },
 	{ "variablelist",	NODE_VARIABLELIST },
 	{ "varlistentry",	NODE_VARLISTENTRY },
Index: statistics.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/statistics.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -Lstatistics.c -Lstatistics.c -u -p -r1.14 -r1.15
--- statistics.c
+++ statistics.c
@@ -369,6 +369,7 @@ main(int argc, char *argv[])
 		table_add("indexterm", "secondary");
 		table_add("informaltable", "tgroup");
 		table_add("itemizedlist", "listitem");
+		table_add("link", NULL);
 		table_add("listitem", NULL);
 		table_add("literal", "TEXT");
 		table_add("literallayout", NULL);
@@ -417,6 +418,7 @@ main(int argc, char *argv[])
 		table_add("thead", "row");
 		table_add("title", "TEXT");
 		table_add("type", "TEXT");
+		table_add("ulink", NULL);
 		table_add("userinput", "TEXT");
 		table_add("variablelist", "varlistentry");
 		table_add("varlistentry", "listitem");
Index: node.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/node.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lnode.c -Lnode.c -u -p -r1.3 -r1.4
--- node.c
+++ node.c
@@ -29,10 +29,13 @@ static	const char *const attrkeys[ATTRKE
 	"class",
 	"close",
 	"cols",
+	"endterm",
 	"id",
 	"linkend",
 	"open",
-	"rep"
+	"rep",
+	"url",
+	"xlink:href"
 };
 
 static	const char *const attrvals[ATTRVAL__MAX] = {
Index: docbook2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.95 -r1.96
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -521,6 +521,41 @@ pnode_printauthor(struct format *f, stru
 }
 
 static void
+pnode_printlink(struct format *f, struct pnode *n)
+{
+	const char	*uri, *text;
+
+	uri = pnode_getattr_raw(n, ATTRKEY_LINKEND, NULL);
+	if (uri != NULL) {
+		if (TAILQ_FIRST(&n->childq) != NULL) {
+			print_textnode(f, n);
+			text = "";
+		} else {
+			text = pnode_getattr_raw(n, ATTRKEY_ENDTERM, NULL);
+			if (text != NULL)
+				print_text(f, text, ARG_SPACE);
+		}
+		if (text != NULL)
+			macro_open(f, "Pq");
+		macro_open(f, "Sx");
+		macro_addarg(f, uri, ARG_SPACE);
+		pnode_unlinksub(n);
+		return;
+	}
+	uri = pnode_getattr_raw(n, ATTRKEY_XLINK_HREF, NULL);
+	if (uri == NULL)
+		uri = pnode_getattr_raw(n, ATTRKEY_URL, NULL);
+	if (uri != NULL) {
+		macro_open(f, "Lk");
+		macro_addarg(f, uri, ARG_SPACE | ARG_SINGLE);
+		if (TAILQ_FIRST(&n->childq) != NULL)
+			macro_addnode(f, n, ARG_SPACE | ARG_SINGLE);
+		pnode_unlinksub(n);
+		return;
+	}
+}
+
+static void
 pnode_printprologue(struct format *p, struct ptree *tree)
 {
 	struct pnode	*refmeta;
@@ -706,7 +741,6 @@ static void
 pnode_print(struct format *p, struct pnode *pn)
 {
 	struct pnode	*pp;
-	const char	*ccp;
 	enum linestate	 sv;
 
 	if (pn == NULL)
@@ -794,11 +828,8 @@ pnode_print(struct format *p, struct pno
 		macro_line(p, "Sh LEGAL NOTICE");
 		break;
 	case NODE_LINK:
-		ccp = pnode_getattr_raw(pn, ATTRKEY_LINKEND, NULL);
-		if (ccp == NULL)
-			break;
-		macro_argline(p, "Sx", ccp);
-		return;
+		pnode_printlink(p, pn);
+		break;
 	case NODE_LITERAL:
 		macro_open(p, "Ql");
 		break;
@@ -964,6 +995,7 @@ pnode_print(struct format *p, struct pno
 	case NODE_FUNCTION:
 	case NODE_FUNCSYNOPSISINFO:
 	case NODE_KEYSYM:
+	case NODE_LINK:
 	case NODE_LITERAL:
 	case NODE_OPTION:
 	case NODE_PARAMETER:
Index: node.h
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/node.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -Lnode.h -Lnode.h -u -p -r1.10 -r1.11
--- node.h
+++ node.h
@@ -155,10 +155,13 @@ enum	attrkey {
 	ATTRKEY_CLASS,
 	ATTRKEY_CLOSE,
 	ATTRKEY_COLS,
+	ATTRKEY_ENDTERM,
 	ATTRKEY_ID,
 	ATTRKEY_LINKEND,
 	ATTRKEY_OPEN,
 	ATTRKEY_REP,
+	ATTRKEY_URL,
+	ATTRKEY_XLINK_HREF,
 	ATTRKEY__MAX
 };
 
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-04-07 17:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-07 17:01 docbook2mdoc: better handling of <link> and <ulink> elements including 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).