git.iko.soy/typeable/pandoc
on master help sign in
Merge changes in branches/wrappers into trunk.

[in trunk] svn merge -r105:HEAD \ https://pandoc.googlecode.com/svn/branches/wrappers git-svn-id: https://pandoc.googlecode.com/svn/trunk@177 788f1e2b-df1e-0410-8736-df70ead52e1b

commit426cbadfef6c26323faedcab2cd5ea7efa64d1bb authorroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b> dateTue 12 Dec 2006, 07:04 (20 years ago) parent6411ea7
25 files changed+735−466
Makefile+32−5 README+85−83 html2markdown−69 latex2markdown−32 man/man1/html2markdown.1+45−18 man/man1/latex2markdown.1+18−16 man/man1/markdown2html.1+18−17 man/man1/markdown2latex.1+17−15 man/man1/markdown2pdf.1+20−21 man/man1/pandoc.1+14−15 markdown2html−31 markdown2latex−31 markdown2pdf−113 src/wrappers/checkin.sh+7 src/wrappers/common.sh+56 src/wrappers/getopts.sh+12 src/wrappers/html2markdown.in+134 src/wrappers/latex2markdown.in+14 src/wrappers/markdown2html.in+12 src/wrappers/markdown2latex.in+12 src/wrappers/markdown2pdf.in+64 src/wrappers/postopts.sh+17 src/wrappers/singlearg.sh+7 src/wrappers/tempdir.sh+10 src/wrappers/testwrapper.in+141
Makefile+32−5
@@ -6,6 +6,7 @@
66CABAL := Pandoc.cabal
77SRCDIR := src
88MANDIR := man
9+TESTDIR := tests
910BUILDDIR := dist
1011BUILDCONF := .setup-config
1112BUILDCMD := runhaskell Setup.hs
@@ -24,7 +25,8 @@ MAIN := $(firstword $(EXECS))
2425#-------------------------------------------------------------------------------
2526# Install targets
2627#-------------------------------------------------------------------------------
27−PROGS := $(EXECS) html2markdown markdown2html latex2markdown markdown2latex markdown2pdf
28+WRAPPERS := html2markdown latex2markdown markdown2html markdown2latex markdown2pdf
29+PROGS := $(EXECS) $(WRAPPERS)
2830DOCS := README.html README BUGS TODO
2931
3032#-------------------------------------------------------------------------------
@@ -86,6 +88,27 @@ templates: $(SRCDIR)/templates
8688$(SRCDIR)/templates:
8789 $(MAKE) -C $(SRCDIR)/templates
8890
91+define generate-shell-script
92+echo "Generating $@..."; \
93+awk ' \
94+ /^[ \t]*###+ / { \
95+ lead = $$0; sub(/[^ \t].*$$/, "", lead); \
96+ t = "$(dir $<)/"$$2; \
97+ while (getline line < t > 0) \
98+ print lead line; \
99+ next; \
100+ } \
101+ { print } \
102+' <$< >$@
103+endef
104+
105+.PHONY: wrappers
106+wrappers: $(WRAPPERS)
107+wrapper_deps := $(wildcard $(SRCDIR)/wrappers/*.sh)
108+cleanup_files+=$(WRAPPERS)
109+%: $(SRCDIR)/wrappers/%.in $(wrapper_deps)
110+ @$(generate-shell-script)
111+
89112cleanup_files+=$(CABAL)
90113$(CABAL): cabalize $(CABAL).in
91114 ./cabalize <$(CABAL).in >$(CABAL)
@@ -104,7 +127,7 @@ build: templates configure
104127 $(BUILDCMD) build
105128
106129.PHONY: build-exec
107−build-exec: $(EXECS)
130+build-exec: $(PROGS)
108131cleanup_files+=$(EXECS)
109132$(EXECS): build
110133 for f in $@; do \
@@ -250,11 +273,15 @@ osx-dmg: ../$(osx_dmg_name)
250273 -rm -f $(osx_dmg_name)
251274 mv $(osx_udzo_name) ../$(osx_dmg_name)
252275
253−.PHONY: test test-markdown
276+.PHONY: test test-markdown test-wrapper
254277test: $(MAIN)
255− @cd tests && perl runtests.pl -s $(PWD)/$(MAIN)
278+ @cd $(TESTDIR) && perl runtests.pl -s $(PWD)/$(MAIN)
256279test-markdown: $(MAIN)
257− @cd tests/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(MAIN) -tidy
280+ @cd $(TESTDIR)/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(MAIN) -tidy
281+cleanup_files+=testwrapper
282+test-wrappers: testwrapper
283+ @echo "Running $<..."
284+ @sh testwrapper
258285
259286# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
260287src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
README+85−83
@@ -39,24 +39,24 @@ STDIN. If you run it with file names as arguments, it will take input
3939from those files. It accepts several command-line options. For a
4040list, type
4141
42− pandoc -h
42+ pandoc -h
4343
4444The most important options specify the format of the source file and
4545the output. The default reader is markdown; the default writer is
4646HTML. So if you don't specify a reader or writer, `pandoc` will
4747convert markdown to HTML. For example,
4848
49− pandoc hello.txt
49+ pandoc hello.txt
5050
5151will convert `hello.txt` from markdown to HTML. For other conversions,
5252you must specify a reader and/or a writer using the `-r` and `-w`
5353flags. To convert markdown to LaTeX, you would write:
5454
55− pandoc -w latex hello.txt
55+ pandoc -w latex hello.txt
5656
5757To convert html to markdown:
5858
59− pandoc -r html -w markdown hello.txt
59+ pandoc -r html -w markdown hello.txt
6060
6161Supported writers include `markdown`, `latex`, `html`, `rtf` (rich text
6262format), `rst` (reStructuredText), and `s5` (which produces an HTML
@@ -120,72 +120,74 @@ before the files can be found by TeX.)
120120
121121# The shell scripts
122122
123−For convenience, five shell scripts have been included that make it
124−easy to run `pandoc` without remembering all the command-line options.
125−All of the scripts use `iconv` to convert to and from the local
126−character encoding. All of the scripts presuppose that `pandoc`
127−is in the path, and some have additional requirements. (For example,
128−`html2markdown` uses `tidy`, and `markdown2pdf` uses `pdflatex`.)
123+Five shell scripts have been included that make it easy to run
124+`pandoc` without worrying about character encodings, and without
125+remembering all the command-line options:
129126
130−1. `markdown2html` converts markdown to HTML. (This can be used
131− as a replacement for `Markdown.pl`.)
127+- `markdown2html` converts markdown-formatted text to HTML
128+- `markdown2latex` converts markdown-formatted text to LaTeX
129+- `markdown2pdf` produces a PDF file from markdown-formatted
130+ text, using `pdflatex`.
131+- `html2markdown` converts HTML to markdown-formatted text
132+- `latex2markdown` converts LaTeX to markdown-formatted text
132133
133−2. `html2markdown` can take either a filename or a URL as argument. If
134− it is given a URL, it uses `curl`, `wget`, or an available text-based
135− browser to fetch the contents of the specified URL, then filters this
136− through `tidy` to straighten up the HTML, and finally passes
137− this HTML to `pandoc` to produce markdown text:
134+All of the scripts use `iconv` (if available) to convert to and from
135+the local character encoding. All of the scripts presuppose that
136+`pandoc` is in the path, and some have additional requirements. (For
137+example, `html2markdown` uses `tidy`, and `markdown2pdf` uses
138+`pdflatex`.)
138139
139− html2markdown http://www.fsf.org
140+When no arguments are specified, text will be read from standard
141+input. Arguments specify input files (limited to one in the case of
142+`latex2markdown` and `html2markdown`; the other scripts accept any number
143+of arguments). `html2markdown` may take a URL as argument instead of
144+a filename; in this case, `curl`, `wget`, or an available text-based
145+browser will be used to fetch the contents of the URL. (The `-n` option
146+inhibits this behavior; the `-g` option allows the user to specify a
147+custom command that will be used to fetch from a URL.)
140148
141− html2markdown www.fsf.org
149+With the exception of `markdown2pdf`, the scripts write to standard output.
150+Output can be sent to a file using shell output redirection:
142151
143− html2markdown subdir/mylocalfile.html
152+ latex2markdown sample.tex > sample.txt
144153
145−3. `latex2markdown` converts a LaTeX file to markdown:
154+The default behavior of `markdown2pdf` is to create a file with the same
155+base name as the first argument and the extension `pdf`; thus, for example,
146156
147− latex2markdown mytexfile.tex
157+ markdown2pdf sample.txt endnotes.txt
148158
149−4. `markdown2latex` converts markdown to LaTeX:
159+will produce `sample.pdf`. (If `sample.pdf` exists already, it will be
160+backed up before being overwritten.) An output file name can be specified
161+explicitly using the `-o` option:
150162
151− markdown2latex mytextfile.txt
163+ markdown2pdf -o "My Book.pdf" chap1.txt chap2.txt chap3.txt
152164
153−5. `markdown2pdf` converts markdown to PDF using `pdflatex`:
165+Options specific to the scripts, like `-o`, `-g`, and `-n`, must
166+be specified *before* any command-line arguments (file names or URLs).
167+Any options specified *after* the command-line arguments will be
168+passed directly to `pandoc`. For example,
154169
155− markdown2pdf mytextfile.txt
170+ markdown2html tusks.txt -S -T Elephants
156171
157− creates a file `mytextfile.pdf`. To specify a different
158− name for the output file, use the `-o` option:
172+will convert `tusks.txt` to `tusks.html` using smart quotes, ellipses,
173+and dashes, with "Elephants" as the page title prefix. (For a
174+complete list of `pandoc` options, see below.) When there are no
175+command-line arguments (because input is from STDIN), `pandoc`
176+options must be preceded by ` -- `:
159177
160− markdown2pdf -o final-draft.pdf mytextfile.txt
178+ cat tusks.txt | markdown2html -- -S -T Elephants
161179
162−If you want to use `pandoc`'s command-line options in these scripts,
163−put the options in the environment variable `PANDOC_OPTS`. For
164−example, to convert `tusks.txt` to `tusks.html` using smart quotes,
165−ellipses, and dashes, with "Elephants" as the page title prefix:
180+The ` -- ` separator may optionally be used when there are command-line
181+arguments:
166182
167− PANDOC_OPTS="-S -T Elephants" markdown2html tusks.txt > tusks.html
168−
169−To make these options persistent, use `export`:
170−
171− export PANDOC_OPTS="-S -T Elephants"
172− markdown2html tusks.txt > tusks.html
173− markdown2html trunk.txt > trunk.html
174−
175−You may also specify options on the command line, separating them
176−from the arguments with '` -- `':
177−
178− markdown2html tusks.txt -- -S -T Elephants
179−
180−Options specified in this way will override any options set in
181−`PANDOC_OPTS`.
183+ markdown2html -- tusks.txt -S -T Elephants
182184
183185# Command-line options
184186
185187Various command-line options can be used to customize the output.
186188For a complete list, type
187189
188− pandoc --help
190+ pandoc --help
189191
190192`-p` or `--preserve-tabs` causes tabs in the source text to be
191193preserved, rather than converted to spaces (the default).
@@ -264,13 +266,13 @@ markdown test suite, type `make test-markdown`.)
264266Pandoc behaves differently from standard markdown on some "edge
265267cases" involving lists. Consider this source:
266268
267− 1. First
268− 2. Second:
269− - Fee
270− - Fie
271− - Foe
269+ 1. First
270+ 2. Second:
271+ - Fee
272+ - Fie
273+ - Foe
272274
273− 3. Third
275+ 3. Third
274276
275277Pandoc transforms this into a "compact list" (with no `<p>` tags
276278around "First", "Second", or "Third"), while markdown puts `<p>`
@@ -286,20 +288,20 @@ is followed by a blank line is irrelevant.
286288Standard markdown allows unescaped literal quotes in titles, as
287289in
288290
289− [foo]: "bar "embedded" baz"
291+ [foo]: "bar "embedded" baz"
290292
291293Pandoc requires all quotes within titles to be escaped:
292294
293− [foo]: "bar \"embedded\" baz"
295+ [foo]: "bar \"embedded\" baz"
294296
295297## Reference links
296298
297299Pandoc allows implicit reference links in either of two styles:
298300
299− 1. Here's my [link]
300− 2. Here's my [link][]
301+ 1. Here's my [link]
302+ 2. Here's my [link][]
301303
302− [link]: linky.com
304+ [link]: linky.com
303305
304306If there's no corresponding reference, the implicit reference link
305307will appear as regular bracketed text. Note: even `[link][]` will
@@ -313,18 +315,18 @@ Pandoc's markdown allows footnotes, using the following syntax:
313315 here is a footnote reference,^(1) and another.^(longnote)
314316
315317 ^(1) Here is the footnote. It can go anywhere in the document,
316− except in embedded contexts like block quotes or lists.
318+ except in embedded contexts like block quotes or lists.
317319
318320 ^(longnote) Here's the other note. This one contains multiple
319321 blocks.
320322 ^
321323 ^ Caret characters are used to indicate that the blocks all belong
322− to a single footnote (as with block quotes).
324+ to a single footnote (as with block quotes).
323325 ^
324326 ^ If you want, you can use a caret at the beginning of every line,
325− ^ as with blockquotes, but all that you need is a caret at the
326− ^ beginning of the first line of the block and any preceding
327− ^ blank lines.
327+ ^ as with blockquotes, but all that you need is a caret at the
328+ ^ beginning of the first line of the block and any preceding
329+ ^ blank lines.
328330
329331Footnote references may not contain spaces, tabs, or newlines.
330332
@@ -335,21 +337,21 @@ Markdown 1.0. While Markdown 1.0 leaves HTML blocks exactly as they
335337are, Pandoc treats text between HTML tags as markdown. Thus, for
336338example, Pandoc will turn
337339
338− <table>
339− <tr>
340− <td>*one*</td>
341− <td>[a link](http://google.com)</td>
342− </tr>
343− </table>
340+ <table>
341+ <tr>
342+ <td>*one*</td>
343+ <td>[a link](http://google.com)</td>
344+ </tr>
345+ </table>
344346
345347into
346348
347− <table>
348− <tr>
349− <td><em>one</em></td>
350− <td><a href="http://google.com">a link</a></td>
351− </tr>
352− </table>
349+ <table>
350+ <tr>
351+ <td><em>one</em></td>
352+ <td><a href="http://google.com">a link</a></td>
353+ </tr>
354+ </table>
353355
354356whereas Markdown 1.0 will preserve it as is.
355357
@@ -426,10 +428,10 @@ include BibTeX citations:
426428You can also use LaTeX environments. For example,
427429
428430 \begin{tabular}{|l|l|}\hline
429− Age & Frequency \\ \hline
431+ Age & Frequency \\ \hline
430432 18--25 & 15 \\
431− 26--35 & 33 \\
432− 36--45 & 22 \\ \hline
433+ 26--35 & 33 \\
434+ 36--45 & 22 \\ \hline
433435 \end{tabular}
434436
435437Note, however, that material between the begin and end tags will
@@ -441,14 +443,14 @@ When run with the "standalone" option (`-s`), `pandoc` creates a
441443standalone file, complete with an appropriate header. To see the
442444default headers used for html and latex, use the following commands:
443445
444− pandoc -D html
446+ pandoc -D html
445447
446− pandoc -D latex
448+ pandoc -D latex
447449
448450If you want to use a different header, just create a file containing
449451it and specify it on the command line as follows:
450452
451− pandoc --header=MyHeaderFile
453+ pandoc --header=MyHeaderFile
452454
453455# Producing S5 with Pandoc
454456
html2markdowndeleted−69
@@ -1,69 +0,0 @@
1−#!/bin/sh -e
2−# converts html to markdown
3−# uses an available program to fetch URL and tidy to normalize it first
4−
5−pathfind () { # portable which(1), code taken from Debian Developer's Reference
6− OLDIFS="$IFS"
7− IFS=:
8− for _p in $PATH; do
9− if [ -x "$_p/$*" ]; then
10− IFS="$OLDIFS"
11− return 0
12− fi
13− done
14− IFS="$OLDIFS"
15− return 1
16−}
17−
18−for p in pandoc tidy; do
19− pathfind $p || {
20− echo >&2 "You need '$p' to use this program!"
21− exit 1
22− }
23−done
24−
25−ALL="$*"
26−ARGS=${ALL%% -- *} # only the part before ' -- ' delimiters is relevant
27−set -- $ARGS
28−
29−REST=${ALL#$ARGS}; REST=${REST# -- }
30−PANDOC_OPTS=${REST:-$PANDOC_OPTS}
31−
32−infile=$1
33−
34−if [ $# -gt 1 ]; then
35− shift
36− echo >&2 "Warning: extra arguments '$@' will be ignored!"
37−fi
38−
39−if [ -z "$infile" ] || [ -f $infile ]; then
40− tidy -utf8 $infile 2>/dev/null | \
41− pandoc $PANDOC_OPTS -r html -w markdown -s | \
42− iconv -f utf-8
43−else
44− # Treat given argument as an URL. Locate a
45− # sensible text based browser (note the order).
46− for p in wget lynx w3m curl links w3c; do
47− if pathfind $p; then
48− DUMPER=$p
49− break
50− fi
51− done
52− # Setup proper options.
53− case "$DUMPER" in
54− wget) OPT="-O-" ;;
55− lynx) OPT="-source" ;;
56− w3m) OPT="-dump_source" ;;
57− curl) OPT="" ;;
58− links) OPT="-source" ;;
59− w3c) OPT="-n -get" ;;
60− "") printf "Needs a program to fetch the URL " >&2
61− printf "(e.g. wget, w3m, lynx, w3c, or curl)." >&2
62− exit 1 ;;
63− esac
64− # Fetch and feed to pandoc.
65− $DUMPER $OPT $infile 2>/dev/null | \
66− tidy -utf8 2>/dev/null | \
67− pandoc $PANDOC_OPTS -r html -w markdown -s | \
68− iconv -f utf-8
69−fi
latex2markdowndeleted−32
@@ -1,32 +0,0 @@
1−#!/bin/sh -e
2−# runs pandoc to convert latex to markdown
3−
4−pathfind () { # portable which(1), code taken from Debian Developer's Reference
5− OLDIFS="$IFS"
6− IFS=:
7− for _p in $PATH; do
8− if [ -x "$_p/$*" ]; then
9− IFS="$OLDIFS"
10− return 0
11− fi
12− done
13− IFS="$OLDIFS"
14− return 1
15−}
16−
17−for p in pandoc; do
18− pathfind $p || {
19− echo >&2 "You need '$p' to use this program!"
20− exit 1
21− }
22−done
23−
24−ALL="$*"
25−ARGS=${ALL%% -- *} # only the part before ' -- ' delimiters is relevant
26−set -- $ARGS
27−
28−REST=${ALL#$ARGS}; REST=${REST# -- }
29−PANDOC_OPTS=${REST:-$PANDOC_OPTS}
30−
31−iconv -t utf-8 $* | pandoc $PANDOC_OPTS -r latex -w markdown -s | \
32− iconv -f utf-8
man/man1/html2markdown.1+45−18
@@ -1,33 +1,60 @@
1−.TH PANDOC 1 "November 1, 2006" Linux "User Manuals"
1+.TH HTML2MARKDOWN 1 "November 21, 2006" Pandoc "User Manuals"
22.SH NAME
33html2markdown \- converts HTML to markdown-formatted text
44.SH SYNOPSIS
5−\fBhtml2markdown\fR [ \fIinput-file\fR or \fIURL\fR ]
5+\fBhtml2markdown\fR [\fIoptions\fR] [\fIinput\-file\fR or \fIURL\fR]
6+[\fB\-\-\fR] [\fIpandoc\-opts\fR]
67.SH DESCRIPTION
7−\fBhtml2markdown\fR converts \fIinput-file\fR or \fIURL\fR
8−(or text from STDIN) from HTML to markdown-formatted plain text.
9−It uses an available program (e.g. wget, w3m, lynx or curl) to fetch
10−the contents of the URL.
8+\fBhtml2markdown\fR converts \fIinput\-file\fR or \fIURL\fR (or text
9+from STDIN) from HTML to markdown\-formatted plain text.
10+If a URL is specified, \fBhtml2markdown\fR uses an available program
11+(e.g. wget, w3m, lynx or curl) to fetch its contents. Output is sent
12+to STDOUT.
1113.PP
1214\fBhtml2markdown\fR is a wrapper for \fBpandoc\fR.
1315.SH OPTIONS
1416.TP
15−.B \-\-
16−Any options appearing after ` \-\- ' on the command line will be passed
17−directly to \fBpandoc\fR. See \fBpandoc\fR(1) for a list of options
18−that may be used. Options specified in this way will override
19−PANDOC_OPTS (see below). Example:
17+.B \-h
18+Show usage message.
19+.TP
20+.B \-e \fIencoding\fR
21+Assume the character encoding \fIencoding\fR in reading the HTML.
22+(Note: \fIencoding\fR will be passed to \fBiconv\fR; a list of
23+available encodings may be obtained using `\fBiconv \-l\fR'.)
24+If the \fB\-e\fR option is not specified, the encoding will be
25+determined as follows: If input is from STDIN, the local encoding
26+will be assumed. Otherwise, \fBhtml2markdown\fR will try to
27+extract the character encoding from the "Content-type" meta tag.
28+If no character encoding is specified in this way, UTF-8 will be
29+assumed for a URL argument, and the local encoding will be assumed
30+for a file argument.
31+.TP
32+.B \-g \fIcommand\fR
33+Use \fIcommand\fR to fetch the contents of a URL. (By default,
34+\fBhtml2markdown\fR searches for an available program or text-based
35+browser to fetch the contents of a URL.) For example:
36+.IP
37+html2markdown \-g 'wget \-\-user=foo \-\-password=bar' mysite.com
38+.TP
39+.B \-n
40+Disable automatic fetching of contents when URLs are specified as
41+arguments.
42+.TP
43+.I pandoc\-opts
44+Any options appearing after \fIinput\-file\fR or \fIURL\fR on the
45+command line will be passed directly to \fBpandoc\fR. If no
46+\fIinput-file\fR or \fIURL\fR is specified, these options must
47+be preceded by ` \fB\-\-\fR '. (In other cases, ` \fB\-\-\fR ' is
48+optional.) See \fBpandoc\fR(1) for a list of options that may be used.
49+Example:
2050.IP
21−html2markdown input.txt -- -R
22−.SH ENVIRONMENT
23−Any command-line options contained in the PANDOC_OPTS environment variable
24−will be passed directly to \fBpandoc\fR. See \fBpandoc\fR(1)
25−for a list of options that may be used.
51+html2markdown input.txt \-\- \-R
2652.SH "SEE ALSO"
2753\fBpandoc\fR(1),
2854\fBmarkdown2html\fR(1),
2955\fBmarkdown2latex\fR(1),
3056\fBlatex2markdown\fR(1),
31−\fBmarkdown2pdf\fR(1)
57+\fBmarkdown2pdf\fR(1),
58+\fBiconv\fR(1)
3259.SH AUTHOR
33−John MacFarlane
60+John MacFarlane and Recai Oktas
man/man1/latex2markdown.1+18−16
@@ -1,26 +1,28 @@
1−.TH PANDOC 1 "November 1, 2006" Linux "User Manuals"
1+.TH LATEX2MARKDOWN 1 "November 21, 2006" Pandoc "User Manuals"
22.SH NAME
3−latex2markdown \- converts LaTeX to markdown-formatted text
3+latex2markdown \- converts LaTeX to markdown\-formatted text
44.SH SYNOPSIS
5−\fBlatex2markdown\fR [ \fIinput-file\fR ]
5+\fBlatex2markdown\fR [\fIoptions\fR] [\fIinput\-file\fR]
6+[\fB\-\-\fR] [\fIpandoc\-opts\fR]
67.SH DESCRIPTION
7−\fBlatex2markdown\fR converts \fIinput-file\fR
8−(or text from STDIN) from LaTeX to markdown-formatted plain text.
8+\fBlatex2markdown\fR converts \fIinput\-file\fR
9+(or text from STDIN) from LaTeX to markdown\-formatted plain text.
10+Output is sent to STDOUT.
911.PP
1012\fBlatex2markdown\fR is a wrapper for \fBpandoc\fR.
1113.SH OPTIONS
1214.TP
13−.B \-\-
14−Any options appearing after ` \-\- ' on the command line will be passed
15−directly to \fBpandoc\fR. See \fBpandoc\fR(1) for a list of options
16−that may be used. Options specified in this way will override
17−PANDOC_OPTS (see below). Example:
15+.B \-h
16+Show usage message.
17+.TP
18+.I pandoc\-opts
19+Any options appearing after \fIinput\-file\fR on the command line
20+will be passed directly to \fBpandoc\fR. If no \fIinput-file\fR
21+is specified, these options must be preceded by ` \fB\-\-\fR '.
22+(In other cases, ` \fB\-\-\fR ' is optional.) See \fBpandoc\fR(1)
23+for a list of options that may be used. Example:
1824.IP
19−latex2markdown input.txt -- -R
20−.SH ENVIRONMENT
21−Any command-line options contained in the PANDOC_OPTS environment variable
22−will be passed directly to \fBpandoc\fR. See \fBpandoc\fR(1)
23−for a list of options that may be used.
25+latex2markdown input.txt \-\- \-R
2426.SH "SEE ALSO"
2527\fBpandoc\fR(1),
2628\fBmarkdown2html\fR(1),
@@ -28,4 +30,4 @@ for a list of options that may be used.
2830\fBmarkdown2latex\fR(1),
2931\fBmarkdown2pdf\fR(1)
3032.SH AUTHOR
31−John MacFarlane
33+John MacFarlane and Recai Oktas
man/man1/markdown2html.1+18−17
@@ -1,28 +1,29 @@
1−.TH PANDOC 1 "November 1, 2006" Linux "User Manuals"
1+.TH MARKDOWN2HTML 1 "November 21, 2006" Pandoc "User Manuals"
22.SH NAME
3−markdown2html \- converts markdown-formatted text to HTML
3+markdown2html \- converts markdown\-formatted text to HTML
44.SH SYNOPSIS
5−\fBmarkdown2html\fR [ \fIinput-files\fR ]
5+\fBmarkdown2html\fR [\fIoptions\fR] [\fIinput\-file\fR]...
6+[\fB\-\-\fR] [\fIpandoc\-opts\fR]
67.SH DESCRIPTION
7−\fBmarkdown2html\fR converts \fIinput-files\fR
8−(or text from STDIN) from markdown-formatted plain text to HTML.
8+\fBmarkdown2html\fR converts \fIinput\-file\fR
9+(or text from STDIN) from markdown\-formatted plain text to HTML.
910If multiple files are specified, they will be combined to make a single
10−HTML document.
11+HTML document. Output is sent to STDOUT.
1112.PP
1213\fBmarkdown2html\fR is a wrapper for \fBpandoc\fR.
1314.SH OPTIONS
1415.TP
15−.B \-\-
16−Any options appearing after ` \-\- ' on the command line will be passed
17−directly to \fBpandoc\fR. See \fBpandoc\fR(1) for a list of options
18−that may be used. Options specified in this way will override
19−PANDOC_OPTS (see below). Example:
16+.B \-h
17+Show usage message.
18+.TP
19+.I pandoc\-opts
20+Any options appearing after \fIinput\-file\fR... on the command line
21+will be passed directly to \fBpandoc\fR. If no \fIinput-file\fR
22+is specified, these options must be preceded by ` \fB\-\-\fR '.
23+(In other cases, ` \fB\-\-\fR ' is optional.) See \fBpandoc\fR(1)
24+for a list of options that may be used. Example:
2025.IP
21−markdown2html input.txt -- --css=main.css -S
22−.SH ENVIRONMENT
23−Any command-line options contained in the PANDOC_OPTS environment variable
24−will be passed directly to \fBpandoc\fR. See \fBpandoc\fR(1)
25−for a list of options that may be used.
26+markdown2html input.txt \-\- \-\-css=main.css \-S
2627.SH "SEE ALSO"
2728\fBpandoc\fR(1),
2829\fBhtml2markdown\fR(1),
@@ -30,4 +31,4 @@ for a list of options that may be used.
3031\fBlatex2markdown\fR(1),
3132\fBmarkdown2pdf\fR(1)
3233.SH AUTHOR
33−John MacFarlane
34+John MacFarlane and Recai Oktas
man/man1/markdown2latex.1+17−15
@@ -1,27 +1,29 @@
1−.TH PANDOC 1 "November 1, 2006" Linux "User Manuals"
1+.TH MARKDOWN2LATEX 1 "November 21, 2006" Pandoc "User Manuals"
22.SH NAME
33markdown2latex \- converts markdown-formatted text to LaTeX
44.SH SYNOPSIS
5−\fBmarkdown2latex\fR [ \fIinput-files\fR ]
5+\fBmarkdown2latex\fR [\fIoptions\fR] [\fIinput\-file\fR]...
6+[\fB\-\-\fR] [\fIpandoc\-opts\fR]
67.SH DESCRIPTION
7−\fBmarkdown2latex\fR converts \fIinput-files\fR (or text from STDIN)
8−from markdown-formatted plain text to LaTeX. If multiple files are
8+\fBmarkdown2latex\fR converts \fIinput\-file\fR (or text from STDIN)
9+from markdown\-formatted plain text to LaTeX. If multiple files are
910specified, they will be combined to make a single LaTeX document.
11+Output is sent to STDOUT.
1012.PP
1113\fBmarkdown2latex\fR is a wrapper for \fBpandoc\fR.
1214.SH OPTIONS
1315.TP
14−.B \-\-
15−Any options appearing after ` \-\- ' on the command line will be passed
16−directly to \fBpandoc\fR. See \fBpandoc\fR(1) for a list of options
17−that may be used. Options specified in this way will override
18−PANDOC_OPTS (see below). Example:
16+.B \-h
17+Show usage message.
18+.TP
19+.I pandoc\-opts
20+Any options appearing after \fIinput\-file\fR... on the command line
21+will be passed directly to \fBpandoc\fR. If no \fIinput-file\fR
22+is specified, these options must be preceded by ` \fB\-\-\fR '.
23+(In other cases, ` \fB\-\-\fR ' is optional.) See \fBpandoc\fR(1)
24+for a list of options that may be used. Example:
1925.IP
20−markdown2latex input.txt -- --custom-header=letterhead.tex
21−.SH ENVIRONMENT
22−Any command-line options contained in the PANDOC_OPTS environment variable
23−will be passed directly to \fBpandoc\fR. See \fBpandoc\fR(1)
24−for a list of options that may be used.
26+markdown2latex input.txt \-\- \-\-custom\-header=letterhead.tex
2527.SH "SEE ALSO"
2628\fBpandoc\fR(1),
2729\fBmarkdown2html\fR(1),
@@ -29,4 +31,4 @@ for a list of options that may be used.
2931\fBlatex2markdown\fR(1),
3032\fBmarkdown2pdf\fR(1)
3133.SH AUTHOR
32−John MacFarlane
34+John MacFarlane and Recai Oktas
man/man1/markdown2pdf.1+20−21
@@ -1,38 +1,37 @@
1−.TH PANDOC 1 "November 1, 2006" Linux "User Manuals"
1+.TH MARKDOWN2PDF 1 "November 21, 2006" Pandoc "User Manuals"
22.SH NAME
33markdown2pdf \- converts markdown-formatted text to PDF, using pdflatex
44.SH SYNOPSIS
5−\fBmarkdown2pdf\fR [ \fB-o|--output\fR \fIoutput-file\fR ]
6−[ \fIinput-file\fR ]
5+\fBmarkdown2pdf\fR [\fIoptions\fR] [\fB\-o\fR \fIoutput-file\fR]
6+[\fIinput-file\fR]... [\fB\-\-\fR] [\fIpandoc\-opts\fR]
77.SH DESCRIPTION
8−\fBmarkdown2pdf\fR converts \fIinput-file\fR (or text from STDIN) from
9−markdown-formatted plain text to PDF, using \fBpdflatex\fR. If no output
8+\fBmarkdown2pdf\fR converts \fIinput\-file\fR (or text from STDIN) from
9+markdown\-formatted plain text to PDF, using \fBpdflatex\fR. If no output
1010filename is specified, the name of the output file is derived from the
1111input file; thus, for example, if the input file is \fIhello.txt\fR,
1212the output file will be \fIhello.pdf\fR. If the input is read from STDIN
1313and no output filename is specified, the output file will be named
14−\fIstdin.pdf\fR.
14+\fIstdin.pdf\fR. If multiple input files are specified, they will be
15+concatenated before conversion, and the name of the output file will be
16+derived from the first input file.
1517.PP
1618\fBmarkdown2pdf\fR is a wrapper for \fBpandoc\fR.
1719.SH OPTIONS
1820.TP
19−.B \-o FILENAME, \-\-output=FILENAME
20−Specify name of output (PDF) file.
21−.TP
22−.B \-h, \-\-help
21+.B \-h
2322Show usage message.
2423.TP
25−.B \-\-
26−Any options appearing after ` \-\- ' on the command line will be passed
27−directly to \fBpandoc\fR. See \fBpandoc\fR(1) for a list of options
28−that may be used. Options specified in this way will override
29−PANDOC_OPTS (see below). Example:
24+.B \-o \fIoutput-file\fR
25+Specify name of output (PDF) file.
26+.TP
27+.I pandoc\-opts
28+Any options appearing after \fIinput\-file\fR... on the command line
29+will be passed directly to \fBpandoc\fR. If no \fIinput-file\fR
30+is specified, these options must be preceded by ` \fB\-\-\fR '.
31+(In other cases, ` \fB\-\-\fR ' is optional.) See \fBpandoc\fR(1)
32+for a list of options that may be used. Example:
3033.IP
31−markdown2pdf input.txt -- --custom-header=letterhead.tex
32−.SH ENVIRONMENT
33−Any command-line options contained in the PANDOC_OPTS environment variable
34−will be passed directly to \fBpandoc\fR. See \fBpandoc\fR(1)
35−for a list of options that may be used.
34+markdown2pdf input.txt \-\- \-\-custom\-header=letterhead.tex
3635.SH "SEE ALSO"
3736\fBpandoc\fR(1),
3837\fBmarkdown2html\fR(1),
@@ -41,4 +40,4 @@ for a list of options that may be used.
4140\fBlatex2markdown\fR(1),
4241\fBpdflatex\fR(1)
4342.SH AUTHOR
44−John MacFarlane
43+John MacFarlane and Recai Oktas
man/man1/pandoc.1+14−15
@@ -1,36 +1,35 @@
1−.TH PANDOC 1 "November 1, 2006" Linux "User Manuals"
1+.TH PANDOC 1 "November 21, 2006" Pandoc "User Manuals"
22.SH NAME
33pandoc \- general markup converter
44.SH SYNOPSIS
5−\fBpandoc\fR [ \fIoptions\fR ] [ \fIinput-files\fR ]
6−
5+\fBpandoc\fR [\fIoptions\fR] [\fIinput\-file\fR]...
76.SH DESCRIPTION
87\fIPandoc\fR converts files from one markup format to another. It can
98read markdown and (subsets of) reStructuredText, HTML, and LaTeX, and
109it can write markdown, reStructuredText, HTML, LaTeX, RTF, and S5 HTML
1110slide shows.
1211.PP
13−If no \fIinput-files\fR are specified, input is read from STDIN. Otherwise,
14−the \fIinput-files\fR are concatenated (with a blank line between each)
12+If no \fIinput\-file\fR is specified, input is read from STDIN. Otherwise,
13+the \fIinput\-files\fR are concatenated (with a blank line between each)
1514and used as input. Output goes to STDOUT. If you want output to a file,
1615use shell redirection:
1716.IP
1817.B pandoc input.txt > output.html
1918.PP
2019The default behavior of \fIPandoc\fR is to convert the input from
21−markdown-formatted plain text to HTML. Different input and output
22−formats can be specified using command-line options. For example,
20+markdown\-formatted plain text to HTML. Different input and output
21+formats can be specified using command\-line options. For example,
2322.IP
24−.B pandoc -f latex -t markdown chap1.tex > chap1.txt
23+.B pandoc \-f latex \-t markdown chap1.tex > chap1.txt
2524.PP
26−converts \fIchap1.tex\fR from LaTeX to markdown-formatted plain text.
27−See below for a detailed list of command-line options.
25+converts \fIchap1.tex\fR from LaTeX to markdown\-formatted plain text.
26+See below for a detailed list of command\-line options.
2827.PP
29−\fIPandoc\fR uses the UTF-8 character encoding for both input and output.
30−If your local character encoding is not UTF-8, you should pipe input
28+\fIPandoc\fR uses the UTF\-8 character encoding for both input and output.
29+If your local character encoding is not UTF\-8, you should pipe input
3130and output through \fBiconv\fR:
3231.IP
33−.B iconv -t utf-8 input.txt | pandoc | iconv -f utf-8
32+.B iconv \-t utf\-8 input.txt | pandoc | iconv \-f utf\-8
3433
3534.SH OPTIONS
3635.TP
@@ -40,7 +39,7 @@ Print version.
4039.B \-h, \-\-help
4140Show usage message.
4241.TP
43−.B \-f FORMAT, \-r FORMAT, --from=FORMAT, --read=FORMAT
42+.B \-f FORMAT, \-r FORMAT, \-\-from=FORMAT, \-\-read=FORMAT
4443Specify input format.
4544.I FORMAT
4645can be
@@ -56,7 +55,7 @@ or
5655.I latex
5756(LaTeX).
5857.TP
59−.B \-t FORMAT, \-w FORMAT, --to=FORMAT, --write=FORMAT
58+.B \-t FORMAT, \-w FORMAT, \-\-to=FORMAT, \-\-write=FORMAT
6059Specify output format.
6160.I FORMAT
6261can be
markdown2htmldeleted−31
@@ -1,31 +0,0 @@
1−#!/bin/sh -e
2−# converts markdown to HTML
3−
4−pathfind () { # portable which(1), code taken from Debian Developer's Reference
5− OLDIFS="$IFS"
6− IFS=:
7− for _p in $PATH; do
8− if [ -x "$_p/$*" ]; then
9− IFS="$OLDIFS"
10− return 0
11− fi
12− done
13− IFS="$OLDIFS"
14− return 1
15−}
16−
17−for p in pandoc; do
18− pathfind $p || {
19− echo >&2 "You need '$p' to use this program!"
20− exit 1
21− }
22−done
23−
24−ALL="$*"
25−ARGS=${ALL%% -- *} # only the part before ' -- ' delimiters is relevant
26−set -- $ARGS
27−
28−REST=${ALL#$ARGS}; REST=${REST# -- }
29−PANDOC_OPTS=${REST:-$PANDOC_OPTS}
30−
31−iconv -t utf-8 $* | pandoc $PANDOC_OPTS | iconv -f utf-8
markdown2latexdeleted−31
@@ -1,31 +0,0 @@
1−#!/bin/sh -e
2−# converts markdown to latex
3−
4−pathfind () { # portable which(1), code taken from Debian Developer's Reference
5− OLDIFS="$IFS"
6− IFS=:
7− for _p in $PATH; do
8− if [ -x "$_p/$*" ]; then
9− IFS="$OLDIFS"
10− return 0
11− fi
12− done
13− IFS="$OLDIFS"
14− return 1
15−}
16−
17−for p in pandoc; do
18− pathfind $p || {
19− echo >&2 "You need '$p' to use this program!"
20− exit 1
21− }
22−done
23−
24−ALL="$*"
25−ARGS=${ALL%% -- *} # only the part before ' -- ' delimiters is relevant
26−set -- $ARGS
27−
28−REST=${ALL#$ARGS}; REST=${REST# -- }
29−PANDOC_OPTS=${REST:-$PANDOC_OPTS}
30−
31−iconv -t utf-8 $* | pandoc $PANDOC_OPTS -w latex -s | iconv -f utf-8
markdown2pdfdeleted−113
@@ -1,113 +0,0 @@
1−#!/bin/sh
2−# converts markdown to latex, then uses latex to make a PDF
3−
4−pathfind () { # portable which(1), code taken from Debian Developer's Reference
5− OLDIFS="$IFS"
6− IFS=:
7− for _p in $PATH; do
8− if [ -x "$_p/$*" ]; then
9− IFS="$OLDIFS"
10− return 0
11− fi
12− done
13− IFS="$OLDIFS"
14− return 1
15−}
16−
17−for p in pandoc pdflatex; do
18− pathfind $p || {
19− echo >&2 "You need '$p' to use this program!"
20− exit 1
21− }
22−done
23−
24−ALL="$*"
25−ARGS=${ALL%% -- *} # only the part before ' -- ' delimiters is relevant
26−set -- $ARGS
27−
28−REST=${ALL#$ARGS}; REST=${REST# -- }
29−PANDOC_OPTS=${REST:-$PANDOC_OPTS}
30−
31−outfile=
32−for option; do
33− if [ -n "$prev" ]; then
34− eval "$prev=\$option"
35− prev=
36− shift
37− continue
38− fi
39− optarg=$(expr "x$option" : 'x[^=]*=\(.*\)')
40− case $option in
41− -h | --h | --help )
42− help=1
43− shift ;;
44− -o | --o | --output )
45− prev=outfile
46− shift ;;
47− -o=* | --o=* | --output=* )
48− outfile=$optarg
49− shift ;;
50− -* ) echo >&2 "$0: unknown option: $option; aborting"
51− exit 1 ;;
52− * ) break ;;
53− esac
54−done
55−
56−[ -z "$help" ] || {
57− echo >&2 "Usage: $0 [-o|--output output-file] [input-file]"
58− exit 0
59−}
60−
61−infile=$1
62−
63−if ! [ -r $infile ]; then
64− echo >&2 "'$infile' not found"
65− exit 1
66−fi
67−
68−if [ $# -gt 1 ]; then
69− shift
70− echo >&2 "Warning: extra arguments '$@' will be ignored!"
71−fi
72−
73−if [ -z "$outfile" ]; then
74− if [ -n "$infile" ]; then
75− outfile=${infile%.*}.pdf
76− else
77− outfile='stdin.pdf' # input is STDIN, since no argument given
78− fi
79−fi
80−
81−BASE=${outfile##*/}
82−BASE=${BASE%.*}
83−
84−set -e
85−
86−TEMP=${TMPDIR-/tmp}/markdown2pdf.$$
87−trap "status=$?; rm -rf $TEMP; exit $status" 0 INT
88−mkdir -p $TEMP
89−
90−iconv -t utf-8 $infile | \
91−pandoc $PANDOC_OPTS -w latex -s | \
92−iconv -f utf-8 > $TEMP/$BASE.tex && (
93− cd $TEMP
94− if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
95− echo >&2 "LaTeX errors:"
96− sed -ne '/^!/,/^ *$/p' $BASE.log >&2
97− exit 1
98− fi
99−) || exit $?
100−
101−is_target_exists=
102−if [ -f $outfile ]; then
103− is_target_exists=1
104− mv -f $outfile $outfile~
105−fi
106−
107−mv -f $TEMP/$BASE.pdf $outfile
108−
109−printf "Created $outfile" >&2
110−[ -z "$is_target_exists" ] || {
111− printf " (previous file has been backed up as '$outfile~')" >&2
112−}
113−echo >&2 .
src/wrappers/checkin.shnew file+7
@@ -0,0 +1,7 @@
1+# Check if input files exist.
2+for f; do
3+ if [ -n "$f" ] && ! [ -f "$f" ]; then
4+ err "File '$f' not found."
5+ exit 1
6+ fi
7+done
src/wrappers/common.shnew file+56
@@ -0,0 +1,56 @@
1+THIS=${0##*/}
2+
3+NEWLINE='
4+'
5+WRAPPER_ARGS=
6+WRAPPEE_ARGS=
7+
8+err () { echo "$*" | fold -s -w ${COLUMNS:-110} >&2; }
9+errn () { printf "$*" | fold -s -w ${COLUMNS:-110} >&2; }
10+
11+usage () {
12+ synopsis="$@"
13+ err "Usage: $THIS $synopsis"
14+ err "See $THIS(1) man file for details."
15+}
16+
17+runpandoc () {
18+ if [ -n "$WRAPPEE_ARGS" ]; then
19+ # Unpack arguments that will be passed to pandoc.
20+ oldifs="$IFS"; IFS="$NEWLINE"; set -- $WRAPPEE_ARGS "$@"; IFS="$oldifs"
21+ case "$1" in --) shift;; esac # tolerate the existence of a leading '--'
22+ fi
23+
24+ pandoc "$@"
25+}
26+
27+# Portable which(1).
28+pathfind () {
29+ oldifs="$IFS"; IFS=':'
30+ for _p in $PATH; do
31+ if [ -x "$_p/$*" ] && [ -f "$_p/$*" ]; then
32+ IFS="$oldifs"
33+ return 0
34+ fi
35+ done
36+ IFS="$oldifs"
37+ return 1
38+}
39+
40+HAVE_ICONV=
41+if pathfind iconv; then
42+ HAVE_ICONV=1
43+ alias to_utf8='iconv -t utf-8'
44+ alias from_utf8='iconv -f utf-8'
45+else
46+ err "Warning: iconv not present. Assuming UTF-8 character encoding."
47+ alias to_utf8='cat'
48+ alias from_utf8='cat'
49+fi
50+
51+for p in pandoc $REQUIRED; do
52+ pathfind $p || {
53+ err "You need '$p' to use this program!"
54+ exit 1
55+ }
56+done
src/wrappers/getopts.shnew file+12
@@ -0,0 +1,12 @@
1+if [ -z "$SYNOPSIS" ]; then
2+ SYNOPSIS="[-h] [input_file]"
3+ [ -n "$THIS_NARG" ] || SYNOPSIS="${SYNOPSIS}..."
4+fi
5+
6+while getopts h opt; do
7+ case $opt in
8+ h|?) usage "$SYNOPSIS"; exit 2 ;;
9+ esac
10+done
11+
12+shift $(($OPTIND - 1))
src/wrappers/html2markdown.innew file+134
@@ -0,0 +1,134 @@
1+#!/bin/sh -e
2+# converts html to markdown
3+# uses an available program to fetch URL and tidy to normalize it first
4+
5+REQUIRED=tidy
6+
7+### common.sh
8+
9+grab_url_with () {
10+ url="${1:?internal error: grab_url_with: url required}"
11+
12+ shift
13+ cmdline="$@"
14+
15+ prog=
16+ prog_opts=
17+ if [ -n "$cmdline" ]; then
18+ eval "set -- $cmdline"
19+ prog=$1
20+ shift
21+ prog_opts="$@"
22+ fi
23+
24+ if [ -z "$prog" ]; then
25+ # Locate a sensible web grabber (note the order).
26+ for p in wget lynx w3m curl links w3c; do
27+ if pathfind $p; then
28+ prog=$p
29+ break
30+ fi
31+ done
32+
33+ [ -n "$prog" ] || {
34+ errn "$THIS: Couldn't find a program to fetch the file from URL "
35+ err "(e.g. wget, w3m, lynx, w3c, or curl)."
36+ return 1
37+ }
38+ else
39+ pathfind "$prog" || {
40+ err "$THIS: No such web grabber '$prog' found; aborting."
41+ return 1
42+ }
43+ fi
44+
45+ # Setup proper base options for known grabbers.
46+ base_opts=
47+ case "$prog" in
48+ wget) base_opts="-O-" ;;
49+ lynx) base_opts="-source" ;;
50+ w3m) base_opts="-dump_source" ;;
51+ curl) base_opts="" ;;
52+ links) base_opts="-source" ;;
53+ w3c) base_opts="-n -get" ;;
54+ *) err "$THIS: unhandled web grabber '$prog'; hope it succeeds."
55+ esac
56+
57+ err "$THIS: invoking '$prog $base_opts $prog_opts $url'..."
58+ eval "set -- $base_opts $prog_opts"
59+ $prog "$@" "$url"
60+}
61+
62+encoding=
63+grabber=
64+nograb=
65+while getopts e:g:nh opt; do
66+ case $opt in
67+ e) encoding="$OPTARG" ;;
68+ g) grabber="$OPTARG" ;;
69+ n) nograb=1 ;;
70+ h|?)
71+ usage "[-e encoding] [-g grabber_command] [-n] [-h] [input_file|url]"
72+ exit 2 ;;
73+ esac
74+done
75+
76+shift $(($OPTIND - 1))
77+
78+### postopts.sh
79+
80+### singlearg.sh
81+
82+inurl=
83+if [ -n "$1" ] && ! [ -f "$1" ]; then
84+ if [ -n "$nograb" ]; then
85+ err "'$1' not found; refusing to treat input as URL."
86+ exit 1
87+ fi
88+ # Treat given argument as an URL.
89+ inurl="$1"
90+fi
91+
92+if [ -n "$inurl" ]; then
93+ err "Attempting to fetch file from '$inurl'..."
94+
95+ ### tempdir.sh
96+
97+ grabber_out=$THIS_TEMPDIR/grabber.out
98+ grabber_log=$THIS_TEMPDIR/grabber.log
99+ if ! grab_url_with "$inurl" "$grabber" 1>$grabber_out \
100+ 2>$grabber_log; then
101+ errn "grab_url_with failed"
102+ if [ -f $grabber_log ]; then
103+ err " with the following error log."
104+ err
105+ cat >&2 $grabber_log
106+ else
107+ err .
108+ fi
109+ exit 1
110+ fi
111+
112+ set -- $grabber_out
113+fi
114+
115+if [ -z "$encoding" ] && [ "x$@" != "x" ]; then
116+ # Try to determine character encoding unless not specified
117+ # and input is STDIN.
118+ encoding=$(
119+ head "$@" |
120+ LC_ALL=C tr 'A-Z' 'a-z' |
121+ sed -ne '/<meta .*content-type.*charset=/ {
122+ s/.*charset=["'\'']*\([-a-zA-Z0-9]*\).*["'\'']*/\1/p
123+ }'
124+ )
125+fi
126+
127+if [ -n "$encoding" ] && [ -n "$HAVE_ICONV" ]; then
128+ alias to_utf8='iconv -f "$encoding" -t utf-8'
129+elif [ -n "$inurl" ]; then # assume web pages are UTF-8
130+ alias to_utf8='cat'
131+fi # else just use local encoding
132+
133+to_utf8 "$@" | tidy -utf8 2>/dev/null |
134+runpandoc -r html -w markdown -s | from_utf8
src/wrappers/latex2markdown.innew file+14
@@ -0,0 +1,14 @@
1+#!/bin/sh -e
2+# runs pandoc to convert latex to markdown
3+
4+### common.sh
5+
6+### getopts.sh
7+
8+### postopts.sh
9+
10+### singlearg.sh
11+
12+### checkin.sh
13+
14+to_utf8 "$@" | runpandoc -r latex -w markdown -s | from_utf8
src/wrappers/markdown2html.innew file+12
@@ -0,0 +1,12 @@
1+#!/bin/sh -e
2+# converts markdown to HTML
3+
4+### common.sh
5+
6+### getopts.sh
7+
8+### postopts.sh
9+
10+### checkin.sh
11+
12+to_utf8 "$@" | runpandoc | from_utf8
src/wrappers/markdown2latex.innew file+12
@@ -0,0 +1,12 @@
1+#!/bin/sh -e
2+# converts markdown to latex
3+
4+### common.sh
5+
6+### getopts.sh
7+
8+### postopts.sh
9+
10+### checkin.sh
11+
12+to_utf8 "$@" | runpandoc -w latex -s | from_utf8
src/wrappers/markdown2pdf.innew file+64
@@ -0,0 +1,64 @@
1+#!/bin/sh -e
2+# converts markdown to latex, then uses latex to make a PDF
3+
4+REQUIRED=pdflatex
5+
6+### common.sh
7+
8+outfile=
9+while getopts o:h opt; do
10+ case $opt in
11+ o) outfile="$OPTARG" ;;
12+ h|?) usage "[-o output_file] [-h] [input_file]..."; exit 2 ;;
13+ esac
14+done
15+
16+shift $(($OPTIND - 1))
17+
18+### postopts.sh
19+
20+### checkin.sh
21+
22+if [ -z "$outfile" ]; then
23+ if [ -n "$1" ]; then
24+ outfile="${1%.*}"
25+ else
26+ outfile="stdin" # input is STDIN, since no argument given
27+ fi
28+fi
29+case "$outfile" in
30+*.*) ;; # skip appending extension if one is already present
31+*) outfile="${outfile%.*}.pdf";;
32+esac
33+
34+### tempdir.sh
35+
36+# We should use a filename without white spaces for pdflatex.
37+TEXNAME=$THIS
38+
39+to_utf8 "$@" | runpandoc -w latex -s >$THIS_TEMPDIR/$TEXNAME.tex
40+(
41+ cd $THIS_TEMPDIR
42+ if ! pdflatex -interaction=batchmode $TEXNAME.tex >/dev/null 2>&1; then
43+ err "LaTeX errors:"
44+ from_utf8 $TEXNAME.log | sed -ne '/^!/,/^ *$/p' >&2
45+ if grep -q "File \`ucs.sty' not found" $TEXNAME.log; then
46+ err "Please install the 'unicode' package from ctan.org."
47+ fi
48+ exit 1
49+ fi
50+)
51+
52+is_target_exists=
53+if [ -f "$outfile" ]; then
54+ is_target_exists=1
55+ mv -f "$outfile" "$outfile~"
56+fi
57+
58+mv -f $THIS_TEMPDIR/$TEXNAME.pdf "$outfile"
59+
60+errn "Created '$outfile'"
61+[ -z "$is_target_exists" ] || {
62+ errn " (previous file has been backed up as '$outfile~')"
63+}
64+err .
src/wrappers/postopts.shnew file+17
@@ -0,0 +1,17 @@
1+# Parse wrapper and wrappee (pandoc) arguments by taking
2+# into account that they may have space or tab characters.
3+pick="WRAPPER_ARGS"
4+while [ $# -gt 0 ]; do
5+ if [ "$pick" = "WRAPPER_ARGS" ]; then
6+ case "$1" in
7+ -*) pick="WRAPPEE_ARGS" ;;
8+ esac
9+ fi
10+ # Pack args with NEWLINE to preserve spaces,
11+ # and put them into the picked variable.
12+ eval "$pick=\"\$${pick}${NEWLINE}${1}\""
13+ shift
14+done
15+
16+# Unpack filename arguments. Now "$@" will hold the filenames.
17+oldifs="$IFS"; IFS="$NEWLINE"; set -- $WRAPPER_ARGS; IFS="$oldifs"
src/wrappers/singlearg.shnew file+7
@@ -0,0 +1,7 @@
1+# Ensure to work with a single argument.
2+if [ $# -gt 1 ]; then
3+ first_arg="$1"
4+ shift
5+ err "Warning: extra arguments '$@' will be ignored."
6+ set -- $first_arg
7+fi
src/wrappers/tempdir.shnew file+10
@@ -0,0 +1,10 @@
1+# As a security measure refuse to proceed if mktemp is not available.
2+pathfind mktemp || { err "Couldn't find 'mktemp'; aborting."; exit 1; }
3+
4+THIS_TEMPDIR=
5+THIS_TEMPDIR="$(mktemp -d -t $THIS.XXXXXXXX)" || exit 1
6+readonly THIS_TEMPDIR
7+
8+trap 'exitcode=$?
9+ [ -z "$THIS_TEMPDIR" ] || rm -rf "$THIS_TEMPDIR"
10+ exit $exitcode' 0 1 2 3 13 15
src/wrappers/testwrapper.innew file+141
@@ -0,0 +1,141 @@
1+#!/bin/sh
2+
3+THIS=$1
4+
5+ASH="ash -s"
6+BASH="bash --posix -s"
7+DASH="dash -s"
8+KSH="ksh -s"
9+POSH="posh -s"
10+ZSH="zsh -s"
11+
12+ERROR=""
13+
14+wrapper () {
15+ $SH -- "$@" <<-'EOF'
16+### common.sh
17+
18+outfile=
19+while getopts o: opt; do
20+ case $opt in
21+ o) outfile="$OPTARG" ;;
22+ esac
23+done
24+
25+shift $(($OPTIND - 1))
26+
27+### postopts.sh
28+
29+echo "Options passed to wrapper:"
30+[ -z "$outfile" ] || echo "|$outfile|"
31+
32+echo "Arguments passed to wrapper:"
33+for arg; do
34+ echo "|$arg|"
35+done
36+
37+pandoc () {
38+ echo "Arguments passed to wrappee:"
39+ for arg; do
40+ echo "|$arg|"
41+ done
42+}
43+runpandoc
44+EOF
45+}
46+
47+# Portable which(1).
48+pathfind () {
49+ oldifs="$IFS"; IFS=':'
50+ for _p in $PATH; do
51+ if [ -x "$_p/$*" ] && [ -f "$_p/$*" ]; then
52+ IFS="$oldifs"
53+ return 0
54+ fi
55+ done
56+ IFS="$oldifs"
57+ return 1
58+}
59+
60+check_results () {
61+ if [ "$1" = "$2" ]; then
62+ echo >&2 ok
63+ return 0
64+ else
65+ echo >&2 failed
66+ sed "s/^/\t/" >&2 <<EOF
67+Command line: '$3'
68+===> Expected:
69+$2
70+<=== Got:
71+$1
72+EOF
73+ return 1
74+ fi
75+}
76+
77+for SH in "$BASH" "$DASH" "$KSH" "$ZSH"; do
78+ CMD=${SH%% *}
79+ echo >&2 " Testing with $CMD..."
80+ if pathfind "$CMD"; then
81+ if [ "$CMD" = "zsh" ]; then
82+ # Zsh needs to be called as 'sh' to enable POSIX mode.
83+ ln -s $(which zsh) ./sh
84+ SH="./sh ${SH#* }"
85+ trap 'err=$?; rm -f ./sh; exit $err' 0 1 2 3 13 15
86+ fi
87+
88+ set -e
89+
90+ # Test 1
91+ printf >&2 " test case 1... "
92+ actual=$(wrapper -o "output file" "foo bar" -A "quux baz" -B)
93+ expected=$(cat <<'EOF'
94+Options passed to wrapper:
95+|output file|
96+Arguments passed to wrapper:
97+|foo bar|
98+Arguments passed to wrappee:
99+|-A|
100+|quux baz|
101+|-B|
102+EOF
103+)
104+ check_results "$actual" "$expected" \
105+ 'wrapper -o "output file" "foo bar" -A "quux baz" -B'
106+
107+ # Test 2
108+ printf >&2 " test case 2... "
109+ actual=$(wrapper -- -A "foo bar")
110+ expected=$(cat <<'EOF'
111+Options passed to wrapper:
112+Arguments passed to wrapper:
113+Arguments passed to wrappee:
114+|-A|
115+|foo bar|
116+EOF
117+)
118+ check_results "$actual" "$expected" 'wrapper -- -A "foo bar"'
119+
120+ # Test 3 (Test 1 with a redundant '--')
121+ printf >&2 " test case 4... "
122+ actual=$(wrapper -o "output file" "foo bar" -- -A "quux baz" -B)
123+ expected=$(cat <<'EOF'
124+Options passed to wrapper:
125+|output file|
126+Arguments passed to wrapper:
127+|foo bar|
128+Arguments passed to wrappee:
129+|-A|
130+|quux baz|
131+|-B|
132+EOF
133+)
134+ check_results "$actual" "$expected" \
135+ 'wrapper -o "output file" "foo bar" -- -A "quux baz" -B'
136+ else
137+ echo >&2 "Warning: cannot verify correctness with $CMD; shell not available"
138+ fi
139+done
140+
141+exit 0