* mdocml: Minimal support for deep linking into man(7) pages.
@ 2017-03-15 11:30 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-03-15 11:30 UTC (permalink / raw)
To: source
Log Message:
-----------
Minimal support for deep linking into man(7) pages.
As the man(7) language does not provide semantic markup,
only .SH, .SS, and .UR become anchors for now.
Modified Files:
--------------
mdocml:
html.c
html.h
man_html.c
mandoc_html.3
mdoc_html.c
Revision Data
-------------
Index: mdoc_html.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_html.c,v
retrieving revision 1.276
retrieving revision 1.277
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.276 -r1.277
--- mdoc_html.c
+++ mdoc_html.c
@@ -49,7 +49,6 @@ struct htmlmdoc {
};
static char *cond_id(const struct roff_node *);
-static char *make_id(const struct roff_node *);
static void print_mdoc_head(MDOC_ARGS);
static void print_mdoc_node(MDOC_ARGS);
static void print_mdoc_nodelist(MDOC_ARGS);
@@ -478,28 +477,6 @@ mdoc_root_pre(MDOC_ARGS)
}
static char *
-make_id(const struct roff_node *n)
-{
- const struct roff_node *nch;
- char *buf, *cp;
-
- for (nch = n->child; nch != NULL; nch = nch->next)
- if (nch->type != ROFFT_TEXT)
- return NULL;
-
- buf = NULL;
- deroff(&buf, n);
-
- /* http://www.w3.org/TR/html5/dom.html#the-id-attribute */
-
- for (cp = buf; *cp != '\0'; cp++)
- if (*cp == ' ')
- *cp = '_';
-
- return buf;
-}
-
-static char *
cond_id(const struct roff_node *n)
{
if (n->child != NULL &&
@@ -511,7 +488,7 @@ cond_id(const struct roff_node *n)
(n->parent->tok == MDOC_Xo &&
n->parent->parent->prev == NULL &&
n->parent->parent->parent->tok == MDOC_It)))
- return make_id(n);
+ return html_make_id(n);
return NULL;
}
@@ -522,7 +499,7 @@ mdoc_sh_pre(MDOC_ARGS)
switch (n->type) {
case ROFFT_HEAD:
- id = make_id(n);
+ id = html_make_id(n);
print_otag(h, TAG_H1, "cTi", "Sh", id);
print_otag(h, TAG_A, "chR", "selflink", id);
free(id);
@@ -545,7 +522,7 @@ mdoc_ss_pre(MDOC_ARGS)
if (n->type != ROFFT_HEAD)
return 1;
- id = make_id(n);
+ id = html_make_id(n);
print_otag(h, TAG_H2, "cTi", "Ss", id);
print_otag(h, TAG_A, "chR", "selflink", id);
free(id);
@@ -955,7 +932,7 @@ mdoc_sx_pre(MDOC_ARGS)
{
char *id;
- id = make_id(n);
+ id = html_make_id(n);
print_otag(h, TAG_A, "cThR", "Sx", id);
free(id);
return 1;
@@ -1128,7 +1105,7 @@ mdoc_er_pre(MDOC_ARGS)
(n->parent->tok == MDOC_It ||
(n->parent->tok == MDOC_Bq &&
n->parent->parent->parent->tok == MDOC_It)) ?
- make_id(n) : NULL;
+ html_make_id(n) : NULL;
if (id != NULL)
print_otag(h, TAG_A, "chR", "selflink", id);
Index: mandoc_html.3
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandoc_html.3,v
retrieving revision 1.6
retrieving revision 1.7
diff -Lmandoc_html.3 -Lmandoc_html.3 -u -p -r1.6 -r1.7
--- mandoc_html.3
+++ mandoc_html.3
@@ -48,6 +48,14 @@
.Fa "struct html *h"
.Fa "const char *word"
.Fc
+.Ft char *
+.Fo html_make_id
+.Fa "const struct roff_node *n"
+.Fc
+.Ft int
+.Fo html_strlen
+.Fa "const char *cp"
+.Fc
.Sh DESCRIPTION
The mandoc HTML formatter is not a formal library.
However, as it is compiled into more than one program, in particular
@@ -306,8 +314,27 @@ and
.Fn print_tagq
functions.
.Pp
+The function
+.Fn html_make_id
+takes a node containing one or more text children
+and returns a newly allocated string containing the concatenation
+of the child strings, with blanks replaced by underscores.
+If the node
+.Fa n
+contains any non-text child node,
+.Fn html_make_id
+returns
+.Dv NULL
+instead.
+The caller is responsible for freeing the returned string.
+.Pp
+The function
+.Fn html_strlen
+counts the number of characters in
+.Fa cp .
+It is used as a crude estimate of the width needed to display a string.
+.Pp
The functions
-.Fn html_strlen ,
.Fn print_eqn ,
.Fn print_tbl ,
and
Index: html.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/html.c,v
retrieving revision 1.209
retrieving revision 1.210
diff -Lhtml.c -Lhtml.c -u -p -r1.209 -r1.210
--- html.c
+++ html.c
@@ -28,8 +28,9 @@
#include <string.h>
#include <unistd.h>
-#include "mandoc.h"
#include "mandoc_aux.h"
+#include "mandoc.h"
+#include "roff.h"
#include "out.h"
#include "html.h"
#include "manconf.h"
@@ -234,6 +235,28 @@ print_metaf(struct html *h, enum mandoc_
default:
break;
}
+}
+
+char *
+html_make_id(const struct roff_node *n)
+{
+ const struct roff_node *nch;
+ char *buf, *cp;
+
+ for (nch = n->child; nch != NULL; nch = nch->next)
+ if (nch->type != ROFFT_TEXT)
+ return NULL;
+
+ buf = NULL;
+ deroff(&buf, n);
+
+ /* http://www.w3.org/TR/html5/dom.html#the-id-attribute */
+
+ for (cp = buf; *cp != '\0'; cp++)
+ if (*cp == ' ')
+ *cp = '_';
+
+ return buf;
}
int
Index: man_html.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man_html.c,v
retrieving revision 1.133
retrieving revision 1.134
diff -Lman_html.c -Lman_html.c -u -p -r1.133 -r1.134
--- man_html.c
+++ man_html.c
@@ -435,8 +435,14 @@ man_br_pre(MAN_ARGS)
static int
man_SH_pre(MAN_ARGS)
{
- if (n->type == ROFFT_HEAD)
- print_otag(h, TAG_H1, "c", "Sh");
+ char *id;
+
+ if (n->type == ROFFT_HEAD) {
+ id = html_make_id(n);
+ print_otag(h, TAG_H1, "cTi", "Sh", id);
+ print_otag(h, TAG_A, "chR", "selflink", id);
+ free(id);
+ }
return 1;
}
@@ -498,8 +504,14 @@ man_SM_pre(MAN_ARGS)
static int
man_SS_pre(MAN_ARGS)
{
- if (n->type == ROFFT_HEAD)
- print_otag(h, TAG_H2, "c", "Ss");
+ char *id;
+
+ if (n->type == ROFFT_HEAD) {
+ id = html_make_id(n);
+ print_otag(h, TAG_H2, "cTi", "Ss", id);
+ print_otag(h, TAG_A, "chR", "selflink", id);
+ free(id);
+ }
return 1;
}
@@ -656,7 +668,7 @@ man_UR_pre(MAN_ARGS)
assert(n->type == ROFFT_HEAD);
if (n->child != NULL) {
assert(n->child->type == ROFFT_TEXT);
- print_otag(h, TAG_A, "ch", "Lk", n->child->string);
+ print_otag(h, TAG_A, "cTh", "Lk", n->child->string);
}
assert(n->next->type == ROFFT_BODY);
Index: html.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/html.h,v
retrieving revision 1.83
retrieving revision 1.84
diff -Lhtml.h -Lhtml.h -u -p -r1.83 -r1.84
--- html.h
+++ html.h
@@ -112,6 +112,7 @@ struct html {
};
+struct roff_node;
struct tbl_span;
struct eqn;
@@ -127,4 +128,5 @@ void print_eqn(struct html *, const s
void print_paragraph(struct html *);
void print_endline(struct html *);
+char *html_make_id(const struct roff_node *);
int html_strlen(const char *);
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-03-15 11:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-15 11:30 mdocml: Minimal support for deep linking into man(7) pages 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).