git.iko.soy/typeable/pandoc
on master help sign in
Merged changes from branches/wrappers since r177.

Summary of main changes: + Added -o/--output and -d/--debug options to pandoc. + Modified pandoc to behave differently depending on the name of the program. For example, if the program name is 'html2latex', the default reader will be html and the default writer latex. + Removed most of the old wrappers, replacing them with symlinks to pandoc. + Rewrote markdown2pdf and created a new wrapper web2markdown, with the functionality of the old html2markdown script. These new scripts exploit pandoc's -d option to avoid having to do complex command-line parsing. + Revised man pages and documentation appropriately. git-svn-id: https://pandoc.googlecode.com/svn/trunk@279 788f1e2b-df1e-0410-8736-df70ead52e1b

commitd829c4820adbe7a7634f1c1d825d0d206512e6e7 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateFri 22 Dec 2006, 20:16 (20 years ago) parentcfaf0c1
27 files changed+710−796
Makefile+14−10 README+154−97 debian/changelog+2 man/man1/html2markdown.1+1−60 man/man1/latex2markdown.1+1−33 man/man1/markdown2html.1+1−34 man/man1/markdown2latex.1+1−34 man/man1/markdown2pdf.1+57−29 man/man1/markdown2rst.1+1 man/man1/markdown2rtf.1+1 man/man1/markdown2s5.1+1 man/man1/pandoc.1+75−51 man/man1/rst2markdown.1+1 man/man1/web2markdown.1+82 src/Main.hs+116−26 src/wrappers/checkin.sh−7 src/wrappers/common.sh−27 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+29−39 src/wrappers/postopts.sh−17 src/wrappers/singlearg.sh−7 src/wrappers/testwrapper.in−141 src/wrappers/web2markdown.in+173
Makefile+14−10
@@ -23,15 +23,16 @@ EXECSBASE := $(shell sed -ne 's/^[Ee]xecutable:[[:space:]]*//p' $(CABAL).in)
2323#-------------------------------------------------------------------------------
2424# Install targets
2525#-------------------------------------------------------------------------------
26+WRAPPERS := web2markdown markdown2pdf
27+SYMLINKS := markdown2html markdown2latex markdown2s5 markdown2rst \
28+ markdown2rtf html2markdown latex2markdown rst2markdown
29+PROGS := $(EXECS) $(WRAPPERS)
2630# Add .exe extensions if we're running Windows/Cygwin.
2731EXTENSION := $(shell uname | tr '[:upper:]' '[:lower:]' | \
2832 sed -ne 's/^cygwin.*$$/\.exe/p')
2933EXECS := $(addsuffix $(EXTENSION),$(EXECSBASE))
3034# First entry in Cabal's executable stanza is the main executable.
3135MAIN := $(firstword $(EXECS))
32−WRAPPERS := html2markdown latex2markdown markdown2html \
33− markdown2latex markdown2pdf
34−PROGS := $(EXECS) $(WRAPPERS)
3536DOCS := README.html README BUGS
3637
3738#-------------------------------------------------------------------------------
@@ -92,6 +93,12 @@ all: build-program
9293templates: $(SRCDIR)/templates
9394 $(MAKE) -C $(SRCDIR)/templates
9495
96+.PHONY: symlinks
97+cleanup_files+=$(SYMLINKS)
98+symlinks: $(SYMLINKS)
99+$(SYMLINKS): $(MAIN)
100+ ln -sf ./$(MAIN) $@
101+
95102define generate-shell-script
96103echo "Generating $@..."; \
97104awk ' \
@@ -131,7 +138,7 @@ build: configure
131138 $(BUILDCMD) build
132139
133140.PHONY: build-exec
134−build-exec: $(PROGS)
141+build-exec: $(PROGS) $(SYMLINKS)
135142cleanup_files+=$(EXECS)
136143$(EXECS): build
137144 for f in $@; do \
@@ -191,8 +198,9 @@ install-exec: build-exec
191198 fi; \
192199 $(INSTALL_PROGRAM) $$f $(BINPATH)/; \
193200 done
201+ cd $(BINPATH); for f in $(SYMLINKS); do ln -sf $(MAIN) $$f; done
194202uninstall-exec:
195− -for f in $(notdir $(PROGS)); do rm -f $(BINPATH)/$$f; done
203+ -for f in $(notdir $(PROGS) $(SYMLINKS)); do rm -f $(BINPATH)/$$f; done ;
196204
197205# Program + user documents installation.
198206.PHONY: install-program uninstall-program
@@ -277,15 +285,11 @@ osx-dmg: ../$(osx_dmg_name)
277285 -rm -f $(osx_dmg_name)
278286 mv $(osx_udzo_name) ../$(osx_dmg_name)
279287
280−.PHONY: test test-markdown test-wrapper
288+.PHONY: test test-markdown
281289test: $(MAIN)
282290 @cd $(TESTDIR) && perl runtests.pl -s $(PWD)/$(MAIN)
283291test-markdown: $(MAIN)
284292 @cd $(TESTDIR)/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(MAIN) -tidy
285−cleanup_files+=testwrapper
286−test-wrappers: testwrapper
287− @echo "Running $<..."
288− @sh testwrapper
289293
290294# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
291295src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
README+154−97
@@ -20,7 +20,7 @@ or output format requires only adding a reader or writer.
2020[reStructuredText]: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
2121[S5]: http://meyerweb.com/eric/tools/s5/
2222[HTML]: http://www.w3.org/TR/html40/
23−[LaTeX]: http://www.latex-project.org/
23+[LaTeX]: http://www.latex-project.org/
2424[RTF]: http://en.wikipedia.org/wiki/Rich_Text_Format
2525[Haskell]: http://www.haskell.org/
2626
@@ -30,9 +30,53 @@ any kind. (See COPYRIGHT for full copyright and warranty notices.)
3030Recai Oktaş (roktas at debian dot org) deserves credit for the build
3131system, the debian package, and the robust wrapper scripts.
3232
33−[GPL]: http://www.gnu.org/copyleft/gpl.html
33+[GPL]: http://www.gnu.org/copyleft/gpl.html "GNU General Public License"
3434
35−# Using Pandoc
35+Requirements
36+============
37+
38+The `pandoc` program itself does not depend on any external libraries
39+or programs. The convenience programs `markdown2html`, `markdown2latex`,
40+`markdown2rst`, `markdown2rtf`, `markdown2s5`, `html2markdown`,
41+`latex2markdown`, and `rst2markdown` are implemented as symbolic links to
42+`pandoc`.
43+
44+The wrapper script `web2markdown` requires
45+
46+ - `html2markdown` (included with Pandoc)
47+ - a POSIX-compliant shell (installed by default on all linux and unix
48+ systems, including Mac OS X, and in [Cygwin] for Windows),
49+ - `HTML Tidy`
50+ - `iconv` (for character encoding conversion). (If `iconv` is absent,
51+ `web2markdown` will still work, but it will treat everything as UTF-8.)
52+
53+[Cygwin]: http://www.cygwin.com/
54+[HTML Tidy]: http://tidy.sourceforge.net/
55+[`iconv`]: http://www.gnu.org/software/libiconv/
56+
57+The wrapper script `markdown2pdf` requires
58+
59+ - `markdown2latex` (included with Pandoc)
60+ - a POSIX-compliant shell
61+ - `pdflatex`, which should be part of any [LaTeX] distribution
62+ - the [unicode] and [fancyvrb] LaTeX packages, which are included
63+ in many LaTeX distributions. The [unicode] package allows LaTeX to
64+ process UTF-8 characters. [fancyvrb] allows code blocks and verbatim
65+ text to be used within footnotes. If your installation of LaTeX
66+ does not include these packages, you will get an error (complaining
67+ about missing `ucs.sty` or `fancyvrb.sty`) when you try to compile
68+ a LaTeX file produced by Pandoc, or when you use the `markdown2pdf`
69+ script (described below). If this happens, install the [unicode] and
70+ [fancyvrb] packages package from [CTAN]. (Get the zip file from CTAN
71+ and unpack it into `~/texmf/tex/latex/`. You may also need to run
72+ `mktexlsr` or `texhash` before the files can be found by TeX.)
73+
74+[CTAN]: http://www.ctan.org "Comprehensive TeX Archive Network"
75+[unicode]: http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/
76+[fancyvrb]: http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/
77+
78+Using Pandoc
79+============
3680
3781If you run `pandoc` without arguments, it will accept input from
3882STDIN. If you run it with file names as arguments, it will take input
@@ -66,10 +110,14 @@ a subset of reStructuredText syntax. For example, it doesn't handle
66110tables, definition lists, option lists, or footnotes. It handles only the
67111constructs expressible in unextended markdown. But for simple documents
68112it should be adequate. The `latex` and `html` readers are also limited
69−in what they can do.
113+in what they can do. Because the `html` reader is picky about the HTML
114+it parses, it is recommended that you pipe HTML through [HTML Tidy] before
115+sending it to `pandoc`, or use the `web2markdown` script described below.
116+
117+By default, `pandoc` writes its output to STDOUT. If you want to
118+write to a file, use the `-o` option or shell redirection:
70119
71−`pandoc` writes its output to STDOUT. If you want to write to a file,
72−use redirection:
120+ pandoc -o hello.html hello.txt
73121
74122 pandoc hello.txt > hello.html
75123
@@ -77,13 +125,14 @@ Note that you can specify multiple input files on the command line.
77125`pandoc` will concatenate them all (with blank lines between them)
78126before parsing:
79127
80− pandoc -s chapter1.txt chapter2.txt chapter3.txt references.txt > book.html
128+ pandoc -s chapter1.txt chapter2.txt references.txt > book.html
81129
82130(The `-s` option here tells `pandoc` to produce a standalone HTML file,
83131with a proper header, rather than a fragment. For more details on this
84132and many other command-line options, see below.)
85133
86−# Character encodings
134+Character encodings
135+-------------------
87136
88137Unfortunately, due to limitations in GHC, `pandoc` does not automatically
89138detect the system's local character encoding. Hence, all input and
@@ -97,92 +146,65 @@ will convert `source.txt` from the local encoding to UTF-8, then
97146convert it to HTML, then convert back to the local encoding,
98147putting the output in `output.html`.
99148
100−[`iconv`]: http://www.gnu.org/software/libiconv/
101−
102149The shell scripts (described below) automatically convert the input
103150from the local encoding to UTF-8 before running them through `pandoc`,
104151then convert the output back to the local encoding.
105152
106−## LaTeX and UTF-8
107−
108−LaTeX sources produced by Pandoc use `ucs.sty`, which is included in many
109−LaTeX distributions. This allows LaTeX to process UTF-8 characters.
110−If your installation of LaTeX does not include `ucs.sty`, you will get an
111−error when you try to compile a LaTeX file produced by Pandoc, or when
112−you use the `markdown2pdf` script (described below). If this happens,
113−install the [unicode] package from [CTAN]. (Get the `unicode.zip`
114−file from CTAN, unpack it, and copy the whole `unicode` directory into
115−`~/texmf/tex/latex/`. You may also need to run `mktexlsr` or `texhash`
116−before the files can be found by TeX.)
153+Convenience programs and wrapper scripts
154+========================================
117155
118−[CTAN]: http://www.ctan.org
119−[unicode]: http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/
156+For convenience, eight variant programs are included with Pandoc:
157+`markdown2html` (which is equivalent to `pandoc -w html`),
158+`markdown2latex` (equivalent to `pandoc -w latex`), `markdown2rst`
159+(equivalent to `pandoc -w rst`), `markdown2rtf` (equivalent to
160+`pandoc -w rtf`), `markdown2s5` (equivalent to `pandoc -w s5`),
161+`html2markdown` (equivalent to `pandoc -r html -w markdown`),
162+`latex2markdown` (equivalent to `pandoc -r latex -w markdown`), and
163+`rst2markdown` (equivalent to `pandoc -r rst -w markdown`). These
164+programs take an appropriately restricted subset of `pandoc`'s
165+options. (Run them with the `-h` flag for a full list of allowed
166+options.)
120167
121−# The shell scripts
168+Like `pandoc`, all of these programs produce fragments by default.
169+If you want to produce a standalone file, complete with a header
170+and footer appropriate to the format, use the `-s` option:
122171
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:
172+ markdown2latex -s sample.txt > sample.tex
126173
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
174+Two shell scripts have also been included:
133175
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`.)
176+1. `markdown2pdf` produces a PDF file from markdown-formatted
177+ text, using `markdown2latex` and `pdflatex`. The default
178+ behavior of `markdown2pdf` is to create a file with the same
179+ base name as the first argument and the extension `pdf`; thus,
180+ for example,
139181
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.)
182+ markdown2pdf sample.txt endnotes.txt
148183
149−With the exception of `markdown2pdf`, the scripts write to standard output.
150−Output can be sent to a file using shell output redirection:
184+ will produce `sample.pdf`. (If `sample.pdf` exists already,
185+ it will be backed up before being overwritten.) An output file
186+ name can be specified explicitly using the `-o` option:
151187
152− latex2markdown sample.tex > sample.txt
188+ markdown2pdf -o "My Book.pdf" chap1.txt chap2.txt chap3.txt
153189
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,
190+ If no input file is specified, input will be taken from STDIN.
156191
157− markdown2pdf sample.txt endnotes.txt
192+2. `web2markdown` grabs a web page from a file or URL and converts
193+ it to markdown-formatted text, using `tidy` and `html2markdown`.
194+ Unless input is from STDIN, an attempt is made to determine the
195+ character encoding of the page from the "Content-type" meta tag.
196+ If this is not present, UTF-8 is assumed. Alternatively, a character
197+ encoding may be specified explicitly using the `-e` option.
158198
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:
199+ `web2markdown` searches for an available program (`wget`, `curl`,
200+ or a text-mode browser) to fetch the contents of a URL.
201+ Optionally, the `-g` command may be used to specify the command
202+ to be used:
162203
163− markdown2pdf -o "My Book.pdf" chap1.txt chap2.txt chap3.txt
204+ web2markdown -g 'wget --user=foo --password=bar' mysite.com
164205
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,
169−
170− markdown2html tusks.txt -S -T Elephants
171−
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 ` -- `:
177−
178− cat tusks.txt | markdown2html -- -S -T Elephants
179−
180−The ` -- ` separator may optionally be used when there are command-line
181−arguments:
182−
183− markdown2html -- tusks.txt -S -T Elephants
184−
185−# Command-line options
206+Command-line options
207+====================
186208
187209Various command-line options can be used to customize the output.
188210For a complete list, type
@@ -207,9 +229,11 @@ specified.)
207229complete with appropriate document headers. By default, `pandoc`
208230produces a fragment.
209231
210−`--custom-header` can be used to specify a custom document header. To
211−see the headers used by default, use the `-D` option: for example,
212−`pandoc -D html` prints the default HTML header.
232+`-o` or `--output-file` can be used to specify an output file.
233+
234+`-C` or `--custom-header` can be used to specify a custom document
235+header. To see the headers used by default, use the `-D` option:
236+for example, `pandoc -D html` prints the default HTML header.
213237
214238`-c` or `--css` allows the user to specify a custom stylesheet that
215239will be linked to in HTML and S5 output.
@@ -253,15 +277,38 @@ is for lists to be displayed all at once.
253277`-N` or `--number-sections` causes sections to be numbered in LaTeX
254278output. By default, sections are not numbered.
255279
256−# Pandoc's markdown vs. standard markdown
280+`-d` or `--debug` causes a debugging message to be written to STDERR.
281+The format of the message is as follows:
282+
283+ OUTPUT=foo
284+ INPUT=bar
285+ INPUT=Foo Baz
286+
287+Here `OUTPUT=` is followed by the name of the output file specified
288+using `-o`, if any. If no output file was specified, `OUTPUT=`
289+will appear with nothing following it. Lines beginning `INPUT=`
290+specify input files. If there are no input files, no `INPUT=` lines
291+will be printed. The `-d` option forces output to be written to
292+STDOUT, even if an output file was specified using the `-o` option.
293+(This option is provided to make it easier to write wrappers for
294+`pandoc`.)
295+
296+`-v` or `--version` prints the version number to STDERR.
297+
298+`-h` or `--help` prints a usage message to STDERR.
299+
300+Pandoc's markdown vs. standard markdown
301+=======================================
257302
258303In parsing markdown, Pandoc departs from and extends [standard markdown]
259304in a few respects. (To run Pandoc on the official
260305markdown test suite, type `make test-markdown`.)
261306
262307[standard markdown]: http://daringfireball.net/projects/markdown/syntax
308+ "Markdown syntax description"
263309
264−## Section Headings
310+Section Headings
311+----------------
265312
266313Pandoc creates an invisible anchor in front of every HTML section
267314heading. The ID of this anchor is derived from the section heading
@@ -281,7 +328,8 @@ example, just insert:
281328
282329 [Back to Aristotle](#Aristotle's_De_Anima)
283330
284−## Lists
331+Lists
332+-----
285333
286334Pandoc behaves differently from standard markdown on some "edge
287335cases" involving lists. Consider this source:
@@ -332,7 +380,8 @@ the example above:
332380 B) Fie
333381 C) Third
334382
335−## Literal quotes in titles
383+Literal quotes in titles
384+------------------------
336385
337386Standard markdown allows unescaped literal quotes in titles, as
338387in
@@ -343,7 +392,8 @@ Pandoc requires all quotes within titles to be escaped:
343392
344393 [foo]: "bar \"embedded\" baz"
345394
346−## Reference links
395+Reference links
396+---------------
347397
348398Pandoc allows implicit reference links in either of two styles:
349399
@@ -357,7 +407,8 @@ will appear as regular bracketed text. Note: even `[link][]` will
357407appear as `[link]` if there's no reference for `link`. If you want
358408`[link][]`, use a backslash escape: `\[link]\[]`.
359409
360−## Footnotes
410+Footnotes
411+---------
361412
362413Pandoc's markdown allows footnotes, using the following syntax:
363414
@@ -394,7 +445,8 @@ they cannot contain multiple paragraphs). The syntax is as follows:
394445
395446Inline and regular footnotes may be mixed freely.
396447
397−## Embedded HTML
448+Embedded HTML
449+-------------
398450
399451Pandoc treats embedded HTML in markdown a bit differently than
400452Markdown 1.0. While Markdown 1.0 leaves HTML blocks exactly as they
@@ -427,7 +479,8 @@ markdown with HTML block elements. For example, one can surround
427479a block of markdown text with `<div>` tags without preventing it
428480from being interpreted as markdown.
429481
430−## Title blocks
482+Title blocks
483+------------
431484
432485If the file begins with a title block
433486
@@ -460,7 +513,8 @@ If a title prefix is specified with `-T` and no title block appears
460513in the document, the title prefix will be used by itself as the
461514HTML title.
462515
463−## Box-style blockquotes
516+Box-style blockquotes
517+---------------------
464518
465519Pandoc supports emacs-style boxquote block quotes, in addition to
466520standard markdown (email-style) boxquotes:
@@ -469,7 +523,8 @@ standard markdown (email-style) boxquotes:
469523 | They look like this.
470524 `----
471525
472−## Inline LaTeX
526+Inline LaTeX
527+------------
473528
474529Anything between two $ characters will be parsed as LaTeX math. The
475530opening $ must have a character immediately to its right, while the
@@ -501,7 +556,8 @@ You can also use LaTeX environments. For example,
501556Note, however, that material between the begin and end tags will
502557be interpreted as raw LaTeX, not as markdown.
503558
504−## Custom headers
559+Custom headers
560+--------------
505561
506562When run with the "standalone" option (`-s`), `pandoc` creates a
507563standalone file, complete with an appropriate header. To see the
@@ -516,13 +572,14 @@ it and specify it on the command line as follows:
516572
517573 pandoc --header=MyHeaderFile
518574
519−# Producing S5 with Pandoc
575+Producing S5 with Pandoc
576+========================
520577
521−Producing an [S5] slide show with Pandoc is easy. A title page is
522−constructed automatically from the document's title block (see above).
523−Each section (with a level-one header) produces a single slide. (Note
524−that if the section is too big, the slide will not fit on the page; S5
525−is not smart enough to produce multiple pages.)
578+Producing an [S5] web-based slide show with Pandoc is easy. A title
579+page is constructed automatically from the document's title block (see
580+above). Each section (with a level-one header) produces a single slide.
581+(Note that if the section is too big, the slide will not fit on the page;
582+S5 is not smart enough to produce multiple pages.)
526583
527584Here's the markdown source for a simple slide show, `eating.txt`:
528585
debian/changelog+2
@@ -14,6 +14,8 @@ pandoc (0.22) unstable; urgency=low
1414
1515 * Refactored template processing (fillTemplates.pl).
1616
17+ * Modified wrapper scripts to make them more robust.
18+
1719 * Modified wrapper scripts to make them more robust and portable.
1820 To avoid code duplication and ensure consistency, wrappers are
1921 generated via a templating system from templates in src/wrappers.
man/man1/html2markdown.1+1−60
@@ -1,60 +1 @@
1−.TH HTML2MARKDOWN 1 "November 21, 2006" Pandoc "User Manuals"
2−.SH NAME
3−html2markdown \- converts HTML to markdown-formatted text
4−.SH SYNOPSIS
5−\fBhtml2markdown\fR [\fIoptions\fR] [\fIinput\-file\fR or \fIURL\fR]
6−[\fB\-\-\fR] [\fIpandoc\-opts\fR]
7−.SH DESCRIPTION
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.
13−.PP
14−\fBhtml2markdown\fR is a wrapper for \fBpandoc\fR.
15−.SH OPTIONS
16−.TP
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:
50−.IP
51−html2markdown input.txt \-\- \-R
52−.SH "SEE ALSO"
53−\fBpandoc\fR(1),
54−\fBmarkdown2html\fR(1),
55−\fBmarkdown2latex\fR(1),
56−\fBlatex2markdown\fR(1),
57−\fBmarkdown2pdf\fR(1),
58−\fBiconv\fR(1)
59−.SH AUTHOR
60−John MacFarlane and Recai Oktas
1+.so man1/pandoc.1
man/man1/latex2markdown.1+1−33
@@ -1,33 +1 @@
1−.TH LATEX2MARKDOWN 1 "November 21, 2006" Pandoc "User Manuals"
2−.SH NAME
3−latex2markdown \- converts LaTeX to markdown\-formatted text
4−.SH SYNOPSIS
5−\fBlatex2markdown\fR [\fIoptions\fR] [\fIinput\-file\fR]
6−[\fB\-\-\fR] [\fIpandoc\-opts\fR]
7−.SH DESCRIPTION
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.
11−.PP
12−\fBlatex2markdown\fR is a wrapper for \fBpandoc\fR.
13−.SH OPTIONS
14−.TP
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:
24−.IP
25−latex2markdown input.txt \-\- \-R
26−.SH "SEE ALSO"
27−\fBpandoc\fR(1),
28−\fBmarkdown2html\fR(1),
29−\fBhtml2markdown\fR(1),
30−\fBmarkdown2latex\fR(1),
31−\fBmarkdown2pdf\fR(1)
32−.SH AUTHOR
33−John MacFarlane and Recai Oktas
1+.so man1/pandoc.1
man/man1/markdown2html.1+1−34
@@ -1,34 +1 @@
1−.TH MARKDOWN2HTML 1 "November 21, 2006" Pandoc "User Manuals"
2−.SH NAME
3−markdown2html \- converts markdown\-formatted text to HTML
4−.SH SYNOPSIS
5−\fBmarkdown2html\fR [\fIoptions\fR] [\fIinput\-file\fR]...
6−[\fB\-\-\fR] [\fIpandoc\-opts\fR]
7−.SH DESCRIPTION
8−\fBmarkdown2html\fR converts \fIinput\-file\fR
9−(or text from STDIN) from markdown\-formatted plain text to HTML.
10−If multiple files are specified, they will be combined to make a single
11−HTML document. Output is sent to STDOUT.
12−.PP
13−\fBmarkdown2html\fR is a wrapper for \fBpandoc\fR.
14−.SH OPTIONS
15−.TP
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:
25−.IP
26−markdown2html input.txt \-\- \-\-css=main.css \-S
27−.SH "SEE ALSO"
28−\fBpandoc\fR(1),
29−\fBhtml2markdown\fR(1),
30−\fBmarkdown2latex\fR(1),
31−\fBlatex2markdown\fR(1),
32−\fBmarkdown2pdf\fR(1)
33−.SH AUTHOR
34−John MacFarlane and Recai Oktas
1+.so man1/pandoc.1
man/man1/markdown2latex.1+1−34
@@ -1,34 +1 @@
1−.TH MARKDOWN2LATEX 1 "November 21, 2006" Pandoc "User Manuals"
2−.SH NAME
3−markdown2latex \- converts markdown-formatted text to LaTeX
4−.SH SYNOPSIS
5−\fBmarkdown2latex\fR [\fIoptions\fR] [\fIinput\-file\fR]...
6−[\fB\-\-\fR] [\fIpandoc\-opts\fR]
7−.SH DESCRIPTION
8−\fBmarkdown2latex\fR converts \fIinput\-file\fR (or text from STDIN)
9−from markdown\-formatted plain text to LaTeX. If multiple files are
10−specified, they will be combined to make a single LaTeX document.
11−Output is sent to STDOUT.
12−.PP
13−\fBmarkdown2latex\fR is a wrapper for \fBpandoc\fR.
14−.SH OPTIONS
15−.TP
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:
25−.IP
26−markdown2latex input.txt \-\- \-\-custom\-header=letterhead.tex
27−.SH "SEE ALSO"
28−\fBpandoc\fR(1),
29−\fBmarkdown2html\fR(1),
30−\fBhtml2markdown\fR(1),
31−\fBlatex2markdown\fR(1),
32−\fBmarkdown2pdf\fR(1)
33−.SH AUTHOR
34−John MacFarlane and Recai Oktas
1+.so man1/pandoc.1
man/man1/markdown2pdf.1+57−29
@@ -1,43 +1,71 @@
1−.TH MARKDOWN2PDF 1 "November 21, 2006" Pandoc "User Manuals"
1+.TH MARKDOWN2PDF 1 "December 15, 2006" Pandoc "User Manuals"
22.SH NAME
33markdown2pdf \- converts markdown-formatted text to PDF, using pdflatex
44.SH SYNOPSIS
5−\fBmarkdown2pdf\fR [\fIoptions\fR] [\fB\-o\fR \fIoutput-file\fR]
6−[\fIinput-file\fR]... [\fB\-\-\fR] [\fIpandoc\-opts\fR]
5+\fBmarkdown2pdf\fR [\fIoptions\fR] [\fIinput-file\fR]...
76.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
10−filename is specified, the name of the output file is derived from the
11−input file; thus, for example, if the input file is \fIhello.txt\fR,
12−the output file will be \fIhello.pdf\fR. If the input is read from STDIN
13−and no output filename is specified, the output file will be named
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.
7+\fBmarkdown2pdf\fR converts \fIinput\-file\fR (or text from standard
8+input) from markdown\-formatted plain text to PDF, using \fBpdflatex\fR.
9+If no output filename is specified, the name of the output file is
10+derived from the input file; thus, for example, if the input file
11+is \fIhello.txt\fR, the output file will be \fIhello.pdf\fR. If
12+the input is read from STDIN and no output filename is
13+specified, the output file will be named \fIstdin.pdf\fR. If
14+multiple input files are specified, they will be concatenated before
15+conversion, and the name of the output file will be derived from
16+the first input file.
1717.PP
18−\fBmarkdown2pdf\fR is a wrapper for \fBpandoc\fR.
18+Input is assumed to be in the UTF\-8 character encoding. If your
19+local character encoding is not UTF\-8, you should pipe input and
20+output through \fBiconv\fR:
21+.IP
22+.B iconv \-t utf\-8 input.txt | pandoc | iconv \-f utf\-8
23+.PP
24+\fBmarkdown2pdf\fR assumes that the 'unicode' package
25+is in latex's search path. If this package is not included in your
26+latex setup, it can be obtained from <http://ctan.org>.
27+.PP
28+\fBmarkdown2pdf\fR is a wrapper around \fBmarkdown2latex\fR.
1929.SH OPTIONS
2030.TP
21−.B \-h
22−Show usage message.
31+.B \-o FILE, \-\-output=FILE
32+Write output to \fIFILE\fR.
2333.TP
24−.B \-o \fIoutput-file\fR
25−Specify name of output (PDF) file.
34+.B \-p, \-\-preserve-tabs
35+Preserve tabs instead of converting them to spaces.
2636.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:
33−.IP
34−markdown2pdf input.txt \-\- \-\-custom\-header=letterhead.tex
37+.B \-\-tab-stop=\fITABSTOP\fB
38+Specify tab stop (default is 4).
39+.TP
40+.B \-R, \-\-parse-raw
41+Parse untranslatable LaTeX environments as raw LaTeX,
42+instead of ignoring them.
43+.TP
44+.B \-N, \-\-number-sections
45+Number section headings in LaTeX output. (Default is not to number them.)
46+.TP
47+.B \-H \fIFILE\fB, \-\-include-in-header=\fIFILE\fB
48+Include (LaTeX) contents of \fIFILE\fR at the end of the header. Implies
49+\fB\-s\fR.
50+.TP
51+.B \-B \fIFILE\fB, \-\-include-before-body=\fIFILE\fB
52+Include (LaTeX) contents of \fIFILE\fR at the beginning of the document body.
53+.TP
54+.B \-A \fIFILE\fB, \-\-include-after-body=\fIFILE\fB
55+Include (LaTeX) contents of \fIFILE\fR at the end of the document body.
56+.TP
57+.B \-C \fIFILE\fB, \-\-custom-header=\fIFILE\fB
58+Use contents of \fIFILE\fR
59+as the LaTeX document header (overriding the default header, which can be
60+printed using '\fBpandoc \-D latex\fR'). Implies \fB-s\fR.
61+.TP
62+.B \-v, \-\-version
63+Print version.
64+.TP
65+.B \-h, \-\-help
66+Show usage message.
3567.SH "SEE ALSO"
3668\fBpandoc\fR(1),
37−\fBmarkdown2html\fR(1),
38−\fBhtml2markdown\fR(1),
39−\fBmarkdown2latex\fR(1),
40−\fBlatex2markdown\fR(1),
4169\fBpdflatex\fR(1)
4270.SH AUTHOR
4371John MacFarlane and Recai Oktas
man/man1/markdown2rst.1new file+1
@@ -0,0 +1 @@
1+.so man1/pandoc.1
man/man1/markdown2rtf.1new file+1
@@ -0,0 +1 @@
1+.so man1/pandoc.1
man/man1/markdown2s5.1new file+1
@@ -0,0 +1 @@
1+.so man1/pandoc.1
man/man1/pandoc.1+75−51
@@ -1,18 +1,23 @@
1−.TH PANDOC 1 "November 21, 2006" Pandoc "User Manuals"
1+.TH PANDOC 1 "December 15, 2006" Pandoc "User Manuals"
22.SH NAME
3−pandoc \- general markup converter
3+pandoc, markdown2html, markdown2latex, markdown2rst, markdown2rtf,
4+markdown2s5, html2markdown2, latex2markdown, rst2markdown \- general
5+markup converter
46.SH SYNOPSIS
57\fBpandoc\fR [\fIoptions\fR] [\fIinput\-file\fR]...
68.SH DESCRIPTION
7−\fIPandoc\fR converts files from one markup format to another. It can
9+\fBPandoc\fR converts files from one markup format to another. It can
810read markdown and (subsets of) reStructuredText, HTML, and LaTeX, and
911it can write markdown, reStructuredText, HTML, LaTeX, RTF, and S5 HTML
1012slide shows.
1113.PP
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)
14−and used as input. Output goes to STDOUT. If you want output to a file,
15−use shell redirection:
14+If no \fIinput\-file\fR is specified, input is read from STDIN.
15+Otherwise, the \fIinput\-files\fR are concatenated (with a blank
16+line between each) and used as input. Output goes to standard
17+output. If you want output to a file, use the \fB\-o\fR option or
18+shell redirection:
19+.IP
20+.B pandoc \-o output.html input.txt
1621.IP
1722.B pandoc input.txt > output.html
1823.PP
@@ -25,6 +30,19 @@ formats can be specified using command\-line options. For example,
2530converts \fIchap1.tex\fR from LaTeX to markdown\-formatted plain text.
2631See below for a detailed list of command\-line options.
2732.PP
33+For convenience, eight variant programs are available:
34+\fBmarkdown2html\fR (same as \fBpandoc \-w html\fR),
35+\fBmarkdown2latex\fR (same as \fBpandoc \-w latex\fR),
36+\fBmarkdown2rst\fR (same as \fBpandoc \-w rst\fR),
37+\fBmarkdown2rtf\fR (same as \fBpandoc \-w rtf\fR),
38+\fBmarkdown2s5\fR (same as \fBpandoc \-w s5\fR),
39+\fBhtml2markdown\fR (same as \fBpandoc \-r html \-w markdown\fR),
40+\fBlatex2markdown\fR (same as \fBpandoc \-r latex \-w markdown\fR),
41+and \fBrst2markdown\fR (same as \fBpandoc \-r rst \-w markdown\fR).
42+These programs take an appropriately restricted subset of \fBpandoc\fR's
43+options. (Run them with the \fB-h\fR flag for a full list of allowed
44+options.)
45+.PP
2846\fIPandoc\fR uses the UTF\-8 character encoding for both input and output.
2947If your local character encoding is not UTF\-8, you should pipe input
3048and output through \fBiconv\fR:
@@ -33,61 +51,58 @@ and output through \fBiconv\fR:
3351
3452.SH OPTIONS
3553.TP
36−.B \-v, \-\-version
37−Print version.
38−.TP
39−.B \-h, \-\-help
40−Show usage message.
41−.TP
42−.B \-f FORMAT, \-r FORMAT, \-\-from=FORMAT, \-\-read=FORMAT
54+.B \-f \fIFORMAT\fB, \-r \fIFORMAT\fB, \-\-from=\fIFORMAT\fB, \-\-read=\fIFORMAT\fB
4355Specify input format.
4456.I FORMAT
4557can be
46−.I native
58+.B native
4759(native Haskell),
48−.I markdown
60+.B markdown
4961(markdown or plain text),
50−.I rst
62+.B rst
5163(reStructuredText),
52−.I html
64+.B html
5365(HTML),
5466or
55−.I latex
67+.B latex
5668(LaTeX).
5769.TP
58−.B \-t FORMAT, \-w FORMAT, \-\-to=FORMAT, \-\-write=FORMAT
70+.B \-t \fIFORMAT\fB, \-w \fIFORMAT\fB, \-\-to=\fIFORMAT\fB, \-\-write=\fIFORMAT\fB
5971Specify output format.
6072.I FORMAT
6173can be
62−.I native
74+.B native
6375(native Haskell),
64−.I markdown
76+.B markdown
6577(markdown or plain text),
66−.I rst
78+.B rst
6779(reStructuredText),
68−.I html
80+.B html
6981(HTML),
70−.I latex
82+.B latex
7183(LaTeX),
72−.I s5
84+.B s5
7385(S5 HTML and javascript slide show),
7486or
75−.I rtf
87+.B rtf
7688(rich text format).
7789.TP
7890.B \-s, \-\-standalone
7991Produce output with an appropriate header and footer (e.g. a
8092standalone HTML, LaTeX, or RTF file, not a fragment).
8193.TP
94+.B \-o FILE, \-\-output=FILE
95+Write output to \fIFILE\fR instead of STDOUT.
96+.TP
8297.B \-p, \-\-preserve-tabs
8398Preserve tabs instead of converting them to spaces.
8499.TP
85−.B \-\-tab-stop=TABSTOP
100+.B \-\-tab-stop=\fITABSTOP\fB
86101Specify tab stop (default is 4).
87102.TP
88103.B \-R, \-\-parse-raw
89−Parse untranslatable HTML codes and LaTeX environments as raw HTML or
90−LaTeX, instead of ignoring them.
104+Parse untranslatable HTML codes and LaTeX environments as raw HTML
105+or LaTeX, instead of ignoring them.
91106.TP
92107.B \-S, \-\-smartypants
93108Use smart quotes, dashes, and ellipses in HTML output.
@@ -99,41 +114,50 @@ Use ASCIIMathML to display embedded LaTeX math in HTML output.
99114Make list items in S5 display incrementally (one by one).
100115.TP
101116.B \-N, \-\-number-sections
102−Number section headings in LaTeX output. (Default is not to number them.)
117+Number section headings in LaTeX output. (Default is not to number
118+them.)
103119.TP
104−.B \-c CSS, \-\-css=CSS
120+.B \-c \fICSS\fB, \-\-css=\fICSS\fB
105121Link to a CSS style sheet.
106122.I CSS
107123is the pathname of the style sheet.
108124.TP
109−.B \-H FILENAME, \-\-include-in-header=FILENAME
110−Include contents of \fIFILENAME\fR at the end of the header. Implies
125+.B \-H \fIFILE\fB, \-\-include-in-header=\fIFILE\fB
126+Include contents of \fIFILE\fR at the end of the header. Implies
111127\fB\-s\fR.
112128.TP
113−.B \-B FILENAME, \-\-include-before-body=FILENAME
114−Include contents of \fIFILENAME\fR at the beginning of the document body.
129+.B \-B \fIFILE\fB, \-\-include-before-body=\fIFILE\fB
130+Include contents of \fIFILE\fR at the beginning of the document
131+body.
115132.TP
116−.B \-A FILENAME, \-\-include-after-body=FILENAME
117−Include contents of \fIFILENAME\fR at the end of the document body.
133+.B \-A \fIFILE\fB, \-\-include-after-body=\fIFILE\fB
134+Include contents of \fIFILE\fR at the end of the document body.
118135.TP
119−.B \-\-custom-header=FILENAME
120−Use contents of \fIFILENAME\fR
121−as the document header (overriding the default header, which can be
122−printed by using the \fB\-D\fR option). Implies
123−\fB-s\fR.
136+.B \-C \fIFILE\fB, \-\-custom-header=\fIFILE\fB
137+Use contents of \fIFILE\fR as the document header (overriding the
138+default header, which can be printed by using the \fB\-D\fR option).
139+Implies \fB-s\fR.
124140.TP
125−.B \-D FORMAT, \-\-print-default-header=FORMAT
126−Print the default header for \fIFORMAT\fR
127−(\fIhtml, s5, latex, markdown, rst, rtf\fR).
141+.B \-D \fIFORMAT\fB, \-\-print-default-header=\fIFORMAT\fB
142+Print the default header for \fIFORMAT\fR (\fIhtml, s5, latex,
143+markdown, rst, rtf\fR).
128144.TP
129−.B \-T STRING, \-\-title-prefix=STRING
145+.B \-T \fISTRING\fB, \-\-title-prefix=\fISTRING\fB
130146Specify \fISTRING\fR as a prefix to the HTML window title.
147+.TP
148+.B \-d, \-\-debug
149+Print debugging information (names of input and output files) to
150+STDERR. Write output to STDOUT, even if an output file was specified
151+using the \fB\-o\fR option.
152+.TP
153+.B \-v, \-\-version
154+Print version.
155+.TP
156+.B \-h, \-\-help
157+Show usage message.
131158
132159.SH "SEE ALSO"
133−\fBmarkdown2html\fR(1),
134−\fBhtml2markdown\fR(1),
135−\fBmarkdown2latex\fR(1),
136−\fBlatex2markdown\fR(1),
160+\fBweb2markdown\fR(1),
137161\fBmarkdown2pdf\fR(1),
138162\fBiconv\fR(1)
139163
man/man1/rst2markdown.1new file+1
@@ -0,0 +1 @@
1+.so man1/pandoc.1
man/man1/web2markdown.1new file+82
@@ -0,0 +1,82 @@
1+.TH WEB2MARKDOWN 1 "December 15, 2006" Pandoc "User Manuals"
2+.SH NAME
3+web2markdown \- converts HTML to markdown-formatted text
4+.SH SYNOPSIS
5+\fBweb2markdown\fR [\fIoptions\fR] [\fIinput\-file\fR or \fIURL\fR]
6+.SH DESCRIPTION
7+\fBweb2markdown\fR converts \fIinput\-file\fR or \fIURL\fR (or text
8+from STDIN) from HTML to markdown\-formatted plain text.
9+If a URL is specified, \fBweb2markdown\fR uses an available program
10+(e.g. wget, w3m, lynx or curl) to fetch its contents. Output is sent
11+to STDOUT unless an output file is specified using the \fB\-o\fR
12+option.
13+.PP
14+\fBweb2markdown\fR uses the character encoding specified in the
15+"Content-type" meta tag. If this is not present, or if input comes
16+from STDIN, UTF-8 is assumed. A character encoding may be specified
17+explicitly using the \fB\-e\fR option.
18+.PP
19+\fBweb2markdown\fR is a wrapper for \fBhtml2markdown\fR.
20+.SH OPTIONS
21+.TP
22+.B \-s, \-\-standalone
23+Include title, author, and date information (if present) at the
24+top of markdown output.
25+.TP
26+.B \-o FILE, \-\-output=FILE
27+Write output to \fIFILE\fR instead of STDOUT.
28+.TP
29+.B \-p, \-\-preserve-tabs
30+Preserve tabs instead of converting them to spaces.
31+.TP
32+.B \-\-tab-stop=\fITABSTOP\fB
33+Specify tab stop (default is 4).
34+.TP
35+.B \-R, \-\-parse-raw
36+Parse untranslatable HTML codes as raw HTML.
37+.TP
38+.B \-H \fIFILE\fB, \-\-include-in-header=\fIFILE\fB
39+Include contents of \fIFILE\fR at the end of the header. Implies
40+\fB\-s\fR.
41+.TP
42+.B \-B \fIFILE\fB, \-\-include-before-body=\fIFILE\fB
43+Include contents of \fIFILE\fR at the beginning of the document body.
44+.TP
45+.B \-A \fIFILE\fB, \-\-include-after-body=\fIFILE\fB
46+Include contents of \fIFILE\fR at the end of the document body.
47+.TP
48+.B \-C \fIFILE\fB, \-\-custom-header=\fIFILE\fB
49+Use contents of \fIFILE\fR
50+as the document header (overriding the default header, which can be
51+printed using '\fBpandoc \-D markdown\fR'). Implies
52+\fB-s\fR.
53+.TP
54+.B \-v, \-\-version
55+Print version.
56+.TP
57+.B \-h, \-\-help
58+Show usage message.
59+.TP
60+.B \-e \fIencoding\fR
61+Assume the character encoding \fIencoding\fR in reading HTML.
62+(Note: \fIencoding\fR will be passed to \fBiconv\fR; a list of
63+available encodings may be obtained using `\fBiconv \-l\fR'.)
64+If the \fB\-e\fR option is not specified and input is not from
65+STDIN, \fBweb2markdown\fR will try to extract the character encoding
66+from the "Content-type" meta tag. If no character encoding is
67+specified in this way, or if input is from STDIN, UTF-8 will be
68+assumed.
69+.TP
70+.B \-g \fIcommand\fR
71+Use \fIcommand\fR to fetch the contents of a URL. (By default,
72+\fBweb2markdown\fR searches for an available program or text-based
73+browser to fetch the contents of a URL.) For example:
74+.IP
75+web2markdown \-g 'wget \-\-user=foo \-\-password=bar' mysite.com
76+
77+.SH "SEE ALSO"
78+\fBpandoc\fR(1),
79+\fBhtml2markdown\fR(1),
80+\fBiconv\fR(1)
81+.SH AUTHOR
82+John MacFarlane and Recai Oktas
src/Main.hs+116−26
@@ -45,6 +45,7 @@ import Text.Pandoc.Writers.DefaultHeaders ( defaultHtmlHeader,
4545 defaultRTFHeader, defaultS5Header, defaultLaTeXHeader )
4646import Text.Pandoc.Definition
4747import Text.Pandoc.Shared
48+import Text.Regex ( mkRegex, splitRegex )
4849import System ( exitWith, getArgs, getProgName )
4950import System.Exit
5051import System.Console.GetOpt
@@ -57,6 +58,9 @@ import Control.Monad ( (>>=) )
5758version :: String
5859version = "0.3"
5960
61+copyrightMessage :: String
62+copyrightMessage = "\nCopyright (C) 2006 John MacFarlane\nWeb: http://sophos.berkeley.edu/macfarlane/pandoc\nThis is free software; see the source for copying conditions. There is no\nwarranty, not even for merchantability or fitness for a particular purpose."
63+
6064-- | Association list of formats and readers.
6165readers :: [(String, ParserState -> String -> Pandoc)]
6266readers = [("native" , readPandoc)
@@ -101,10 +105,13 @@ data Opt = Opt
101105 , optCustomHeader :: String -- ^ Custom header to use, or "DEFAULT"
102106 , optDefaultHeader :: String -- ^ Default header
103107 , optTitlePrefix :: String -- ^ Optional prefix for HTML title
108+ , optOutputFile :: String -- ^ Name of output file
104109 , optNumberSections :: Bool -- ^ If @True@, number sections in LaTeX
105110 , optIncremental :: Bool -- ^ If @True@, incremental lists in S5
106111 , optSmart :: Bool -- ^ If @True@, use smart typography
107112 , optASCIIMathML :: Bool -- ^ If @True@, use ASCIIMathML in HTML
113+ , optShowUsage :: Bool -- ^ If @True@, show usage message
114+ , optDebug :: Bool -- ^ If @True@, output debug messages
108115 }
109116
110117-- | Defaults for command-line options.
@@ -123,32 +130,20 @@ startOpt = Opt
123130 , optCustomHeader = "DEFAULT"
124131 , optDefaultHeader = defaultHtmlHeader
125132 , optTitlePrefix = ""
133+ , optOutputFile = "" -- null for stdout
126134 , optNumberSections = False
127135 , optIncremental = False
128136 , optSmart = False
129137 , optASCIIMathML = False
138+ , optShowUsage = False
139+ , optDebug = False
130140 }
131141
132142-- | A list of functions, each transforming the options data structure in response
133143-- to a command-line option.
134−options :: [OptDescr (Opt -> IO Opt)]
135−options =
136− [ Option "v" ["version"]
137− (NoArg
138− (\_ -> do
139− hPutStrLn stderr ("Version " ++ version)
140− exitWith ExitSuccess))
141− "Print version"
142−
143− , Option "h" ["help"]
144− (NoArg
145− (\_ -> do
146− prg <- getProgName
147− hPutStrLn stderr (usageInfo (prg ++ " [OPTIONS] [FILES] - convert FILES from one markup format to another\nIf no OPTIONS specified, converts from markdown to html.\nIf no FILES specified, input is read from STDIN.\nOptions:") options)
148− exitWith ExitSuccess))
149− "Show help"
150−
151− , Option "fr" ["from","read"]
144+allOptions :: [OptDescr (Opt -> IO Opt)]
145+allOptions =
146+ [ Option "fr" ["from","read"]
152147 (ReqArg
153148 (\arg opt -> case (lookup (map toLower arg) readers) of
154149 Just reader -> return opt { optReader = reader }
@@ -172,6 +167,13 @@ options =
172167 (\opt -> return opt { optStandalone = True }))
173168 "Include needed header and footer on output"
174169
170+ , Option "o" ["output"]
171+ (ReqArg
172+ (\arg opt -> do
173+ return opt { optOutputFile = arg })
174+ "FILENAME")
175+ "Name of output file"
176+
175177 , Option "p" ["preserve-tabs"]
176178 (NoArg
177179 (\opt -> return opt { optPreserveTabs = True }))
@@ -241,7 +243,7 @@ options =
241243 "FILENAME")
242244 "File to include after document body"
243245
244− , Option "" ["custom-header"]
246+ , Option "C" ["custom-header"]
245247 (ReqArg
246248 (\arg opt -> do
247249 text <- readFile arg
@@ -263,18 +265,87 @@ options =
263265 let header = case (lookup arg writers) of
264266 Just (writer, head) -> head
265267 Nothing -> error ("Unknown reader: " ++ arg)
266− hPutStrLn stdout header
268+ hPutStr stdout header
267269 exitWith ExitSuccess)
268270 "FORMAT")
269271 "Print default header for FORMAT"
272+
273+ , Option "d" ["debug"]
274+ (NoArg
275+ (\opt -> return opt { optDebug = True }))
276+ "Print debug messages to stderr, output to stdout"
277+
278+ , Option "v" ["version"]
279+ (NoArg
280+ (\_ -> do
281+ prg <- getProgName
282+ hPutStrLn stderr (prg ++ " " ++ version ++
283+ copyrightMessage)
284+ exitWith $ ExitFailure 2))
285+ "Print version"
286+
287+ , Option "h" ["help"]
288+ (NoArg
289+ (\opt -> return opt { optShowUsage = True }))
290+ "Show help"
270291 ]
292+
293+-- parse name of calling program and return default reader and writer descriptions
294+parseProgName name =
295+ case (splitRegex (mkRegex "2") (map toLower name)) of
296+ [from, to] -> (from, to)
297+ _ -> ("markdown", "html")
298+
299+-- set default options based on reader and writer descriptions; start is starting options
300+setDefaultOpts from to start =
301+ case ((lookup from readers), (lookup to writers)) of
302+ (Just reader, Just (writer, header)) -> start {optReader = reader,
303+ optWriter = writer,
304+ optDefaultHeader = header}
305+ _ -> start
306+
307+-- True if single-letter option is in option list
308+inOptList :: [Char] -> OptDescr (Opt -> IO Opt) -> Bool
309+inOptList list desc =
310+ let (Option letters _ _ _) = desc in
311+ any (\x -> x `elem` list) letters
312+
313+-- Reformat usage message so it doesn't wrap illegibly
314+reformatUsageInfo = gsub " *--" " --" .
315+ gsub "(-[A-Za-z0-9]) *--" "\\1, --" .
316+ gsub " *([^- ])" "\n\t\\1"
317+
271318main = do
272319
320+ name <- getProgName
321+ let (from, to) = parseProgName name
322+
323+ let irrelevantOptions = if not ('2' `elem` name)
324+ then ""
325+ else "frtwD" ++
326+ (if (to /= "html" && to /= "s5") then "SmcT" else "") ++
327+ (if (to /= "latex") then "N" else "") ++
328+ (if (to /= "s5") then "i" else "") ++
329+ (if (from /= "html" && from /= "latex") then "R" else "")
330+
331+ let options = filter (not . inOptList irrelevantOptions) allOptions
332+
333+ let defaultOpts = setDefaultOpts from to startOpt
334+
273335 args <- getArgs
274− let (actions, sources, errors) = getOpt RequireOrder options args
336+ let (actions, sources, errors) = getOpt Permute options args
337+
338+ if (not (null errors))
339+ then do
340+ mapM (\e -> hPutStrLn stderr e) errors
341+ hPutStrLn stderr (reformatUsageInfo $
342+ usageInfo (name ++ " [OPTIONS] [FILES]") options)
343+ exitWith $ ExitFailure 2
344+ else
345+ return ()
275346
276347 -- thread option data structure through all supplied option actions
277− opts <- foldl (>>=) (return startOpt) actions
348+ opts <- foldl (>>=) (return defaultOpts) actions
278349
279350 let Opt { optPreserveTabs = preserveTabs
280351 , optTabStop = tabStop
@@ -289,12 +360,31 @@ main = do
289360 , optCustomHeader = customHeader
290361 , optDefaultHeader = defaultHeader
291362 , optTitlePrefix = titlePrefix
363+ , optOutputFile = outputFile
292364 , optNumberSections = numberSections
293365 , optIncremental = incremental
294366 , optSmart = smart
295367 , optASCIIMathML = asciiMathML
368+ , optShowUsage = showUsage
369+ , optDebug = debug
296370 } = opts
297371
372+ if showUsage
373+ then do
374+ hPutStr stderr (reformatUsageInfo $ usageInfo (name ++ " [OPTIONS] [FILES]") options)
375+ exitWith $ ExitFailure 2
376+ else return ()
377+
378+ output <- if ((null outputFile) || debug)
379+ then return stdout
380+ else openFile outputFile WriteMode
381+
382+ if debug
383+ then do
384+ hPutStrLn stderr ("OUTPUT=" ++ outputFile)
385+ hPutStr stderr $ concatMap (\s -> "INPUT=" ++ s ++ "\n") sources
386+ else return ()
387+
298388 let writingS5 = (defaultHeader == defaultS5Header)
299389 let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)
300390 let addBlank str = str ++ "\n\n"
@@ -323,13 +413,13 @@ main = do
323413 writerIncludeBefore = includeBefore,
324414 writerIncludeAfter = includeAfter }
325415
326− (readSources sources) >>= (putStr . encodeUTF8 . (writer writerOptions) .
416+ (readSources sources) >>= (hPutStr output . encodeUTF8 .
417+ (writer writerOptions) .
327418 (reader startParserState) . filter .
328− decodeUTF8 . (joinWithSep "\n"))
419+ decodeUTF8 . (joinWithSep "\n")) >> hClose output
329420
330421 where
331422 readSources [] = mapM readSource ["-"]
332423 readSources sources = mapM readSource sources
333− readSource "-" = getContents
424+ readSource "-" = getContents
334425 readSource source = readFile source
335−
src/wrappers/checkin.shdeleted−7
@@ -1,7 +0,0 @@
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.sh−27
@@ -8,22 +8,6 @@ WRAPPEE_ARGS=
88err () { echo "$*" | fold -s -w ${COLUMNS:-110} >&2; }
99errn () { printf "$*" | fold -s -w ${COLUMNS:-110} >&2; }
1010
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−
2711# Portable which(1).
2812pathfind () {
2913 oldifs="$IFS"; IFS=':'
@@ -37,17 +21,6 @@ pathfind () {
3721 return 1
3822}
3923
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−
5124for p in pandoc $REQUIRED; do
5225 pathfind $p || {
5326 err "You need '$p' to use this program!"
src/wrappers/getopts.shdeleted−12
@@ -1,12 +0,0 @@
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.indeleted−134
@@ -1,134 +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−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.indeleted−14
@@ -1,14 +0,0 @@
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.indeleted−12
@@ -1,12 +0,0 @@
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.indeleted−12
@@ -1,12 +0,0 @@
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.in+29−39
@@ -1,64 +1,54 @@
11#!/bin/sh -e
2−# converts markdown to latex, then uses latex to make a PDF
32
4−REQUIRED=pdflatex
3+REQUIRED="markdown2latex pdflatex"
54
65### common.sh
76
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
7+### tempdir.sh
198
20−### checkin.sh
9+texname=output
10+logfile=$THIS_TEMPDIR/log
2111
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
12+if ! markdown2latex -s -d "$@" >$THIS_TEMPDIR/$texname.tex 2>$logfile; then
13+ [ -f $logfile ] && sed -e 's/markdown2latex/markdown2pdf/g' \
14+ -e '/^INPUT=/d' -e '/^OUTPUT=/d' $logfile >&2
15+ exit 1
2816fi
29−case "$outfile" in
30−*.*) ;; # skip appending extension if one is already present
31−*) outfile="${outfile%.*}.pdf";;
32−esac
3317
34−### tempdir.sh
35−
36−# We should use a filename without white spaces for pdflatex.
37−TEXNAME=$THIS
18+outfile="$(sed -ne 's/^OUTPUT=//p' $logfile)"
19+IFS="$NEWLINE"
20+set -- $(sed -ne 's/^INPUT=//p' $logfile)
21+firstinfilebase="${1%.*}"
22+defaultdest="${firstinfilebase:-stdin}.pdf"
23+destname="${outfile:-$defaultdest}"
3824
39−to_utf8 "$@" | runpandoc -w latex -s >$THIS_TEMPDIR/$TEXNAME.tex
4025(
4126 cd $THIS_TEMPDIR
42− if ! pdflatex -interaction=batchmode $TEXNAME.tex >/dev/null 2>&1; then
27+ if ! pdflatex -interaction=batchmode $texname.tex >/dev/null 2>&1; then
4328 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."
29+ sed -ne '/^!/,/^ *$/p' $texname.log >&2
30+ if grep -q "File \`ucs.sty' not found" $texname.log; then
31+ err "Please install the 'unicode' package from CTAN:"
32+ err "http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/"
33+ fi
34+ if grep -q "File \`fancyvrb.sty' not found" $texname.log; then
35+ err "Please install the 'fancyvrb' package from CTAN:"
36+ err "http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/"
4737 fi
4838 exit 1
4939 fi
50−)
40+) || exit $?
5141
5242is_target_exists=
53−if [ -f "$outfile" ]; then
43+if [ -f "$destname" ]; then
5444 is_target_exists=1
55− mv -f "$outfile" "$outfile~"
45+ mv "$destname" "$destname~"
5646fi
5747
58−mv -f $THIS_TEMPDIR/$TEXNAME.pdf "$outfile"
48+mv -f $THIS_TEMPDIR/$texname.pdf "$destname"
5949
60−errn "Created '$outfile'"
50+errn "Created $destname"
6151[ -z "$is_target_exists" ] || {
62− errn " (previous file has been backed up as '$outfile~')"
52+ errn " (previous file has been backed up as $destname~)"
6353}
6454err .
src/wrappers/postopts.shdeleted−17
@@ -1,17 +0,0 @@
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.shdeleted−7
@@ -1,7 +0,0 @@
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/testwrapper.indeleted−141
@@ -1,141 +0,0 @@
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 3... "
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
src/wrappers/web2markdown.innew file+173
@@ -0,0 +1,173 @@
1+#!/bin/sh -e
2+# converts HTML from a URL, file, or stdin to markdown
3+# uses an available program to fetch URL and tidy to normalize it first
4+
5+REQUIRED="tidy html2markdown"
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+add_option () {
63+ options="$options$NEWLINE$1"
64+}
65+
66+options=
67+argument=
68+encoding=
69+grabber=
70+
71+# Parse command-line arguments
72+while [ $# -gt 0 ]; do
73+ case "$1" in
74+ -h|--help)
75+ html2markdown -h 2>&1 | sed -e 's/html2markdown/web2markdown/' 1>&2
76+ err " -e ENCODING, --encoding=ENCODING"
77+ err " Specify character encoding of input"
78+ err " -g COMMAND, --grabber=COMMAND"
79+ err " Specify command to be used to grab contents of URL"
80+ exit 0 ;;
81+ -v|--version)
82+ html2markdown -v
83+ exit 0 ;;
84+ -e)
85+ shift
86+ encoding=$1 ;;
87+ --encoding=*)
88+ wholeopt=$1
89+ # extract encoding from after =
90+ encoding=${wholeopt#*=} ;;
91+ -g)
92+ shift
93+ grabber=$1 ;;
94+ --grabber=*)
95+ wholeopt=$1
96+ # extract encoding from after =
97+ grabber=${wholeopt#*=} ;;
98+ -o|--output|-b|--tab-stop|-H|--include-in-header| \
99+ -A|--include-after-body|-C|-B|--include-before-body| \
100+ -C|--custom-header|-T|--title-prefix)
101+ add_option $1
102+ shift
103+ add_option $1 ;;
104+ -*) add_option $1 ;;
105+ *)
106+ if [ -z "$argument" ]; then
107+ argument=$1
108+ else
109+ err "Warning: extra argument '$1' will be ignored."
110+ fi ;;
111+ esac
112+ shift
113+done
114+
115+# Unpack options. Now "$@" will hold the html2markdown options.
116+oldifs="$IFS"; IFS="$NEWLINE"; set -- $options; IFS="$oldifs"
117+
118+inurl=
119+if [ -n "$argument" ] && ! [ -f "$argument" ]; then
120+ # Treat given argument as an URL.
121+ inurl="$argument"
122+fi
123+
124+if [ -n "$inurl" ]; then
125+ err "Attempting to fetch file from '$inurl'..."
126+
127+ ### tempdir.sh
128+
129+ grabber_out=$THIS_TEMPDIR/grabber.out
130+ grabber_log=$THIS_TEMPDIR/grabber.log
131+ if ! grab_url_with "$inurl" "$grabber" 1>$grabber_out 2>$grabber_log; then
132+ errn "grab_url_with failed"
133+ if [ -f $grabber_log ]; then
134+ err " with the following error log."
135+ err
136+ cat >&2 $grabber_log
137+ else
138+ err .
139+ fi
140+ exit 1
141+ fi
142+
143+ argument="$grabber_out"
144+fi
145+
146+if [ -z "$encoding" ] && [ "x$argument" != "x" ]; then
147+ # Try to determine character encoding if not specified
148+ # and input is not STDIN.
149+ encoding=$(
150+ head "$argument" |
151+ LC_ALL=C tr 'A-Z' 'a-z' |
152+ sed -ne '/<meta .*content-type.*charset=/ {
153+ s/.*charset=["'\'']*\([-a-zA-Z0-9]*\).*["'\'']*/\1/p
154+ }'
155+ )
156+fi
157+
158+if [ -n "$encoding" ] && pathfind iconv; then
159+ alias to_utf8='iconv -f "$encoding" -t utf-8'
160+else # assume UTF-8
161+ alias to_utf8='cat'
162+fi
163+
164+if [ -z "$argument" ]; then
165+ tidy -utf8 2>/dev/null | html2markdown "$@"
166+else
167+ if [ -f "$argument" ]; then
168+ to_utf8 "$argument" | tidy -utf8 2>/dev/null | html2markdown "$@"
169+ else
170+ err "File '$argument' not found."
171+ exit 1
172+ fi
173+fi