* mandoc: When a .Tg is attached to a paragraph, attach the permalink to
@ 2020-04-18 20:40 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2020-04-18 20:40 UTC (permalink / raw)
To: source
Log Message:
-----------
When a .Tg is attached to a paragraph, attach the permalink
to the first word, or the first few words if they are short.
Modified Files:
--------------
mandoc:
Makefile.depend
html.c
html.h
man_validate.c
mdoc_html.c
mdoc_validate.c
read.c
tag.c
tag.h
term_tag.c
mandoc/regress/mdoc/Bd:
paragraph.out_html
mandoc/regress/mdoc/Pp:
Makefile
arg.in
arg.out_ascii
arg.out_lint
arg.out_markdown
arg.out_tag
mandoc/regress/mdoc/blank:
transp.out_markdown
Added Files:
-----------
mandoc/regress/mdoc/Pp:
arg.out_html
Revision Data
-------------
Index: paragraph.out_html
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Bd/paragraph.out_html,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lregress/mdoc/Bd/paragraph.out_html -Lregress/mdoc/Bd/paragraph.out_html -u -p -r1.3 -r1.4
--- regress/mdoc/Bd/paragraph.out_html
+++ regress/mdoc/Bd/paragraph.out_html
@@ -1,6 +1,8 @@
-<p class="Pp" id="npara">normal paragraph</p>
+<p class="Pp" id="npara"><a class="permalink" href="#npara">normal</a>
+ paragraph</p>
<div class="Bd Pp" id="filled">filled display
-<p class="Pp" id="fpara">paragraph in display</p>
+<p class="Pp" id="fpara"><a class="permalink" href="#fpara">paragraph</a> in
+ display</p>
</div>
back to normal
<p class="Pp">another paragraph</p>
@@ -9,7 +11,7 @@ back to normal
unfilled
display
<mark id="upara"></mark>
-unfilled
+<a class="permalink" href="#upara">unfilled</a>
paragraph
</pre>
</div>
Index: Makefile.depend
===================================================================
RCS file: /home/cvs/mandoc/mandoc/Makefile.depend,v
retrieving revision 1.47
retrieving revision 1.48
diff -LMakefile.depend -LMakefile.depend -u -p -r1.47 -r1.48
--- Makefile.depend
+++ Makefile.depend
@@ -38,7 +38,7 @@ man.o: man.c config.h mandoc_aux.h mando
man_html.o: man_html.c config.h mandoc_aux.h mandoc.h roff.h man.h out.h html.h main.h
man_macro.o: man_macro.c config.h mandoc.h roff.h man.h libmandoc.h roff_int.h libman.h
man_term.o: man_term.c config.h mandoc_aux.h mandoc.h roff.h man.h out.h term.h term_tag.h main.h
-man_validate.o: man_validate.c config.h mandoc_aux.h mandoc.h roff.h tag.h man.h libmandoc.h roff_int.h libman.h
+man_validate.o: man_validate.c config.h mandoc_aux.h mandoc.h roff.h man.h libmandoc.h roff_int.h libman.h tag.h
mandoc.o: mandoc.c config.h mandoc_aux.h mandoc.h roff.h libmandoc.h roff_int.h
mandoc_aux.o: mandoc_aux.c config.h mandoc.h mandoc_aux.h
mandoc_msg.o: mandoc_msg.c config.h mandoc.h
@@ -56,18 +56,18 @@ mdoc_man.o: mdoc_man.c config.h mandoc_a
mdoc_markdown.o: mdoc_markdown.c mandoc_aux.h mandoc.h roff.h mdoc.h main.h
mdoc_state.o: mdoc_state.c mandoc.h roff.h mdoc.h libmandoc.h roff_int.h libmdoc.h
mdoc_term.o: mdoc_term.c config.h mandoc_aux.h roff.h mdoc.h out.h term.h term_tag.h main.h
-mdoc_validate.o: mdoc_validate.c config.h mandoc_aux.h mandoc.h mandoc_xr.h roff.h tag.h mdoc.h libmandoc.h roff_int.h libmdoc.h
+mdoc_validate.o: mdoc_validate.c config.h mandoc_aux.h mandoc.h mandoc_xr.h roff.h mdoc.h libmandoc.h roff_int.h libmdoc.h tag.h
msec.o: msec.c config.h mandoc.h libmandoc.h msec.in
out.o: out.c config.h mandoc_aux.h tbl.h out.h
preconv.o: preconv.c config.h mandoc.h roff.h mandoc_parse.h libmandoc.h
-read.o: read.c config.h mandoc_aux.h mandoc.h roff.h tag.h mdoc.h man.h mandoc_parse.h libmandoc.h roff_int.h
+read.o: read.c config.h mandoc_aux.h mandoc.h roff.h mdoc.h man.h mandoc_parse.h libmandoc.h roff_int.h tag.h
roff.o: roff.c config.h mandoc_aux.h mandoc_ohash.h compat_ohash.h mandoc.h roff.h mandoc_parse.h libmandoc.h roff_int.h tbl_parse.h eqn_parse.h predefs.in
roff_html.o: roff_html.c mandoc.h roff.h out.h html.h
roff_term.o: roff_term.c mandoc.h roff.h out.h term.h
roff_validate.o: roff_validate.c mandoc.h roff.h libmandoc.h roff_int.h
soelim.o: soelim.c config.h compat_stringlist.h
st.o: st.c config.h mandoc.h roff.h libmdoc.h
-tag.o: tag.c config.h mandoc_aux.h mandoc_ohash.h compat_ohash.h roff.h mdoc.h tag.h
+tag.o: tag.c config.h mandoc_aux.h mandoc_ohash.h compat_ohash.h roff.h mdoc.h roff_int.h tag.h
tbl.o: tbl.c config.h mandoc_aux.h mandoc.h tbl.h libmandoc.h tbl_parse.h tbl_int.h
tbl_data.o: tbl_data.c config.h mandoc_aux.h mandoc.h tbl.h libmandoc.h tbl_int.h
tbl_html.o: tbl_html.c config.h mandoc.h roff.h tbl.h out.h html.h
@@ -78,5 +78,5 @@ term.o: term.c config.h mandoc.h mandoc_
term_ascii.o: term_ascii.c config.h mandoc.h mandoc_aux.h out.h term.h manconf.h main.h
term_ps.o: term_ps.c config.h mandoc_aux.h out.h term.h manconf.h main.h
term_tab.o: term_tab.c mandoc_aux.h out.h term.h
-term_tag.o: term_tag.c config.h mandoc.h roff.h tag.h term_tag.h
+term_tag.o: term_tag.c config.h mandoc.h roff.h roff_int.h tag.h term_tag.h
tree.o: tree.c config.h mandoc.h roff.h mdoc.h man.h tbl.h eqn.h main.h
Index: mdoc_validate.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_validate.c,v
retrieving revision 1.384
retrieving revision 1.385
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.384 -r1.385
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -37,11 +37,11 @@
#include "mandoc.h"
#include "mandoc_xr.h"
#include "roff.h"
-#include "tag.h"
#include "mdoc.h"
#include "libmandoc.h"
#include "roff_int.h"
#include "libmdoc.h"
+#include "tag.h"
/* FIXME: .Bl -diag can't have non-text children in HEAD. */
Index: tag.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/tag.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -Ltag.c -Ltag.c -u -p -r1.34 -r1.35
--- tag.c
+++ tag.c
@@ -32,6 +32,7 @@
#include "mandoc_ohash.h"
#include "roff.h"
#include "mdoc.h"
+#include "roff_int.h"
#include "tag.h"
struct tag_entry {
@@ -258,13 +259,37 @@ tag_move_id(struct roff_node *n)
* to the beginning of the respective paragraphs.
*/
void
-tag_postprocess(struct roff_node *n)
+tag_postprocess(struct roff_man *man, struct roff_node *n)
{
+ struct roff_node *nn;
+ char *cp;
+
if (n->flags & NODE_ID) {
switch (n->tok) {
+ case MDOC_Pp:
+ nn = n->next;
+ if (nn == NULL || nn->type != ROFFT_TEXT ||
+ *nn->string == '\0' || *nn->string == ' ')
+ break;
+ /* Use the first few letters for the permalink. */
+ cp = nn->string;
+ while (cp != NULL && cp - nn->string < 5)
+ cp = strchr(cp + 1, ' ');
+ if (cp != NULL && cp[1] != '\0') {
+ /* Split a longer text node. */
+ man->last = nn;
+ man->next = ROFF_NEXT_SIBLING;
+ roff_word_alloc(man, nn->line,
+ nn->pos + (cp - nn->string), cp + 1);
+ man->last->flags = nn->flags;
+ *cp = '\0';
+ }
+ assert(nn->tag == NULL);
+ nn->tag = mandoc_strdup(n->tag);
+ nn->flags |= NODE_HREF;
+ break;
case MDOC_Bd:
case MDOC_Bl:
- case MDOC_Pp:
/* XXX No permalink for now. */
break;
default:
@@ -281,5 +306,5 @@ tag_postprocess(struct roff_node *n)
}
}
for (n = n->child; n != NULL; n = n->next)
- tag_postprocess(n);
+ tag_postprocess(man, n);
}
Index: read.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/read.c,v
retrieving revision 1.217
retrieving revision 1.218
diff -Lread.c -Lread.c -u -p -r1.217 -r1.218
--- read.c
+++ read.c
@@ -1,6 +1,6 @@
/* $Id$ */
/*
- * Copyright (c) 2010-2019 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2020 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org>
*
@@ -42,12 +42,12 @@
#include "mandoc_aux.h"
#include "mandoc.h"
#include "roff.h"
-#include "tag.h"
#include "mdoc.h"
#include "man.h"
#include "mandoc_parse.h"
#include "libmandoc.h"
#include "roff_int.h"
+#include "tag.h"
#define REPARSE_LIMIT 1000
@@ -708,7 +708,7 @@ mparse_result(struct mparse *curp)
mdoc_validate(curp->man);
else
man_validate(curp->man);
- tag_postprocess(curp->man->meta.first);
+ tag_postprocess(curp->man, curp->man->meta.first);
}
return &curp->man->meta;
}
Index: mdoc_html.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_html.c,v
retrieving revision 1.338
retrieving revision 1.339
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.338 -r1.339
--- mdoc_html.c
+++ mdoc_html.c
@@ -377,10 +377,13 @@ print_mdoc_node(MDOC_ARGS)
}
t = h->tag;
t->refcnt++;
- if (NODE_DELIMC & n->flags)
+ if (n->flags & NODE_DELIMC)
h->flags |= HTML_NOSPACE;
- print_text(h, n->string);
- if (NODE_DELIMO & n->flags)
+ if (n->flags & NODE_HREF)
+ print_tagged_text(h, n->string, n);
+ else
+ print_text(h, n->string);
+ if (n->flags & NODE_DELIMO)
h->flags |= HTML_NOSPACE;
break;
case ROFFT_EQN:
Index: man_validate.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man_validate.c,v
retrieving revision 1.152
retrieving revision 1.153
diff -Lman_validate.c -Lman_validate.c -u -p -r1.152 -r1.153
--- man_validate.c
+++ man_validate.c
@@ -34,11 +34,11 @@
#include "mandoc_aux.h"
#include "mandoc.h"
#include "roff.h"
-#include "tag.h"
#include "man.h"
#include "libmandoc.h"
#include "roff_int.h"
#include "libman.h"
+#include "tag.h"
#define CHKARGS struct roff_man *man, struct roff_node *n
Index: html.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/html.h,v
retrieving revision 1.107
retrieving revision 1.108
diff -Lhtml.h -Lhtml.h -u -p -r1.107 -r1.108
--- html.h
+++ html.h
@@ -127,6 +127,8 @@ struct tag *print_otag_id(struct html *
struct roff_node *);
void print_tagq(struct html *, const struct tag *);
void print_stagq(struct html *, const struct tag *);
+void print_tagged_text(struct html *, const char *,
+ struct roff_node *);
void print_text(struct html *, const char *);
void print_tblclose(struct html *);
void print_tbl(struct html *, const struct tbl_span *);
Index: term_tag.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/term_tag.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lterm_tag.c -Lterm_tag.c -u -p -r1.3 -r1.4
--- term_tag.c
+++ term_tag.c
@@ -31,6 +31,7 @@
#include "mandoc.h"
#include "roff.h"
+#include "roff_int.h"
#include "tag.h"
#include "term_tag.h"
Index: html.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/html.c,v
retrieving revision 1.267
retrieving revision 1.268
diff -Lhtml.c -Lhtml.c -u -p -r1.267 -r1.268
--- html.c
+++ html.c
@@ -878,6 +878,15 @@ print_gen_comment(struct html *h, struct
void
print_text(struct html *h, const char *word)
{
+ print_tagged_text(h, word, NULL);
+}
+
+void
+print_tagged_text(struct html *h, const char *word, struct roff_node *n)
+{
+ struct tag *t;
+ char *href;
+
/*
* Always wrap text in a paragraph unless already contained in
* some flow container; never put it directly into a section.
@@ -898,13 +907,20 @@ print_text(struct html *h, const char *w
}
/*
- * Print the text, optionally surrounded by HTML whitespace,
- * optionally manually switching fonts before and after.
+ * Optionally switch fonts, optionally write a permalink, then
+ * print the text, optionally surrounded by HTML whitespace.
*/
assert(h->metaf == NULL);
print_metaf(h);
print_indent(h);
+
+ if (n != NULL && (href = html_make_id(n, 0)) != NULL) {
+ t = print_otag(h, TAG_A, "chR", "permalink", href);
+ free(href);
+ } else
+ t = NULL;
+
if ( ! print_encode(h, word, NULL, 0)) {
if ( ! (h->flags & HTML_NONOSPACE))
h->flags &= ~HTML_NOSPACE;
@@ -915,7 +931,8 @@ print_text(struct html *h, const char *w
if (h->metaf != NULL) {
print_tagq(h, h->metaf);
h->metaf = NULL;
- }
+ } else if (t != NULL)
+ print_tagq(h, t);
h->flags &= ~HTML_IGNDELIM;
}
Index: tag.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/tag.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -Ltag.h -Ltag.h -u -p -r1.13 -r1.14
--- tag.h
+++ tag.h
@@ -31,5 +31,5 @@
void tag_alloc(void);
int tag_exists(const char *);
void tag_put(const char *, int, struct roff_node *);
-void tag_postprocess(struct roff_node *);
+void tag_postprocess(struct roff_man *, struct roff_node *);
void tag_free(void);
--- /dev/null
+++ regress/mdoc/Pp/arg.out_html
@@ -0,0 +1,6 @@
+<p class="Pp">line 1</p>
+<p class="Pp" id="first"><a class="permalink" href="#first">line 2</a>
+ <br/>
+ line 3</p>
+<p class="Pp">line 4</p>
+<p class="Pp" id="last"><a class="permalink" href="#last">final</a> text</p>
Index: arg.out_ascii
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Pp/arg.out_ascii,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lregress/mdoc/Pp/arg.out_ascii -Lregress/mdoc/Pp/arg.out_ascii -u -p -r1.3 -r1.4
--- regress/mdoc/Pp/arg.out_ascii
+++ regress/mdoc/Pp/arg.out_ascii
@@ -4,6 +4,8 @@ N\bNA\bAM\bME\bE
P\bPp\bp-\b-a\bar\brg\bg - paragraph macro with arguments
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ BEGINTEST
+
line 1
line 2
@@ -13,4 +15,6 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
final text
-OpenBSD April 6, 2020 OpenBSD
+ ENDTEST
+
+OpenBSD April 18, 2020 OpenBSD
Index: arg.out_markdown
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Pp/arg.out_markdown,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lregress/mdoc/Pp/arg.out_markdown -Lregress/mdoc/Pp/arg.out_markdown -u -p -r1.3 -r1.4
--- regress/mdoc/Pp/arg.out_markdown
+++ regress/mdoc/Pp/arg.out_markdown
@@ -6,6 +6,8 @@ PP-ARG(1) - General Commands Manual
# DESCRIPTION
+BEGINTEST
+
line 1
line 2
@@ -13,6 +15,9 @@ line 3
line 4
-final text
+final
+text
+
+ENDTEST
-OpenBSD - April 6, 2020
+OpenBSD - April 18, 2020
Index: arg.in
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Pp/arg.in,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lregress/mdoc/Pp/arg.in -Lregress/mdoc/Pp/arg.in -u -p -r1.3 -r1.4
--- regress/mdoc/Pp/arg.in
+++ regress/mdoc/Pp/arg.in
@@ -1,4 +1,4 @@
-.\" $OpenBSD: arg.in,v 1.5 2020/04/06 09:55:50 schwarze Exp $
+.\" $OpenBSD: arg.in,v 1.6 2020/04/18 20:28:46 schwarze Exp $
.Dd $Mdocdate$
.Dt PP-ARG 1
.Os
@@ -6,6 +6,8 @@
.Nm Pp-arg
.Nd paragraph macro with arguments
.Sh DESCRIPTION
+BEGINTEST
+.Pp
line 1
.Tg first
.Pp drop this
@@ -17,3 +19,5 @@ line 4
.Tg last
.Pp
final text
+.Pp
+ENDTEST
Index: Makefile
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Pp/Makefile,v
retrieving revision 1.4
retrieving revision 1.5
diff -Lregress/mdoc/Pp/Makefile -Lregress/mdoc/Pp/Makefile -u -p -r1.4 -r1.5
--- regress/mdoc/Pp/Makefile
+++ regress/mdoc/Pp/Makefile
@@ -1,7 +1,8 @@
-# $OpenBSD: Makefile,v 1.7 2020/04/06 09:55:50 schwarze Exp $
+# $OpenBSD: Makefile,v 1.8 2020/04/18 20:28:46 schwarze Exp $
REGRESS_TARGETS = arg
TAG_TARGETS = arg
LINT_TARGETS = arg
+HTML_TARGETS = arg
.include <bsd.regress.mk>
Index: arg.out_lint
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Pp/arg.out_lint,v
retrieving revision 1.8
retrieving revision 1.9
diff -Lregress/mdoc/Pp/arg.out_lint -Lregress/mdoc/Pp/arg.out_lint -u -p -r1.8 -r1.9
--- regress/mdoc/Pp/arg.out_lint
+++ regress/mdoc/Pp/arg.out_lint
@@ -1,3 +1,3 @@
-mandoc: arg.in:13:5: ERROR: skipping all arguments: br drop this
-mandoc: arg.in:15:8: ERROR: skipping excess arguments: sp ... drop this
-mandoc: arg.in:11:2: ERROR: skipping all arguments: Pp drop
+mandoc: arg.in:15:5: ERROR: skipping all arguments: br drop this
+mandoc: arg.in:17:8: ERROR: skipping excess arguments: sp ... drop this
+mandoc: arg.in:13:2: ERROR: skipping all arguments: Pp drop
Index: arg.out_tag
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/Pp/arg.out_tag,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/mdoc/Pp/arg.out_tag -Lregress/mdoc/Pp/arg.out_tag -u -p -r1.1 -r1.2
--- regress/mdoc/Pp/arg.out_tag
+++ regress/mdoc/Pp/arg.out_tag
@@ -1,4 +1,4 @@
NAME 3
DESCRIPTION 6
-first 9
-last 14
+first 11
+last 16
Index: transp.out_markdown
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/mdoc/blank/transp.out_markdown,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/mdoc/blank/transp.out_markdown -Lregress/mdoc/blank/transp.out_markdown -u -p -r1.1 -r1.2
--- regress/mdoc/blank/transp.out_markdown
+++ regress/mdoc/blank/transp.out_markdown
@@ -23,7 +23,8 @@ Pp sp 2v:
sp Pp:
-Double sp:
+Double
+sp:
br blank:
--
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:[~2020-04-18 20:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-18 20:40 mandoc: When a .Tg is attached to a paragraph, attach the permalink to 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).