Add strike-through support for groff output [jgm/peg-markdown]
See https://github.com/jgm/peg-markdown/commit/7748eca
This commit is contained in:
parent
53573d327b
commit
002c4b71f8
@ -26,6 +26,7 @@ import (
|
||||
|
||||
type troffOut struct {
|
||||
baseWriter
|
||||
strikeMacroWritten bool
|
||||
inListItem bool
|
||||
escape *strings.Replacer
|
||||
}
|
||||
@ -67,6 +68,10 @@ func (w *troffOut) s(s string) *troffOut {
|
||||
|
||||
// write string, escape '\'
|
||||
func (w *troffOut) str(s string) *troffOut {
|
||||
if strings.HasPrefix(s, ".") {
|
||||
w.WriteString(`\[char46]`)
|
||||
s = s[1:]
|
||||
}
|
||||
w.escape.WriteString(w, s)
|
||||
return w
|
||||
}
|
||||
@ -128,6 +133,17 @@ func (w *troffOut) elem(elt *element, isFirst bool) *troffOut {
|
||||
w.inline(`\fI`, elt, `\fR`)
|
||||
case STRONG:
|
||||
w.inline(`\fB`, elt, `\fR`)
|
||||
case STRIKE:
|
||||
w.s("\\c\n")
|
||||
if !w.strikeMacroWritten {
|
||||
w.s(`.de ST
|
||||
.nr width \w'\\$1'
|
||||
\Z@\v'-.25m'\l'\\n[width]u'@\\$1\c
|
||||
..
|
||||
`)
|
||||
w.strikeMacroWritten = true
|
||||
}
|
||||
w.inline(".ST \"", elt, `"`).br()
|
||||
case LIST:
|
||||
w.children(elt)
|
||||
case RAW:
|
||||
|
@ -11,8 +11,8 @@ This & that.
|
||||
.P
|
||||
Here's a link (http://example.com/?foo=1&bar=2) with an ampersand in the URL.
|
||||
.P
|
||||
Here's a link with an amersand in the link text: AT&T (http://att.com/).
|
||||
Here's a link with an amersand in the link text: AT&T (http://att.com/)\[char46]
|
||||
.P
|
||||
Here's an inline link (/script?foo=1&bar=2).
|
||||
Here's an inline link (/script?foo=1&bar=2)\[char46]
|
||||
.P
|
||||
Here's an inline link (/script?foo=1&bar=2).
|
||||
Here's an inline link (/script?foo=1&bar=2)\[char46]
|
||||
|
@ -1,5 +1,5 @@
|
||||
.P
|
||||
Link: http://example.com/ (http://example.com/).
|
||||
Link: http://example.com/ (http://example.com/)\[char46]
|
||||
.P
|
||||
With an ampersand: http://example.com/?foo=1&bar=2 (http://example.com/?foo=1&bar=2)
|
||||
.BL
|
||||
|
@ -25,7 +25,7 @@ Greater-than: >
|
||||
.P
|
||||
Hash: #
|
||||
.P
|
||||
Period: .
|
||||
Period: \[char46]
|
||||
.P
|
||||
Bang: !
|
||||
.P
|
||||
@ -113,6 +113,6 @@ _underscores_
|
||||
.P
|
||||
This is a code span with a literal backslash-backtick sequence: \fC\e`\fR
|
||||
.P
|
||||
This is a tag with unescaped backticks bar.
|
||||
This is a tag with unescaped backticks bar\[char46]
|
||||
.P
|
||||
This is a tag with backslashes bar.
|
||||
This is a tag with backslashes bar\[char46]
|
||||
|
@ -1,12 +1,12 @@
|
||||
.P
|
||||
Just a URL (/url/).
|
||||
Just a URL (/url/)\[char46]
|
||||
.P
|
||||
URL and title (/url/).
|
||||
URL and title (/url/)\[char46]
|
||||
.P
|
||||
URL and title (/url/).
|
||||
URL and title (/url/)\[char46]
|
||||
.P
|
||||
URL and title (/url/).
|
||||
URL and title (/url/)\[char46]
|
||||
.P
|
||||
URL and title (/url/).
|
||||
URL and title (/url/)\[char46]
|
||||
.P
|
||||
Empty ().
|
||||
Empty ()\[char46]
|
||||
|
@ -1,17 +1,17 @@
|
||||
.P
|
||||
Foo bar (/url/).
|
||||
Foo bar (/url/)\[char46]
|
||||
.P
|
||||
Foo bar (/url/).
|
||||
Foo bar (/url/)\[char46]
|
||||
.P
|
||||
Foo bar (/url/).
|
||||
Foo bar (/url/)\[char46]
|
||||
.P
|
||||
With embedded [brackets] (/url/).
|
||||
With embedded [brackets] (/url/)\[char46]
|
||||
.P
|
||||
Indented once (/url).
|
||||
Indented once (/url)\[char46]
|
||||
.P
|
||||
Indented twice (/url).
|
||||
Indented twice (/url)\[char46]
|
||||
.P
|
||||
Indented thrice (/url).
|
||||
Indented thrice (/url)\[char46]
|
||||
.P
|
||||
Indented [four][] times.
|
||||
.VERBON 2
|
||||
@ -21,27 +21,27 @@ Indented [four][] times.
|
||||
.P
|
||||
this (foo) should work
|
||||
.P
|
||||
So should this (foo).
|
||||
So should this (foo)\[char46]
|
||||
.P
|
||||
And this (foo).
|
||||
And this (foo)\[char46]
|
||||
.P
|
||||
And this (foo).
|
||||
And this (foo)\[char46]
|
||||
.P
|
||||
And this (foo).
|
||||
And this (foo)\[char46]
|
||||
.P
|
||||
But not [that] [].
|
||||
But not [that] []\[char46]
|
||||
.P
|
||||
Nor [that][].
|
||||
Nor [that][]\[char46]
|
||||
.P
|
||||
Nor [that].
|
||||
Nor [that]\[char46]
|
||||
.P
|
||||
[Something in brackets like this (foo) should work]
|
||||
.P
|
||||
[Same with this (foo).]
|
||||
[Same with this (foo)\[char46]]
|
||||
.P
|
||||
In this case, this (/somethingelse/) points to something else.
|
||||
.P
|
||||
Backslashing should suppress [this] and [this].
|
||||
Backslashing should suppress [this] and [this]\[char46]
|
||||
\l'\n(.lu*8u/10u'
|
||||
.P
|
||||
Here's one where the link
|
||||
|
@ -1,8 +1,8 @@
|
||||
.P
|
||||
This is the simple case (/simple).
|
||||
This is the simple case (/simple)\[char46]
|
||||
.P
|
||||
This one has a line
|
||||
break (/foo).
|
||||
break (/foo)\[char46]
|
||||
.P
|
||||
This one has a line
|
||||
break (/foo) with a line-ending space.
|
||||
|
@ -1,4 +1,4 @@
|
||||
.P
|
||||
Foo bar (/url/).
|
||||
Foo bar (/url/)\[char46]
|
||||
.P
|
||||
Foo bar (/url/).
|
||||
Foo bar (/url/)\[char46]
|
||||
|
@ -13,7 +13,7 @@ web application that allows you type your own Markdown-formatted text
|
||||
and translate it to XHTML.
|
||||
.P
|
||||
\fBNote:\fR This document is itself written using Markdown; you
|
||||
can see the source for it by adding '.text' to the URL (/projects/markdown/basics.text).
|
||||
can see the source for it by adding '\[char46]text' to the URL (/projects/markdown/basics.text)\[char46]
|
||||
.H 2 "Paragraphs, Headers, Blockquotes"
|
||||
.P
|
||||
A paragraph is simply one or more consecutive lines of text, separated
|
||||
@ -21,7 +21,7 @@ by one or more blank lines. (A blank line is any line that looks like a
|
||||
blank line -- a line containing nothing spaces or tabs is considered
|
||||
blank.) Normal paragraphs should not be intended with spaces or tabs.
|
||||
.P
|
||||
Markdown offers two styles of headers: \fISetext\fR and \fIatx\fR.
|
||||
Markdown offers two styles of headers: \fISetext\fR and \fIatx\fR\[char46]
|
||||
Setext-style headers for \fC<h1>\fR and \fC<h2>\fR are created by
|
||||
"underlining" with equal signs (\fC=\fR) and hyphens (\fC-\fR), respectively.
|
||||
To create an atx-style header, you put 1-6 hash marks (\fC#\fR) at the
|
||||
@ -171,7 +171,7 @@ Output:
|
||||
.H 3 "Links"
|
||||
.P
|
||||
Markdown supports two styles for creating links: \fIinline\fR and
|
||||
\fIreference\fR. With both styles, you use square brackets to delimit the
|
||||
\fIreference\fR\[char46] With both styles, you use square brackets to delimit the
|
||||
text you want to turn into a link.
|
||||
.P
|
||||
Inline-style links use parentheses immediately after the link text.
|
||||
|
@ -49,7 +49,7 @@ Automatic Links (#autolink)
|
||||
.LE 1
|
||||
.P
|
||||
\fBNote:\fR This document is itself written using Markdown; you
|
||||
can see the source for it by adding '.text' to the URL (/projects/markdown/syntax.text).
|
||||
can see the source for it by adding '\[char46]text' to the URL (/projects/markdown/syntax.text)\[char46]
|
||||
\l'\n(.lu*8u/10u'
|
||||
.P
|
||||
Markdown is intended to be as easy-to-read and easy-to-write as is feasible.
|
||||
@ -65,7 +65,7 @@ inspiration for Markdown's syntax is the format of plain text email.
|
||||
To this end, Markdown's syntax is comprised entirely of punctuation
|
||||
characters, which punctuation characters have been carefully chosen so
|
||||
as to look like what they mean. E.g., asterisks around a word actually
|
||||
look like *emphasis*. Markdown lists look like, well, lists. Even
|
||||
look like *emphasis*\[char46] Markdown lists look like, well, lists. Even
|
||||
blockquotes look like quoted passages of text, assuming you've ever
|
||||
used email.
|
||||
.P
|
||||
@ -119,13 +119,13 @@ Unlike block-level HTML tags, Markdown syntax \fIis\fR processed within
|
||||
span-level tags.
|
||||
.P
|
||||
In HTML, there are two characters that demand special treatment: \fC<\fR
|
||||
and \fC&\fR. Left angle brackets are used to start tags; ampersands are
|
||||
and \fC&\fR\[char46] Left angle brackets are used to start tags; ampersands are
|
||||
used to denote HTML entities. If you want to use them as literal
|
||||
characters, you must escape them as entities, e.g. \fC<\fR, and
|
||||
\fC&\fR.
|
||||
\fC&\fR\[char46]
|
||||
.P
|
||||
Ampersands in particular are bedeviling for web writers. If you want to
|
||||
write about 'AT&T', you need to write '\fCAT&T\fR'. You even need to
|
||||
write about 'AT&T', you need to write '\fCAT&T\fR'\[char46] You even need to
|
||||
escape ampersands within URLs. Thus, if you want to link to:
|
||||
.VERBON 2
|
||||
http://images.google.com/images?num=30&q=larry+bird
|
||||
@ -143,7 +143,7 @@ errors in otherwise well-marked-up web sites.
|
||||
Markdown allows you to use these characters naturally, taking care of
|
||||
all the necessary escaping for you. If you use an ampersand as part of
|
||||
an HTML entity, it remains unchanged; otherwise it will be translated
|
||||
into \fC&\fR.
|
||||
into \fC&\fR\[char46]
|
||||
.P
|
||||
So, if you want to include a copyright symbol in your article, you can write:
|
||||
.VERBON 2
|
||||
@ -198,10 +198,10 @@ Yes, this takes a tad more effort to create a \fC<br />\fR, but a simplistic
|
||||
Markdown's email-style blockquoting (#blockquote) and multi-paragraph list items (#list)
|
||||
work best -- and look better -- when you format them with hard breaks.
|
||||
.P
|
||||
Markdown supports two styles of headers, Setext (http://docutils.sourceforge.net/mirror/setext.html) and atx (http://www.aaronsw.com/2002/atx/).
|
||||
Markdown supports two styles of headers, Setext (http://docutils.sourceforge.net/mirror/setext.html) and atx (http://www.aaronsw.com/2002/atx/)\[char46]
|
||||
.P
|
||||
Setext-style headers are "underlined" using equal signs (for first-level
|
||||
headers) and dashes (for second-level headers). For example:
|
||||
headers) and dashes (for second-level headers)\[char46] For example:
|
||||
.VERBON 2
|
||||
This is an H1
|
||||
=============
|
||||
@ -502,7 +502,7 @@ end tell
|
||||
.VERBOFF
|
||||
.P
|
||||
A code block continues until it reaches a line that is not indented
|
||||
(or the end of the article).
|
||||
(or the end of the article)\[char46]
|
||||
.P
|
||||
Within a code block, ampersands (\fC&\fR) and angle brackets (\fC<\fR and \fC>\fR)
|
||||
are automatically converted into HTML entities. This makes it very
|
||||
@ -546,9 +546,9 @@ _ _ _
|
||||
.VERBOFF
|
||||
\l'\n(.lu*8u/10u'
|
||||
.P
|
||||
Markdown supports two style of links: \fIinline\fR and \fIreference\fR.
|
||||
Markdown supports two style of links: \fIinline\fR and \fIreference\fR\[char46]
|
||||
.P
|
||||
In both styles, the link text is delimited by [square brackets].
|
||||
In both styles, the link text is delimited by [square brackets]\[char46]
|
||||
.P
|
||||
To create an inline link, use a set of regular parentheses immediately
|
||||
after the link text's closing square bracket. Inside the parentheses,
|
||||
@ -753,7 +753,7 @@ escape it:
|
||||
\e*this text is surrounded by literal asterisks\e*
|
||||
.VERBOFF
|
||||
.P
|
||||
To indicate a span of code, wrap it with backtick quotes (\fC`\fR).
|
||||
To indicate a span of code, wrap it with backtick quotes (\fC`\fR)\[char46]
|
||||
Unlike a pre-formatted code block, a code span indicates code within a
|
||||
normal paragraph. For example:
|
||||
.VERBON 2
|
||||
@ -819,7 +819,7 @@ Admittedly, it's fairly difficult to devise a "natural" syntax for
|
||||
placing images into a plain text document format.
|
||||
.P
|
||||
Markdown uses an image syntax that is intended to resemble the syntax
|
||||
for links, allowing for two styles: \fIinline\fR and \fIreference\fR.
|
||||
for links, allowing for two styles: \fIinline\fR and \fIreference\fR\[char46]
|
||||
.P
|
||||
Inline image syntax looks like this:
|
||||
.VERBON 2
|
||||
@ -883,7 +883,7 @@ into something like this:
|
||||
mple.com</a>
|
||||
.VERBOFF
|
||||
.P
|
||||
which will render in a browser as a clickable link to "address@example.com".
|
||||
which will render in a browser as a clickable link to "address@example.com"\[char46]
|
||||
.P
|
||||
(This sort of entity-encoding trick will indeed fool many, if not
|
||||
most, address-harvesting bots, but it definitely won't fool all of
|
||||
|
Loading…
Reference in New Issue
Block a user