git.iko.soy/typeable/pandoc
on master help sign in
Merge changes in branches/wrappers into trunk.
426cbadroktas
Makefile+32−5
@@ -6,6 +6,7 @@
6CABAL := Pandoc.cabal
6CABAL := Pandoc.cabal
7SRCDIR := src
7SRCDIR := src
8MANDIR := man
8MANDIR := man
9+TESTDIR := tests
9BUILDDIR := dist
10BUILDDIR := dist
10BUILDCONF := .setup-config
11BUILDCONF := .setup-config
11BUILDCMD := runhaskell Setup.hs
12BUILDCMD := runhaskell Setup.hs
@@ -24,7 +25,8 @@ MAIN := $(firstword $(EXECS))
24#-------------------------------------------------------------------------------
25#-------------------------------------------------------------------------------
25# Install targets
26# Install targets
26#-------------------------------------------------------------------------------
27#-------------------------------------------------------------------------------
27−PROGS := $(EXECS) html2markdown markdown2html latex2markdown markdown2latex markdown2pdf
28+WRAPPERS := html2markdown latex2markdown markdown2html markdown2latex markdown2pdf
29+PROGS := $(EXECS) $(WRAPPERS)
28DOCS := README.html README BUGS TODO
30DOCS := README.html README BUGS TODO
29
31
30#-------------------------------------------------------------------------------
32#-------------------------------------------------------------------------------
@@ -86,6 +88,27 @@ templates: $(SRCDIR)/templates
86$(SRCDIR)/templates:
88$(SRCDIR)/templates:
87 $(MAKE) -C $(SRCDIR)/templates
89 $(MAKE) -C $(SRCDIR)/templates
88
90
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+
89cleanup_files+=$(CABAL)
112cleanup_files+=$(CABAL)
90$(CABAL): cabalize $(CABAL).in
113$(CABAL): cabalize $(CABAL).in
91 ./cabalize <$(CABAL).in >$(CABAL)
114 ./cabalize <$(CABAL).in >$(CABAL)
@@ -104,7 +127,7 @@ build: templates configure
104 $(BUILDCMD) build
127 $(BUILDCMD) build
105
128
106.PHONY: build-exec
129.PHONY: build-exec
107−build-exec: $(EXECS)
130+build-exec: $(PROGS)
108cleanup_files+=$(EXECS)
131cleanup_files+=$(EXECS)
109$(EXECS): build
132$(EXECS): build
110 for f in $@; do \
133 for f in $@; do \
@@ -250,11 +273,15 @@ osx-dmg: ../$(osx_dmg_name)
250 -rm -f $(osx_dmg_name)
273 -rm -f $(osx_dmg_name)
251 mv $(osx_udzo_name) ../$(osx_dmg_name)
274 mv $(osx_udzo_name) ../$(osx_dmg_name)
252
275
253−.PHONY: test test-markdown
276+.PHONY: test test-markdown test-wrapper
254test: $(MAIN)
277test: $(MAIN)
255− @cd tests && perl runtests.pl -s $(PWD)/$(MAIN)
278+ @cd $(TESTDIR) && perl runtests.pl -s $(PWD)/$(MAIN)
256test-markdown: $(MAIN)
279test-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
258
285
259# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
286# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
260src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
287src_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
39from those files. It accepts several command-line options. For a
39from those files. It accepts several command-line options. For a
40list, type
40list, type
41
41
42− pandoc -h
42+ pandoc -h
43
43
44The most important options specify the format of the source file and
44The most important options specify the format of the source file and
45the output. The default reader is markdown; the default writer is
45the output. The default reader is markdown; the default writer is
46HTML. So if you don't specify a reader or writer, `pandoc` will
46HTML. So if you don't specify a reader or writer, `pandoc` will
47convert markdown to HTML. For example,
47convert markdown to HTML. For example,
48
48
49− pandoc hello.txt
49+ pandoc hello.txt
50
50
51will convert `hello.txt` from markdown to HTML. For other conversions,
51will convert `hello.txt` from markdown to HTML. For other conversions,
52you must specify a reader and/or a writer using the `-r` and `-w`
52you must specify a reader and/or a writer using the `-r` and `-w`
53flags. To convert markdown to LaTeX, you would write:
53flags. To convert markdown to LaTeX, you would write:
54
54
55− pandoc -w latex hello.txt
55+ pandoc -w latex hello.txt
56
56
57To convert html to markdown:
57To convert html to markdown:
58
58
59− pandoc -r html -w markdown hello.txt
59+ pandoc -r html -w markdown hello.txt
60
60
61Supported writers include `markdown`, `latex`, `html`, `rtf` (rich text
61Supported writers include `markdown`, `latex`, `html`, `rtf` (rich text
62format), `rst` (reStructuredText), and `s5` (which produces an HTML
62format), `rst` (reStructuredText), and `s5` (which produces an HTML
@@ -120,72 +120,74 @@ before the files can be found by TeX.)
120
120
121# The shell scripts
121# The shell scripts
122
122
123−For convenience, five shell scripts have been included that make it
123+Five shell scripts have been included that make it easy to run
124+`pandoc` without worrying about character encodings, and without
124−easy to run `pandoc` without remembering all the command-line options.
125+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`.)
129
126
130−1. `markdown2html` converts markdown to HTML. (This can be used
127+- `markdown2html` converts markdown-formatted text to HTML
131− as a replacement for `Markdown.pl`.)
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
132
133
133−2. `html2markdown` can take either a filename or a URL as argument. If
134+All of the scripts use `iconv` (if available) to convert to and from
134− it is given a URL, it uses `curl`, `wget`, or an available text-based
135+the local character encoding. All of the scripts presuppose that
135− browser to fetch the contents of the specified URL, then filters this
136+`pandoc` is in the path, and some have additional requirements. (For
136− through `tidy` to straighten up the HTML, and finally passes
137+example, `html2markdown` uses `tidy`, and `markdown2pdf` uses
137− this HTML to `pandoc` to produce markdown text:
138+`pdflatex`.)
138
139
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.)
140
148
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:
142
151
143− html2markdown subdir/mylocalfile.html
152+ latex2markdown sample.tex > sample.txt
144
153
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,
146
156
147− latex2markdown mytexfile.tex
157+ markdown2pdf sample.txt endnotes.txt
148
158
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:
150
162
151− markdown2latex mytextfile.txt
163+ markdown2pdf -o "My Book.pdf" chap1.txt chap2.txt chap3.txt
152
164
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,
154
169
155− markdown2pdf mytextfile.txt
170+ markdown2html tusks.txt -S -T Elephants
156
171
157− creates a file `mytextfile.pdf`. To specify a different
172+will convert `tusks.txt` to `tusks.html` using smart quotes, ellipses,
158− name for the output file, use the `-o` option:
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 ` -- `:
159
177
160− markdown2pdf -o final-draft.pdf mytextfile.txt
178+ cat tusks.txt | markdown2html -- -S -T Elephants
161
179
162−If you want to use `pandoc`'s command-line options in these scripts,
180+The ` -- ` separator may optionally be used when there are command-line
163−put the options in the environment variable `PANDOC_OPTS`. For
181+arguments:
164−example, to convert `tusks.txt` to `tusks.html` using smart quotes,
165−ellipses, and dashes, with "Elephants" as the page title prefix:
166
182
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
183+ markdown2html -- tusks.txt -S -T Elephants
179−
180−Options specified in this way will override any options set in
181−`PANDOC_OPTS`.
182
184
183# Command-line options
185# Command-line options
184
186
185Various command-line options can be used to customize the output.
187Various command-line options can be used to customize the output.
186For a complete list, type
188For a complete list, type
187
189
188− pandoc --help
190+ pandoc --help
189
191
190`-p` or `--preserve-tabs` causes tabs in the source text to be
192`-p` or `--preserve-tabs` causes tabs in the source text to be
191preserved, rather than converted to spaces (the default).
193preserved, rather than converted to spaces (the default).
@@ -264,13 +266,13 @@ markdown test suite, type `make test-markdown`.)
264Pandoc behaves differently from standard markdown on some "edge
266Pandoc behaves differently from standard markdown on some "edge
265cases" involving lists. Consider this source:
267cases" involving lists. Consider this source:
266
268
267− 1. First
269+ 1. First
268− 2. Second:
270+ 2. Second:
269− - Fee
271+ - Fee
270− - Fie
272+ - Fie
271− - Foe
273+ - Foe
272
274
273− 3. Third
275+ 3. Third
274
276
275Pandoc transforms this into a "compact list" (with no `<p>` tags
277Pandoc transforms this into a "compact list" (with no `<p>` tags
276around "First", "Second", or "Third"), while markdown puts `<p>`
278around "First", "Second", or "Third"), while markdown puts `<p>`
@@ -286,20 +288,20 @@ is followed by a blank line is irrelevant.
286Standard markdown allows unescaped literal quotes in titles, as
288Standard markdown allows unescaped literal quotes in titles, as
287in
289in
288
290
289− [foo]: "bar "embedded" baz"
291+ [foo]: "bar "embedded" baz"
290
292
291Pandoc requires all quotes within titles to be escaped:
293Pandoc requires all quotes within titles to be escaped:
292
294
293− [foo]: "bar \"embedded\" baz"
295+ [foo]: "bar \"embedded\" baz"
294
296
295## Reference links
297## Reference links
296
298
297Pandoc allows implicit reference links in either of two styles:
299Pandoc allows implicit reference links in either of two styles:
298
300
299− 1. Here's my [link]
301+ 1. Here's my [link]
300− 2. Here's my [link][]
302+ 2. Here's my [link][]
301
303
302− [link]: linky.com
304+ [link]: linky.com
303
305
304If there's no corresponding reference, the implicit reference link
306If there's no corresponding reference, the implicit reference link
305will appear as regular bracketed text. Note: even `[link][]` will
307will appear as regular bracketed text. Note: even `[link][]` will
@@ -313,18 +315,18 @@ Pandoc's markdown allows footnotes, using the following syntax:
313 here is a footnote reference,^(1) and another.^(longnote)
315 here is a footnote reference,^(1) and another.^(longnote)
314
316
315 ^(1) Here is the footnote. It can go anywhere in the document,
317 ^(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.
317
319
318 ^(longnote) Here's the other note. This one contains multiple
320 ^(longnote) Here's the other note. This one contains multiple
319 blocks.
321 blocks.
320 ^
322 ^
321 ^ Caret characters are used to indicate that the blocks all belong
323 ^ 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).
323 ^
325 ^
324 ^ If you want, you can use a caret at the beginning of every line,
326 ^ 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
327+ ^ 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
328+ ^ beginning of the first line of the block and any preceding
327− ^ blank lines.
329+ ^ blank lines.
328
330
329Footnote references may not contain spaces, tabs, or newlines.
331Footnote references may not contain spaces, tabs, or newlines.
330
332
@@ -335,21 +337,21 @@ Markdown 1.0. While Markdown 1.0 leaves HTML blocks exactly as they
335are, Pandoc treats text between HTML tags as markdown. Thus, for
337are, Pandoc treats text between HTML tags as markdown. Thus, for
336example, Pandoc will turn
338example, Pandoc will turn
337
339
338− <table>
340+ <table>
339− <tr>
341+ <tr>
340− <td>*one*</td>
342+ <td>*one*</td>
341− <td>[a link](http://google.com)</td>
343+ <td>[a link](http://google.com)</td>
342− </tr>
344+ </tr>
343− </table>
345+ </table>
344
346
345into
347into
346
348
347− <table>
349+ <table>
348− <tr>
350+ <tr>
349− <td><em>one</em></td>
351+ <td><em>one</em></td>
350− <td><a href="http://google.com">a link</a></td>
352+ <td><a href="http://google.com">a link</a></td>
351− </tr>
353+ </tr>
352− </table>
354+ </table>
353
355
354whereas Markdown 1.0 will preserve it as is.
356whereas Markdown 1.0 will preserve it as is.
355
357
@@ -426,10 +428,10 @@ include BibTeX citations:
426You can also use LaTeX environments. For example,
428You can also use LaTeX environments. For example,
427
429
428 \begin{tabular}{|l|l|}\hline
430 \begin{tabular}{|l|l|}\hline
429− Age & Frequency \\ \hline
431+ Age & Frequency \\ \hline
430 18--25 & 15 \\
432 18--25 & 15 \\
431− 26--35 & 33 \\
433+ 26--35 & 33 \\
432− 36--45 & 22 \\ \hline
434+ 36--45 & 22 \\ \hline
433 \end{tabular}
435 \end{tabular}
434
436
435Note, however, that material between the begin and end tags will
437Note, however, that material between the begin and end tags will
@@ -441,14 +443,14 @@ When run with the "standalone" option (`-s`), `pandoc` creates a
441standalone file, complete with an appropriate header. To see the
443standalone file, complete with an appropriate header. To see the
442default headers used for html and latex, use the following commands:
444default headers used for html and latex, use the following commands:
443
445
444− pandoc -D html
446+ pandoc -D html
445
447
446− pandoc -D latex
448+ pandoc -D latex
447
449
448If you want to use a different header, just create a file containing
450If you want to use a different header, just create a file containing
449it and specify it on the command line as follows:
451it and specify it on the command line as follows:
450
452
451− pandoc --header=MyHeaderFile
453+ pandoc --header=MyHeaderFile
452
454
453# Producing S5 with Pandoc
455# Producing S5 with Pandoc
454
456
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"
2.SH NAME
2.SH NAME
3html2markdown \- converts HTML to markdown-formatted text
3html2markdown \- converts HTML to markdown-formatted text
4.SH SYNOPSIS
4.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]
6.SH DESCRIPTION
7.SH DESCRIPTION
7−\fBhtml2markdown\fR converts \fIinput-file\fR or \fIURL\fR
8+\fBhtml2markdown\fR converts \fIinput\-file\fR or \fIURL\fR (or text
8−(or text from STDIN) from HTML to markdown-formatted plain text.
9+from STDIN) from HTML to markdown\-formatted plain text.
10+If a URL is specified, \fBhtml2markdown\fR uses an available program
9−It uses an available program (e.g. wget, w3m, lynx or curl) to fetch
11+(e.g. wget, w3m, lynx or curl) to fetch its contents. Output is sent
10−the contents of the URL.
12+to STDOUT.
11.PP
13.PP
12\fBhtml2markdown\fR is a wrapper for \fBpandoc\fR.
14\fBhtml2markdown\fR is a wrapper for \fBpandoc\fR.
13.SH OPTIONS
15.SH OPTIONS
14.TP
16.TP
15−.B \-\-
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
16−Any options appearing after ` \-\- ' on the command line will be passed
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
17−directly to \fBpandoc\fR. See \fBpandoc\fR(1) for a list of options
48+optional.) See \fBpandoc\fR(1) for a list of options that may be used.
18−that may be used. Options specified in this way will override
19−PANDOC_OPTS (see below). Example:
49+Example:
20.IP
50.IP
21−html2markdown input.txt -- -R
51+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.
26.SH "SEE ALSO"
52.SH "SEE ALSO"
27\fBpandoc\fR(1),
53\fBpandoc\fR(1),
28\fBmarkdown2html\fR(1),
54\fBmarkdown2html\fR(1),
29\fBmarkdown2latex\fR(1),
55\fBmarkdown2latex\fR(1),
30\fBlatex2markdown\fR(1),
56\fBlatex2markdown\fR(1),
31−\fBmarkdown2pdf\fR(1)
57+\fBmarkdown2pdf\fR(1),
58+\fBiconv\fR(1)
32.SH AUTHOR
59.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"
2.SH NAME
2.SH NAME
3−latex2markdown \- converts LaTeX to markdown-formatted text
3+latex2markdown \- converts LaTeX to markdown\-formatted text
4.SH SYNOPSIS
4.SH SYNOPSIS
5−\fBlatex2markdown\fR [ \fIinput-file\fR ]
5+\fBlatex2markdown\fR [\fIoptions\fR] [\fIinput\-file\fR]
6+[\fB\-\-\fR] [\fIpandoc\-opts\fR]
6.SH DESCRIPTION
7.SH DESCRIPTION
7−\fBlatex2markdown\fR converts \fIinput-file\fR
8+\fBlatex2markdown\fR converts \fIinput\-file\fR
8−(or text from STDIN) from LaTeX to markdown-formatted plain text.
9+(or text from STDIN) from LaTeX to markdown\-formatted plain text.
10+Output is sent to STDOUT.
9.PP
11.PP
10\fBlatex2markdown\fR is a wrapper for \fBpandoc\fR.
12\fBlatex2markdown\fR is a wrapper for \fBpandoc\fR.
11.SH OPTIONS
13.SH OPTIONS
12.TP
14.TP
13−.B \-\-
15+.B \-h
16+Show usage message.
17+.TP
18+.I pandoc\-opts
14−Any options appearing after ` \-\- ' on the command line will be passed
19+Any options appearing after \fIinput\-file\fR on the command line
15−directly to \fBpandoc\fR. See \fBpandoc\fR(1) for a list of options
20+will be passed directly to \fBpandoc\fR. If no \fIinput-file\fR
16−that may be used. Options specified in this way will override
21+is specified, these options must be preceded by ` \fB\-\-\fR '.
17−PANDOC_OPTS (see below). Example:
22+(In other cases, ` \fB\-\-\fR ' is optional.) See \fBpandoc\fR(1)
23+for a list of options that may be used. Example:
18.IP
24.IP
19−latex2markdown input.txt -- -R
25+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.
24.SH "SEE ALSO"
26.SH "SEE ALSO"
25\fBpandoc\fR(1),
27\fBpandoc\fR(1),
26\fBmarkdown2html\fR(1),
28\fBmarkdown2html\fR(1),
@@ -28,4 +30,4 @@ for a list of options that may be used.
28\fBmarkdown2latex\fR(1),
30\fBmarkdown2latex\fR(1),
29\fBmarkdown2pdf\fR(1)
31\fBmarkdown2pdf\fR(1)
30.SH AUTHOR
32.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"
2.SH NAME
2.SH NAME
3−markdown2html \- converts markdown-formatted text to HTML
3+markdown2html \- converts markdown\-formatted text to HTML
4.SH SYNOPSIS
4.SH SYNOPSIS
5−\fBmarkdown2html\fR [ \fIinput-files\fR ]
5+\fBmarkdown2html\fR [\fIoptions\fR] [\fIinput\-file\fR]...
6+[\fB\-\-\fR] [\fIpandoc\-opts\fR]
6.SH DESCRIPTION
7.SH DESCRIPTION
7−\fBmarkdown2html\fR converts \fIinput-files\fR
8+\fBmarkdown2html\fR converts \fIinput\-file\fR
8−(or text from STDIN) from markdown-formatted plain text to HTML.
9+(or text from STDIN) from markdown\-formatted plain text to HTML.
9If multiple files are specified, they will be combined to make a single
10If multiple files are specified, they will be combined to make a single
10−HTML document.
11+HTML document. Output is sent to STDOUT.
11.PP
12.PP
12\fBmarkdown2html\fR is a wrapper for \fBpandoc\fR.
13\fBmarkdown2html\fR is a wrapper for \fBpandoc\fR.
13.SH OPTIONS
14.SH OPTIONS
14.TP
15.TP
15−.B \-\-
16+.B \-h
17+Show usage message.
18+.TP
19+.I pandoc\-opts
16−Any options appearing after ` \-\- ' on the command line will be passed
20+Any options appearing after \fIinput\-file\fR... on the command line
17−directly to \fBpandoc\fR. See \fBpandoc\fR(1) for a list of options
21+will be passed directly to \fBpandoc\fR. If no \fIinput-file\fR
18−that may be used. Options specified in this way will override
22+is specified, these options must be preceded by ` \fB\-\-\fR '.
19−PANDOC_OPTS (see below). Example:
23+(In other cases, ` \fB\-\-\fR ' is optional.) See \fBpandoc\fR(1)
24+for a list of options that may be used. Example:
20.IP
25.IP
21−markdown2html input.txt -- --css=main.css -S
26+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.SH "SEE ALSO"
27.SH "SEE ALSO"
27\fBpandoc\fR(1),
28\fBpandoc\fR(1),
28\fBhtml2markdown\fR(1),
29\fBhtml2markdown\fR(1),
@@ -30,4 +31,4 @@ for a list of options that may be used.
30\fBlatex2markdown\fR(1),
31\fBlatex2markdown\fR(1),
31\fBmarkdown2pdf\fR(1)
32\fBmarkdown2pdf\fR(1)
32.SH AUTHOR
33.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"
2.SH NAME
2.SH NAME
3markdown2latex \- converts markdown-formatted text to LaTeX
3markdown2latex \- converts markdown-formatted text to LaTeX
4.SH SYNOPSIS
4.SH SYNOPSIS
5−\fBmarkdown2latex\fR [ \fIinput-files\fR ]
5+\fBmarkdown2latex\fR [\fIoptions\fR] [\fIinput\-file\fR]...
6+[\fB\-\-\fR] [\fIpandoc\-opts\fR]
6.SH DESCRIPTION
7.SH DESCRIPTION
7−\fBmarkdown2latex\fR converts \fIinput-files\fR (or text from STDIN)
8+\fBmarkdown2latex\fR converts \fIinput\-file\fR (or text from STDIN)
8−from markdown-formatted plain text to LaTeX. If multiple files are
9+from markdown\-formatted plain text to LaTeX. If multiple files are
9specified, they will be combined to make a single LaTeX document.
10specified, they will be combined to make a single LaTeX document.
11+Output is sent to STDOUT.
10.PP
12.PP
11\fBmarkdown2latex\fR is a wrapper for \fBpandoc\fR.
13\fBmarkdown2latex\fR is a wrapper for \fBpandoc\fR.
12.SH OPTIONS
14.SH OPTIONS
13.TP
15.TP
14−.B \-\-
16+.B \-h
17+Show usage message.
18+.TP
19+.I pandoc\-opts
15−Any options appearing after ` \-\- ' on the command line will be passed
20+Any options appearing after \fIinput\-file\fR... on the command line
16−directly to \fBpandoc\fR. See \fBpandoc\fR(1) for a list of options
21+will be passed directly to \fBpandoc\fR. If no \fIinput-file\fR
17−that may be used. Options specified in this way will override
22+is specified, these options must be preceded by ` \fB\-\-\fR '.
18−PANDOC_OPTS (see below). Example:
23+(In other cases, ` \fB\-\-\fR ' is optional.) See \fBpandoc\fR(1)
24+for a list of options that may be used. Example:
19.IP
25.IP
20−markdown2latex input.txt -- --custom-header=letterhead.tex
26+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.
25.SH "SEE ALSO"
27.SH "SEE ALSO"
26\fBpandoc\fR(1),
28\fBpandoc\fR(1),
27\fBmarkdown2html\fR(1),
29\fBmarkdown2html\fR(1),
@@ -29,4 +31,4 @@ for a list of options that may be used.
29\fBlatex2markdown\fR(1),
31\fBlatex2markdown\fR(1),
30\fBmarkdown2pdf\fR(1)
32\fBmarkdown2pdf\fR(1)
31.SH AUTHOR
33.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"
2.SH NAME
2.SH NAME
3markdown2pdf \- converts markdown-formatted text to PDF, using pdflatex
3markdown2pdf \- converts markdown-formatted text to PDF, using pdflatex
4.SH SYNOPSIS
4.SH SYNOPSIS
5−\fBmarkdown2pdf\fR [ \fB-o|--output\fR \fIoutput-file\fR ]
5+\fBmarkdown2pdf\fR [\fIoptions\fR] [\fB\-o\fR \fIoutput-file\fR]
6−[ \fIinput-file\fR ]
6+[\fIinput-file\fR]... [\fB\-\-\fR] [\fIpandoc\-opts\fR]
7.SH DESCRIPTION
7.SH DESCRIPTION
8−\fBmarkdown2pdf\fR converts \fIinput-file\fR (or text from STDIN) from
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
9+markdown\-formatted plain text to PDF, using \fBpdflatex\fR. If no output
10filename is specified, the name of the output file is derived from the
10filename is specified, the name of the output file is derived from the
11input file; thus, for example, if the input file is \fIhello.txt\fR,
11input file; thus, for example, if the input file is \fIhello.txt\fR,
12the output file will be \fIhello.pdf\fR. If the input is read from STDIN
12the output file will be \fIhello.pdf\fR. If the input is read from STDIN
13and no output filename is specified, the output file will be named
13and 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.
15.PP
17.PP
16\fBmarkdown2pdf\fR is a wrapper for \fBpandoc\fR.
18\fBmarkdown2pdf\fR is a wrapper for \fBpandoc\fR.
17.SH OPTIONS
19.SH OPTIONS
18.TP
20.TP
19−.B \-o FILENAME, \-\-output=FILENAME
21+.B \-h
20−Specify name of output (PDF) file.
21−.TP
22−.B \-h, \-\-help
23Show usage message.
22Show usage message.
24.TP
23.TP
25−.B \-\-
24+.B \-o \fIoutput-file\fR
25+Specify name of output (PDF) file.
26+.TP
27+.I pandoc\-opts
26−Any options appearing after ` \-\- ' on the command line will be passed
28+Any options appearing after \fIinput\-file\fR... on the command line
27−directly to \fBpandoc\fR. See \fBpandoc\fR(1) for a list of options
29+will be passed directly to \fBpandoc\fR. If no \fIinput-file\fR
28−that may be used. Options specified in this way will override
30+is specified, these options must be preceded by ` \fB\-\-\fR '.
29−PANDOC_OPTS (see below). Example:
31+(In other cases, ` \fB\-\-\fR ' is optional.) See \fBpandoc\fR(1)
32+for a list of options that may be used. Example:
30.IP
33.IP
31−markdown2pdf input.txt -- --custom-header=letterhead.tex
34+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.
36.SH "SEE ALSO"
35.SH "SEE ALSO"
37\fBpandoc\fR(1),
36\fBpandoc\fR(1),
38\fBmarkdown2html\fR(1),
37\fBmarkdown2html\fR(1),
@@ -41,4 +40,4 @@ for a list of options that may be used.
41\fBlatex2markdown\fR(1),
40\fBlatex2markdown\fR(1),
42\fBpdflatex\fR(1)
41\fBpdflatex\fR(1)
43.SH AUTHOR
42.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"
2.SH NAME
2.SH NAME
3pandoc \- general markup converter
3pandoc \- general markup converter
4.SH SYNOPSIS
4.SH SYNOPSIS
5−\fBpandoc\fR [ \fIoptions\fR ] [ \fIinput-files\fR ]
5+\fBpandoc\fR [\fIoptions\fR] [\fIinput\-file\fR]...
6−
7.SH DESCRIPTION
6.SH DESCRIPTION
8\fIPandoc\fR converts files from one markup format to another. It can
7\fIPandoc\fR converts files from one markup format to another. It can
9read markdown and (subsets of) reStructuredText, HTML, and LaTeX, and
8read markdown and (subsets of) reStructuredText, HTML, and LaTeX, and
10it can write markdown, reStructuredText, HTML, LaTeX, RTF, and S5 HTML
9it can write markdown, reStructuredText, HTML, LaTeX, RTF, and S5 HTML
11slide shows.
10slide shows.
12.PP
11.PP
13−If no \fIinput-files\fR are specified, input is read from STDIN. Otherwise,
12+If no \fIinput\-file\fR is specified, input is read from STDIN. Otherwise,
14−the \fIinput-files\fR are concatenated (with a blank line between each)
13+the \fIinput\-files\fR are concatenated (with a blank line between each)
15and used as input. Output goes to STDOUT. If you want output to a file,
14and used as input. Output goes to STDOUT. If you want output to a file,
16use shell redirection:
15use shell redirection:
17.IP
16.IP
18.B pandoc input.txt > output.html
17.B pandoc input.txt > output.html
19.PP
18.PP
20The default behavior of \fIPandoc\fR is to convert the input from
19The default behavior of \fIPandoc\fR is to convert the input from
21−markdown-formatted plain text to HTML. Different input and output
20+markdown\-formatted plain text to HTML. Different input and output
22−formats can be specified using command-line options. For example,
21+formats can be specified using command\-line options. For example,
23.IP
22.IP
24−.B pandoc -f latex -t markdown chap1.tex > chap1.txt
23+.B pandoc \-f latex \-t markdown chap1.tex > chap1.txt
25.PP
24.PP
26−converts \fIchap1.tex\fR from LaTeX to markdown-formatted plain text.
25+converts \fIchap1.tex\fR from LaTeX to markdown\-formatted plain text.
27−See below for a detailed list of command-line options.
26+See below for a detailed list of command\-line options.
28.PP
27.PP
29−\fIPandoc\fR uses the UTF-8 character encoding for both input and output.
28+\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
29+If your local character encoding is not UTF\-8, you should pipe input
31and output through \fBiconv\fR:
30and output through \fBiconv\fR:
32.IP
31.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
34
33
35.SH OPTIONS
34.SH OPTIONS
36.TP
35.TP
@@ -40,7 +39,7 @@ Print version.
40.B \-h, \-\-help
39.B \-h, \-\-help
41Show usage message.
40Show usage message.
42.TP
41.TP
43−.B \-f FORMAT, \-r FORMAT, --from=FORMAT, --read=FORMAT
42+.B \-f FORMAT, \-r FORMAT, \-\-from=FORMAT, \-\-read=FORMAT
44Specify input format.
43Specify input format.
45.I FORMAT
44.I FORMAT
46can be
45can be
@@ -56,7 +55,7 @@ or
56.I latex
55.I latex
57(LaTeX).
56(LaTeX).
58.TP
57.TP
59−.B \-t FORMAT, \-w FORMAT, --to=FORMAT, --write=FORMAT
58+.B \-t FORMAT, \-w FORMAT, \-\-to=FORMAT, \-\-write=FORMAT
60Specify output format.
59Specify output format.
61.I FORMAT
60.I FORMAT
62can be
61can 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