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 {
|
type troffOut struct {
|
||||||
baseWriter
|
baseWriter
|
||||||
|
strikeMacroWritten bool
|
||||||
inListItem bool
|
inListItem bool
|
||||||
escape *strings.Replacer
|
escape *strings.Replacer
|
||||||
}
|
}
|
||||||
@ -67,6 +68,10 @@ func (w *troffOut) s(s string) *troffOut {
|
|||||||
|
|
||||||
// write string, escape '\'
|
// write string, escape '\'
|
||||||
func (w *troffOut) str(s string) *troffOut {
|
func (w *troffOut) str(s string) *troffOut {
|
||||||
|
if strings.HasPrefix(s, ".") {
|
||||||
|
w.WriteString(`\[char46]`)
|
||||||
|
s = s[1:]
|
||||||
|
}
|
||||||
w.escape.WriteString(w, s)
|
w.escape.WriteString(w, s)
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
@ -128,6 +133,17 @@ func (w *troffOut) elem(elt *element, isFirst bool) *troffOut {
|
|||||||
w.inline(`\fI`, elt, `\fR`)
|
w.inline(`\fI`, elt, `\fR`)
|
||||||
case STRONG:
|
case STRONG:
|
||||||
w.inline(`\fB`, elt, `\fR`)
|
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:
|
case LIST:
|
||||||
w.children(elt)
|
w.children(elt)
|
||||||
case RAW:
|
case RAW:
|
||||||
|
@ -11,8 +11,8 @@ This & that.
|
|||||||
.P
|
.P
|
||||||
Here's a link (http://example.com/?foo=1&bar=2) with an ampersand in the URL.
|
Here's a link (http://example.com/?foo=1&bar=2) with an ampersand in the URL.
|
||||||
.P
|
.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
|
.P
|
||||||
Here's an inline link (/script?foo=1&bar=2).
|
Here's an inline link (/script?foo=1&bar=2)\[char46]
|
||||||
.P
|
.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
|
.P
|
||||||
Link: http://example.com/ (http://example.com/).
|
Link: http://example.com/ (http://example.com/)\[char46]
|
||||||
.P
|
.P
|
||||||
With an ampersand: http://example.com/?foo=1&bar=2 (http://example.com/?foo=1&bar=2)
|
With an ampersand: http://example.com/?foo=1&bar=2 (http://example.com/?foo=1&bar=2)
|
||||||
.BL
|
.BL
|
||||||
|
@ -25,7 +25,7 @@ Greater-than: >
|
|||||||
.P
|
.P
|
||||||
Hash: #
|
Hash: #
|
||||||
.P
|
.P
|
||||||
Period: .
|
Period: \[char46]
|
||||||
.P
|
.P
|
||||||
Bang: !
|
Bang: !
|
||||||
.P
|
.P
|
||||||
@ -113,6 +113,6 @@ _underscores_
|
|||||||
.P
|
.P
|
||||||
This is a code span with a literal backslash-backtick sequence: \fC\e`\fR
|
This is a code span with a literal backslash-backtick sequence: \fC\e`\fR
|
||||||
.P
|
.P
|
||||||
This is a tag with unescaped backticks bar.
|
This is a tag with unescaped backticks bar\[char46]
|
||||||
.P
|
.P
|
||||||
This is a tag with backslashes bar.
|
This is a tag with backslashes bar\[char46]
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
.P
|
.P
|
||||||
Just a URL (/url/).
|
Just a URL (/url/)\[char46]
|
||||||
.P
|
.P
|
||||||
URL and title (/url/).
|
URL and title (/url/)\[char46]
|
||||||
.P
|
.P
|
||||||
URL and title (/url/).
|
URL and title (/url/)\[char46]
|
||||||
.P
|
.P
|
||||||
URL and title (/url/).
|
URL and title (/url/)\[char46]
|
||||||
.P
|
.P
|
||||||
URL and title (/url/).
|
URL and title (/url/)\[char46]
|
||||||
.P
|
.P
|
||||||
Empty ().
|
Empty ()\[char46]
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
.P
|
.P
|
||||||
Foo bar (/url/).
|
Foo bar (/url/)\[char46]
|
||||||
.P
|
.P
|
||||||
Foo bar (/url/).
|
Foo bar (/url/)\[char46]
|
||||||
.P
|
.P
|
||||||
Foo bar (/url/).
|
Foo bar (/url/)\[char46]
|
||||||
.P
|
.P
|
||||||
With embedded [brackets] (/url/).
|
With embedded [brackets] (/url/)\[char46]
|
||||||
.P
|
.P
|
||||||
Indented once (/url).
|
Indented once (/url)\[char46]
|
||||||
.P
|
.P
|
||||||
Indented twice (/url).
|
Indented twice (/url)\[char46]
|
||||||
.P
|
.P
|
||||||
Indented thrice (/url).
|
Indented thrice (/url)\[char46]
|
||||||
.P
|
.P
|
||||||
Indented [four][] times.
|
Indented [four][] times.
|
||||||
.VERBON 2
|
.VERBON 2
|
||||||
@ -21,27 +21,27 @@ Indented [four][] times.
|
|||||||
.P
|
.P
|
||||||
this (foo) should work
|
this (foo) should work
|
||||||
.P
|
.P
|
||||||
So should this (foo).
|
So should this (foo)\[char46]
|
||||||
.P
|
.P
|
||||||
And this (foo).
|
And this (foo)\[char46]
|
||||||
.P
|
.P
|
||||||
And this (foo).
|
And this (foo)\[char46]
|
||||||
.P
|
.P
|
||||||
And this (foo).
|
And this (foo)\[char46]
|
||||||
.P
|
.P
|
||||||
But not [that] [].
|
But not [that] []\[char46]
|
||||||
.P
|
.P
|
||||||
Nor [that][].
|
Nor [that][]\[char46]
|
||||||
.P
|
.P
|
||||||
Nor [that].
|
Nor [that]\[char46]
|
||||||
.P
|
.P
|
||||||
[Something in brackets like this (foo) should work]
|
[Something in brackets like this (foo) should work]
|
||||||
.P
|
.P
|
||||||
[Same with this (foo).]
|
[Same with this (foo)\[char46]]
|
||||||
.P
|
.P
|
||||||
In this case, this (/somethingelse/) points to something else.
|
In this case, this (/somethingelse/) points to something else.
|
||||||
.P
|
.P
|
||||||
Backslashing should suppress [this] and [this].
|
Backslashing should suppress [this] and [this]\[char46]
|
||||||
\l'\n(.lu*8u/10u'
|
\l'\n(.lu*8u/10u'
|
||||||
.P
|
.P
|
||||||
Here's one where the link
|
Here's one where the link
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
.P
|
.P
|
||||||
This is the simple case (/simple).
|
This is the simple case (/simple)\[char46]
|
||||||
.P
|
.P
|
||||||
This one has a line
|
This one has a line
|
||||||
break (/foo).
|
break (/foo)\[char46]
|
||||||
.P
|
.P
|
||||||
This one has a line
|
This one has a line
|
||||||
break (/foo) with a line-ending space.
|
break (/foo) with a line-ending space.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
.P
|
.P
|
||||||
Foo bar (/url/).
|
Foo bar (/url/)\[char46]
|
||||||
.P
|
.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.
|
and translate it to XHTML.
|
||||||
.P
|
.P
|
||||||
\fBNote:\fR This document is itself written using Markdown; you
|
\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"
|
.H 2 "Paragraphs, Headers, Blockquotes"
|
||||||
.P
|
.P
|
||||||
A paragraph is simply one or more consecutive lines of text, separated
|
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 line -- a line containing nothing spaces or tabs is considered
|
||||||
blank.) Normal paragraphs should not be intended with spaces or tabs.
|
blank.) Normal paragraphs should not be intended with spaces or tabs.
|
||||||
.P
|
.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
|
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.
|
"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
|
To create an atx-style header, you put 1-6 hash marks (\fC#\fR) at the
|
||||||
@ -171,7 +171,7 @@ Output:
|
|||||||
.H 3 "Links"
|
.H 3 "Links"
|
||||||
.P
|
.P
|
||||||
Markdown supports two styles for creating links: \fIinline\fR and
|
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.
|
text you want to turn into a link.
|
||||||
.P
|
.P
|
||||||
Inline-style links use parentheses immediately after the link text.
|
Inline-style links use parentheses immediately after the link text.
|
||||||
|
@ -49,7 +49,7 @@ Automatic Links (#autolink)
|
|||||||
.LE 1
|
.LE 1
|
||||||
.P
|
.P
|
||||||
\fBNote:\fR This document is itself written using Markdown; you
|
\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'
|
\l'\n(.lu*8u/10u'
|
||||||
.P
|
.P
|
||||||
Markdown is intended to be as easy-to-read and easy-to-write as is feasible.
|
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
|
To this end, Markdown's syntax is comprised entirely of punctuation
|
||||||
characters, which punctuation characters have been carefully chosen so
|
characters, which punctuation characters have been carefully chosen so
|
||||||
as to look like what they mean. E.g., asterisks around a word actually
|
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
|
blockquotes look like quoted passages of text, assuming you've ever
|
||||||
used email.
|
used email.
|
||||||
.P
|
.P
|
||||||
@ -119,13 +119,13 @@ Unlike block-level HTML tags, Markdown syntax \fIis\fR processed within
|
|||||||
span-level tags.
|
span-level tags.
|
||||||
.P
|
.P
|
||||||
In HTML, there are two characters that demand special treatment: \fC<\fR
|
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
|
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
|
characters, you must escape them as entities, e.g. \fC<\fR, and
|
||||||
\fC&\fR.
|
\fC&\fR\[char46]
|
||||||
.P
|
.P
|
||||||
Ampersands in particular are bedeviling for web writers. If you want to
|
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:
|
escape ampersands within URLs. Thus, if you want to link to:
|
||||||
.VERBON 2
|
.VERBON 2
|
||||||
http://images.google.com/images?num=30&q=larry+bird
|
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
|
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
|
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
|
an HTML entity, it remains unchanged; otherwise it will be translated
|
||||||
into \fC&\fR.
|
into \fC&\fR\[char46]
|
||||||
.P
|
.P
|
||||||
So, if you want to include a copyright symbol in your article, you can write:
|
So, if you want to include a copyright symbol in your article, you can write:
|
||||||
.VERBON 2
|
.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)
|
Markdown's email-style blockquoting (#blockquote) and multi-paragraph list items (#list)
|
||||||
work best -- and look better -- when you format them with hard breaks.
|
work best -- and look better -- when you format them with hard breaks.
|
||||||
.P
|
.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
|
.P
|
||||||
Setext-style headers are "underlined" using equal signs (for first-level
|
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
|
.VERBON 2
|
||||||
This is an H1
|
This is an H1
|
||||||
=============
|
=============
|
||||||
@ -502,7 +502,7 @@ end tell
|
|||||||
.VERBOFF
|
.VERBOFF
|
||||||
.P
|
.P
|
||||||
A code block continues until it reaches a line that is not indented
|
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
|
.P
|
||||||
Within a code block, ampersands (\fC&\fR) and angle brackets (\fC<\fR and \fC>\fR)
|
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
|
are automatically converted into HTML entities. This makes it very
|
||||||
@ -546,9 +546,9 @@ _ _ _
|
|||||||
.VERBOFF
|
.VERBOFF
|
||||||
\l'\n(.lu*8u/10u'
|
\l'\n(.lu*8u/10u'
|
||||||
.P
|
.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
|
.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
|
.P
|
||||||
To create an inline link, use a set of regular parentheses immediately
|
To create an inline link, use a set of regular parentheses immediately
|
||||||
after the link text's closing square bracket. Inside the parentheses,
|
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*
|
\e*this text is surrounded by literal asterisks\e*
|
||||||
.VERBOFF
|
.VERBOFF
|
||||||
.P
|
.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
|
Unlike a pre-formatted code block, a code span indicates code within a
|
||||||
normal paragraph. For example:
|
normal paragraph. For example:
|
||||||
.VERBON 2
|
.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.
|
placing images into a plain text document format.
|
||||||
.P
|
.P
|
||||||
Markdown uses an image syntax that is intended to resemble the syntax
|
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
|
.P
|
||||||
Inline image syntax looks like this:
|
Inline image syntax looks like this:
|
||||||
.VERBON 2
|
.VERBON 2
|
||||||
@ -883,7 +883,7 @@ into something like this:
|
|||||||
mple.com</a>
|
mple.com</a>
|
||||||
.VERBOFF
|
.VERBOFF
|
||||||
.P
|
.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
|
.P
|
||||||
(This sort of entity-encoding trick will indeed fool many, if not
|
(This sort of entity-encoding trick will indeed fool many, if not
|
||||||
most, address-harvesting bots, but it definitely won't fool all of
|
most, address-harvesting bots, but it definitely won't fool all of
|
||||||
|
Loading…
Reference in New Issue
Block a user