git.iko.soy/typeable/pandoc
on master help sign in
Merged changes from branches/wrappers since r177.
d829c48fiddlosopher
Makefile+14−10
@@ -23,15 +23,16 @@ EXECSBASE := $(shell sed -ne 's/^[Ee]xecutable:[[:space:]]*//p' $(CABAL).in)
23#-------------------------------------------------------------------------------
23#-------------------------------------------------------------------------------
24# Install targets
24# Install targets
25#-------------------------------------------------------------------------------
25#-------------------------------------------------------------------------------
26+WRAPPERS := web2markdown markdown2pdf
27+SYMLINKS := markdown2html markdown2latex markdown2s5 markdown2rst \
28+ markdown2rtf html2markdown latex2markdown rst2markdown
29+PROGS := $(EXECS) $(WRAPPERS)
26# Add .exe extensions if we're running Windows/Cygwin.
30# Add .exe extensions if we're running Windows/Cygwin.
27EXTENSION := $(shell uname | tr '[:upper:]' '[:lower:]' | \
31EXTENSION := $(shell uname | tr '[:upper:]' '[:lower:]' | \
28 sed -ne 's/^cygwin.*$$/\.exe/p')
32 sed -ne 's/^cygwin.*$$/\.exe/p')
29EXECS := $(addsuffix $(EXTENSION),$(EXECSBASE))
33EXECS := $(addsuffix $(EXTENSION),$(EXECSBASE))
30# First entry in Cabal's executable stanza is the main executable.
34# First entry in Cabal's executable stanza is the main executable.
31MAIN := $(firstword $(EXECS))
35MAIN := $(firstword $(EXECS))
32−WRAPPERS := html2markdown latex2markdown markdown2html \
33− markdown2latex markdown2pdf
34−PROGS := $(EXECS) $(WRAPPERS)
35DOCS := README.html README BUGS
36DOCS := README.html README BUGS
36
37
37#-------------------------------------------------------------------------------
38#-------------------------------------------------------------------------------
@@ -92,6 +93,12 @@ all: build-program
92templates: $(SRCDIR)/templates
93templates: $(SRCDIR)/templates
93 $(MAKE) -C $(SRCDIR)/templates
94 $(MAKE) -C $(SRCDIR)/templates
94
95
96+.PHONY: symlinks
97+cleanup_files+=$(SYMLINKS)
98+symlinks: $(SYMLINKS)
99+$(SYMLINKS): $(MAIN)
100+ ln -sf ./$(MAIN) $@
101+
95define generate-shell-script
102define generate-shell-script
96echo "Generating $@..."; \
103echo "Generating $@..."; \
97awk ' \
104awk ' \
@@ -131,7 +138,7 @@ build: configure
131 $(BUILDCMD) build
138 $(BUILDCMD) build
132
139
133.PHONY: build-exec
140.PHONY: build-exec
134−build-exec: $(PROGS)
141+build-exec: $(PROGS) $(SYMLINKS)
135cleanup_files+=$(EXECS)
142cleanup_files+=$(EXECS)
136$(EXECS): build
143$(EXECS): build
137 for f in $@; do \
144 for f in $@; do \
@@ -191,8 +198,9 @@ install-exec: build-exec
191 fi; \
198 fi; \
192 $(INSTALL_PROGRAM) $$f $(BINPATH)/; \
199 $(INSTALL_PROGRAM) $$f $(BINPATH)/; \
193 done
200 done
201+ cd $(BINPATH); for f in $(SYMLINKS); do ln -sf $(MAIN) $$f; done
194uninstall-exec:
202uninstall-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 ;
196
204
197# Program + user documents installation.
205# Program + user documents installation.
198.PHONY: install-program uninstall-program
206.PHONY: install-program uninstall-program
@@ -277,15 +285,11 @@ osx-dmg: ../$(osx_dmg_name)
277 -rm -f $(osx_dmg_name)
285 -rm -f $(osx_dmg_name)
278 mv $(osx_udzo_name) ../$(osx_dmg_name)
286 mv $(osx_udzo_name) ../$(osx_dmg_name)
279
287
280−.PHONY: test test-markdown test-wrapper
288+.PHONY: test test-markdown
281test: $(MAIN)
289test: $(MAIN)
282 @cd $(TESTDIR) && perl runtests.pl -s $(PWD)/$(MAIN)
290 @cd $(TESTDIR) && perl runtests.pl -s $(PWD)/$(MAIN)
283test-markdown: $(MAIN)
291test-markdown: $(MAIN)
284 @cd $(TESTDIR)/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(MAIN) -tidy
292 @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
289
293
290# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
294# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
291src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
295src_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.
20[reStructuredText]: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
20[reStructuredText]: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
21[S5]: http://meyerweb.com/eric/tools/s5/
21[S5]: http://meyerweb.com/eric/tools/s5/
22[HTML]: http://www.w3.org/TR/html40/
22[HTML]: http://www.w3.org/TR/html40/
23−[LaTeX]: http://www.latex-project.org/
23+[LaTeX]: http://www.latex-project.org/
24[RTF]: http://en.wikipedia.org/wiki/Rich_Text_Format
24[RTF]: http://en.wikipedia.org/wiki/Rich_Text_Format
25[Haskell]: http://www.haskell.org/
25[Haskell]: http://www.haskell.org/
26
26
@@ -30,9 +30,53 @@ any kind. (See COPYRIGHT for full copyright and warranty notices.)
30Recai Oktaş (roktas at debian dot org) deserves credit for the build
30Recai Oktaş (roktas at debian dot org) deserves credit for the build
31system, the debian package, and the robust wrapper scripts.
31system, the debian package, and the robust wrapper scripts.
32
32
33−[GPL]: http://www.gnu.org/copyleft/gpl.html
33+[GPL]: http://www.gnu.org/copyleft/gpl.html "GNU General Public License"
34
34
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+
35−# Using Pandoc
78+Using Pandoc
79+============
36
80
37If you run `pandoc` without arguments, it will accept input from
81If you run `pandoc` without arguments, it will accept input from
38STDIN. If you run it with file names as arguments, it will take input
82STDIN. 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
66tables, definition lists, option lists, or footnotes. It handles only the
110tables, definition lists, option lists, or footnotes. It handles only the
67constructs expressible in unextended markdown. But for simple documents
111constructs expressible in unextended markdown. But for simple documents
68it should be adequate. The `latex` and `html` readers are also limited
112it 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:
70
119
71−`pandoc` writes its output to STDOUT. If you want to write to a file,
120+ pandoc -o hello.html hello.txt
72−use redirection:
73
121
74 pandoc hello.txt > hello.html
122 pandoc hello.txt > hello.html
75
123
@@ -77,13 +125,14 @@ Note that you can specify multiple input files on the command line.
77`pandoc` will concatenate them all (with blank lines between them)
125`pandoc` will concatenate them all (with blank lines between them)
78before parsing:
126before parsing:
79
127
80− pandoc -s chapter1.txt chapter2.txt chapter3.txt references.txt > book.html
128+ pandoc -s chapter1.txt chapter2.txt references.txt > book.html
81
129
82(The `-s` option here tells `pandoc` to produce a standalone HTML file,
130(The `-s` option here tells `pandoc` to produce a standalone HTML file,
83with a proper header, rather than a fragment. For more details on this
131with a proper header, rather than a fragment. For more details on this
84and many other command-line options, see below.)
132and many other command-line options, see below.)
85
133
86−# Character encodings
134+Character encodings
135+-------------------
87
136
88Unfortunately, due to limitations in GHC, `pandoc` does not automatically
137Unfortunately, due to limitations in GHC, `pandoc` does not automatically
89detect the system's local character encoding. Hence, all input and
138detect 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
97convert it to HTML, then convert back to the local encoding,
146convert it to HTML, then convert back to the local encoding,
98putting the output in `output.html`.
147putting the output in `output.html`.
99
148
100−[`iconv`]: http://www.gnu.org/software/libiconv/
101−
102The shell scripts (described below) automatically convert the input
149The shell scripts (described below) automatically convert the input
103from the local encoding to UTF-8 before running them through `pandoc`,
150from the local encoding to UTF-8 before running them through `pandoc`,
104then convert the output back to the local encoding.
151then convert the output back to the local encoding.
105
152
106−## LaTeX and UTF-8
153+Convenience programs and wrapper scripts
107−
154+========================================
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.)
117
155
118−[CTAN]: http://www.ctan.org
156+For convenience, eight variant programs are included with Pandoc:
119−[unicode]: http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/
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.)
120
167
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:
122
171
123−Five shell scripts have been included that make it easy to run
172+ markdown2latex -s sample.txt > sample.tex
124−`pandoc` without worrying about character encodings, and without
125−remembering all the command-line options:
126
173
127−- `markdown2html` converts markdown-formatted text to HTML
174+Two shell scripts have also been included:
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
133
175
134−All of the scripts use `iconv` (if available) to convert to and from
176+1. `markdown2pdf` produces a PDF file from markdown-formatted
135−the local character encoding. All of the scripts presuppose that
177+ text, using `markdown2latex` and `pdflatex`. The default
136−`pandoc` is in the path, and some have additional requirements. (For
178+ behavior of `markdown2pdf` is to create a file with the same
137−example, `html2markdown` uses `tidy`, and `markdown2pdf` uses
179+ base name as the first argument and the extension `pdf`; thus,
138−`pdflatex`.)
180+ for example,
139
181
140−When no arguments are specified, text will be read from standard
182+ markdown2pdf sample.txt endnotes.txt
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.)
148
183
149−With the exception of `markdown2pdf`, the scripts write to standard output.
184+ will produce `sample.pdf`. (If `sample.pdf` exists already,
150−Output can be sent to a file using shell output redirection:
185+ it will be backed up before being overwritten.) An output file
186+ name can be specified explicitly using the `-o` option:
151
187
152− latex2markdown sample.tex > sample.txt
188+ markdown2pdf -o "My Book.pdf" chap1.txt chap2.txt chap3.txt
153
189
154−The default behavior of `markdown2pdf` is to create a file with the same
190+ If no input file is specified, input will be taken from STDIN.
155−base name as the first argument and the extension `pdf`; thus, for example,
156
191
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.
158
198
159−will produce `sample.pdf`. (If `sample.pdf` exists already, it will be
199+ `web2markdown` searches for an available program (`wget`, `curl`,
160−backed up before being overwritten.) An output file name can be specified
200+ or a text-mode browser) to fetch the contents of a URL.
161−explicitly using the `-o` option:
201+ Optionally, the `-g` command may be used to specify the command
202+ to be used:
162
203
163− markdown2pdf -o "My Book.pdf" chap1.txt chap2.txt chap3.txt
204+ web2markdown -g 'wget --user=foo --password=bar' mysite.com
164
205
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+====================
186
208
187Various command-line options can be used to customize the output.
209Various command-line options can be used to customize the output.
188For a complete list, type
210For a complete list, type
@@ -207,9 +229,11 @@ specified.)
207complete with appropriate document headers. By default, `pandoc`
229complete with appropriate document headers. By default, `pandoc`
208produces a fragment.
230produces a fragment.
209
231
232+`-o` or `--output-file` can be used to specify an output file.
233+
210−`--custom-header` can be used to specify a custom document header. To
234+`-C` or `--custom-header` can be used to specify a custom document
211−see the headers used by default, use the `-D` option: for example,
235+header. To see the headers used by default, use the `-D` option:
212−`pandoc -D html` prints the default HTML header.
236+for example, `pandoc -D html` prints the default HTML header.
213
237
214`-c` or `--css` allows the user to specify a custom stylesheet that
238`-c` or `--css` allows the user to specify a custom stylesheet that
215will be linked to in HTML and S5 output.
239will be linked to in HTML and S5 output.
@@ -253,15 +277,38 @@ is for lists to be displayed all at once.
253`-N` or `--number-sections` causes sections to be numbered in LaTeX
277`-N` or `--number-sections` causes sections to be numbered in LaTeX
254output. By default, sections are not numbered.
278output. By default, sections are not numbered.
255
279
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+
256−# Pandoc's markdown vs. standard markdown
300+Pandoc's markdown vs. standard markdown
301+=======================================
257
302
258In parsing markdown, Pandoc departs from and extends [standard markdown]
303In parsing markdown, Pandoc departs from and extends [standard markdown]
259in a few respects. (To run Pandoc on the official
304in a few respects. (To run Pandoc on the official
260markdown test suite, type `make test-markdown`.)
305markdown test suite, type `make test-markdown`.)
261
306
262[standard markdown]: http://daringfireball.net/projects/markdown/syntax
307[standard markdown]: http://daringfireball.net/projects/markdown/syntax
308+ "Markdown syntax description"
263
309
264−## Section Headings
310+Section Headings
311+----------------
265
312
266Pandoc creates an invisible anchor in front of every HTML section
313Pandoc creates an invisible anchor in front of every HTML section
267heading. The ID of this anchor is derived from the section heading
314heading. The ID of this anchor is derived from the section heading
@@ -281,7 +328,8 @@ example, just insert:
281
328
282 [Back to Aristotle](#Aristotle's_De_Anima)
329 [Back to Aristotle](#Aristotle's_De_Anima)
283
330
284−## Lists
331+Lists
332+-----
285
333
286Pandoc behaves differently from standard markdown on some "edge
334Pandoc behaves differently from standard markdown on some "edge
287cases" involving lists. Consider this source:
335cases" involving lists. Consider this source:
@@ -332,7 +380,8 @@ the example above:
332 B) Fie
380 B) Fie
333 C) Third
381 C) Third
334
382
335−## Literal quotes in titles
383+Literal quotes in titles
384+------------------------
336
385
337Standard markdown allows unescaped literal quotes in titles, as
386Standard markdown allows unescaped literal quotes in titles, as
338in
387in
@@ -343,7 +392,8 @@ Pandoc requires all quotes within titles to be escaped:
343
392
344 [foo]: "bar \"embedded\" baz"
393 [foo]: "bar \"embedded\" baz"
345
394
346−## Reference links
395+Reference links
396+---------------
347
397
348Pandoc allows implicit reference links in either of two styles:
398Pandoc allows implicit reference links in either of two styles:
349
399
@@ -357,7 +407,8 @@ will appear as regular bracketed text. Note: even `[link][]` will
357appear as `[link]` if there's no reference for `link`. If you want
407appear as `[link]` if there's no reference for `link`. If you want
358`[link][]`, use a backslash escape: `\[link]\[]`.
408`[link][]`, use a backslash escape: `\[link]\[]`.
359
409
360−## Footnotes
410+Footnotes
411+---------
361
412
362Pandoc's markdown allows footnotes, using the following syntax:
413Pandoc's markdown allows footnotes, using the following syntax:
363
414
@@ -394,7 +445,8 @@ they cannot contain multiple paragraphs). The syntax is as follows:
394
445
395Inline and regular footnotes may be mixed freely.
446Inline and regular footnotes may be mixed freely.
396
447
397−## Embedded HTML
448+Embedded HTML
449+-------------
398
450
399Pandoc treats embedded HTML in markdown a bit differently than
451Pandoc treats embedded HTML in markdown a bit differently than
400Markdown 1.0. While Markdown 1.0 leaves HTML blocks exactly as they
452Markdown 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
427a block of markdown text with `<div>` tags without preventing it
479a block of markdown text with `<div>` tags without preventing it
428from being interpreted as markdown.
480from being interpreted as markdown.
429
481
430−## Title blocks
482+Title blocks
483+------------
431
484
432If the file begins with a title block
485If the file begins with a title block
433
486
@@ -460,7 +513,8 @@ If a title prefix is specified with `-T` and no title block appears
460in the document, the title prefix will be used by itself as the
513in the document, the title prefix will be used by itself as the
461HTML title.
514HTML title.
462
515
463−## Box-style blockquotes
516+Box-style blockquotes
517+---------------------
464
518
465Pandoc supports emacs-style boxquote block quotes, in addition to
519Pandoc supports emacs-style boxquote block quotes, in addition to
466standard markdown (email-style) boxquotes:
520standard markdown (email-style) boxquotes:
@@ -469,7 +523,8 @@ standard markdown (email-style) boxquotes:
469 | They look like this.
523 | They look like this.
470 `----
524 `----
471
525
472−## Inline LaTeX
526+Inline LaTeX
527+------------
473
528
474Anything between two $ characters will be parsed as LaTeX math. The
529Anything between two $ characters will be parsed as LaTeX math. The
475opening $ must have a character immediately to its right, while the
530opening $ must have a character immediately to its right, while the
@@ -501,7 +556,8 @@ You can also use LaTeX environments. For example,
501Note, however, that material between the begin and end tags will
556Note, however, that material between the begin and end tags will
502be interpreted as raw LaTeX, not as markdown.
557be interpreted as raw LaTeX, not as markdown.
503
558
504−## Custom headers
559+Custom headers
560+--------------
505
561
506When run with the "standalone" option (`-s`), `pandoc` creates a
562When run with the "standalone" option (`-s`), `pandoc` creates a
507standalone file, complete with an appropriate header. To see the
563standalone file, complete with an appropriate header. To see the
@@ -516,13 +572,14 @@ it and specify it on the command line as follows:
516
572
517 pandoc --header=MyHeaderFile
573 pandoc --header=MyHeaderFile
518
574
519−# Producing S5 with Pandoc
575+Producing S5 with Pandoc
576+========================
520
577
521−Producing an [S5] slide show with Pandoc is easy. A title page is
578+Producing an [S5] web-based slide show with Pandoc is easy. A title
522−constructed automatically from the document's title block (see above).
579+page is constructed automatically from the document's title block (see
523−Each section (with a level-one header) produces a single slide. (Note
580+above). Each section (with a level-one header) produces a single slide.
524−that if the section is too big, the slide will not fit on the page; S5
581+(Note that if the section is too big, the slide will not fit on the page;
525−is not smart enough to produce multiple pages.)
582+S5 is not smart enough to produce multiple pages.)
526
583
527Here's the markdown source for a simple slide show, `eating.txt`:
584Here's the markdown source for a simple slide show, `eating.txt`:
528
585
debian/changelog+2
@@ -14,6 +14,8 @@ pandoc (0.22) unstable; urgency=low
14
14
15 * Refactored template processing (fillTemplates.pl).
15 * Refactored template processing (fillTemplates.pl).
16
16
17+ * Modified wrapper scripts to make them more robust.
18+
17 * Modified wrapper scripts to make them more robust and portable.
19 * Modified wrapper scripts to make them more robust and portable.
18 To avoid code duplication and ensure consistency, wrappers are
20 To avoid code duplication and ensure consistency, wrappers are
19 generated via a templating system from templates in src/wrappers.
21 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
1+.so man1/pandoc.1
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
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
1+.so man1/pandoc.1
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
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
1+.so man1/pandoc.1
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
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
1+.so man1/pandoc.1
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
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"
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 [\fIoptions\fR] [\fB\-o\fR \fIoutput-file\fR]
5+\fBmarkdown2pdf\fR [\fIoptions\fR] [\fIinput-file\fR]...
6−[\fIinput-file\fR]... [\fB\-\-\fR] [\fIpandoc\-opts\fR]
7.SH DESCRIPTION
6.SH DESCRIPTION
8−\fBmarkdown2pdf\fR converts \fIinput\-file\fR (or text from STDIN) from
7+\fBmarkdown2pdf\fR converts \fIinput\-file\fR (or text from standard
9−markdown\-formatted plain text to PDF, using \fBpdflatex\fR. If no output
8+input) from markdown\-formatted plain text to PDF, using \fBpdflatex\fR.
10−filename is specified, the name of the output file is derived from the
9+If no output filename is specified, the name of the output file is
11−input file; thus, for example, if the input file is \fIhello.txt\fR,
10+derived from the input file; thus, for example, if the input file
12−the output file will be \fIhello.pdf\fR. If the input is read from STDIN
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−and no output filename is specified, the output file will be named
13+specified, the output file will be named \fIstdin.pdf\fR. If
14−\fIstdin.pdf\fR. If multiple input files are specified, they will be
14+multiple input files are specified, they will be concatenated before
15−concatenated before conversion, and the name of the output file will be
15+conversion, and the name of the output file will be derived from
16−derived from the first input file.
16+the first input file.
17.PP
17.PP
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
18−\fBmarkdown2pdf\fR is a wrapper for \fBpandoc\fR.
28+\fBmarkdown2pdf\fR is a wrapper around \fBmarkdown2latex\fR.
19.SH OPTIONS
29.SH OPTIONS
20.TP
30.TP
21−.B \-h
31+.B \-o FILE, \-\-output=FILE
22−Show usage message.
32+Write output to \fIFILE\fR.
23.TP
33.TP
24−.B \-o \fIoutput-file\fR
34+.B \-p, \-\-preserve-tabs
25−Specify name of output (PDF) file.
35+Preserve tabs instead of converting them to spaces.
26.TP
36.TP
27−.I pandoc\-opts
37+.B \-\-tab-stop=\fITABSTOP\fB
28−Any options appearing after \fIinput\-file\fR... on the command line
38+Specify tab stop (default is 4).
29−will be passed directly to \fBpandoc\fR. If no \fIinput-file\fR
39+.TP
30−is specified, these options must be preceded by ` \fB\-\-\fR '.
40+.B \-R, \-\-parse-raw
31−(In other cases, ` \fB\-\-\fR ' is optional.) See \fBpandoc\fR(1)
41+Parse untranslatable LaTeX environments as raw LaTeX,
32−for a list of options that may be used. Example:
42+instead of ignoring them.
33−.IP
43+.TP
34−markdown2pdf input.txt \-\- \-\-custom\-header=letterhead.tex
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.
35.SH "SEE ALSO"
67.SH "SEE ALSO"
36\fBpandoc\fR(1),
68\fBpandoc\fR(1),
37−\fBmarkdown2html\fR(1),
38−\fBhtml2markdown\fR(1),
39−\fBmarkdown2latex\fR(1),
40−\fBlatex2markdown\fR(1),
41\fBpdflatex\fR(1)
69\fBpdflatex\fR(1)
42.SH AUTHOR
70.SH AUTHOR
43John MacFarlane and Recai Oktas
71John 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"
2.SH NAME
2.SH NAME
3+pandoc, markdown2html, markdown2latex, markdown2rst, markdown2rtf,
4+markdown2s5, html2markdown2, latex2markdown, rst2markdown \- general
3−pandoc \- general markup converter
5+markup converter
4.SH SYNOPSIS
6.SH SYNOPSIS
5\fBpandoc\fR [\fIoptions\fR] [\fIinput\-file\fR]...
7\fBpandoc\fR [\fIoptions\fR] [\fIinput\-file\fR]...
6.SH DESCRIPTION
8.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
8read markdown and (subsets of) reStructuredText, HTML, and LaTeX, and
10read markdown and (subsets of) reStructuredText, HTML, and LaTeX, and
9it can write markdown, reStructuredText, HTML, LaTeX, RTF, and S5 HTML
11it can write markdown, reStructuredText, HTML, LaTeX, RTF, and S5 HTML
10slide shows.
12slide shows.
11.PP
13.PP
12−If no \fIinput\-file\fR is specified, input is read from STDIN. Otherwise,
14+If no \fIinput\-file\fR is specified, input is read from STDIN.
13−the \fIinput\-files\fR are concatenated (with a blank line between each)
15+Otherwise, the \fIinput\-files\fR are concatenated (with a blank
14−and used as input. Output goes to STDOUT. If you want output to a file,
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
15−use shell redirection:
18+shell redirection:
19+.IP
20+.B pandoc \-o output.html input.txt
16.IP
21.IP
17.B pandoc input.txt > output.html
22.B pandoc input.txt > output.html
18.PP
23.PP
@@ -25,6 +30,19 @@ formats can be specified using command\-line options. For example,
25converts \fIchap1.tex\fR from LaTeX to markdown\-formatted plain text.
30converts \fIchap1.tex\fR from LaTeX to markdown\-formatted plain text.
26See below for a detailed list of command\-line options.
31See below for a detailed list of command\-line options.
27.PP
32.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
28\fIPandoc\fR uses the UTF\-8 character encoding for both input and output.
46\fIPandoc\fR uses the UTF\-8 character encoding for both input and output.
29If your local character encoding is not UTF\-8, you should pipe input
47If your local character encoding is not UTF\-8, you should pipe input
30and output through \fBiconv\fR:
48and output through \fBiconv\fR:
@@ -33,61 +51,58 @@ and output through \fBiconv\fR:
33
51
34.SH OPTIONS
52.SH OPTIONS
35.TP
53.TP
36−.B \-v, \-\-version
54+.B \-f \fIFORMAT\fB, \-r \fIFORMAT\fB, \-\-from=\fIFORMAT\fB, \-\-read=\fIFORMAT\fB
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
43Specify input format.
55Specify input format.
44.I FORMAT
56.I FORMAT
45can be
57can be
46−.I native
58+.B native
47(native Haskell),
59(native Haskell),
48−.I markdown
60+.B markdown
49(markdown or plain text),
61(markdown or plain text),
50−.I rst
62+.B rst
51(reStructuredText),
63(reStructuredText),
52−.I html
64+.B html
53(HTML),
65(HTML),
54or
66or
55−.I latex
67+.B latex
56(LaTeX).
68(LaTeX).
57.TP
69.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
59Specify output format.
71Specify output format.
60.I FORMAT
72.I FORMAT
61can be
73can be
62−.I native
74+.B native
63(native Haskell),
75(native Haskell),
64−.I markdown
76+.B markdown
65(markdown or plain text),
77(markdown or plain text),
66−.I rst
78+.B rst
67(reStructuredText),
79(reStructuredText),
68−.I html
80+.B html
69(HTML),
81(HTML),
70−.I latex
82+.B latex
71(LaTeX),
83(LaTeX),
72−.I s5
84+.B s5
73(S5 HTML and javascript slide show),
85(S5 HTML and javascript slide show),
74or
86or
75−.I rtf
87+.B rtf
76(rich text format).
88(rich text format).
77.TP
89.TP
78.B \-s, \-\-standalone
90.B \-s, \-\-standalone
79Produce output with an appropriate header and footer (e.g. a
91Produce output with an appropriate header and footer (e.g. a
80standalone HTML, LaTeX, or RTF file, not a fragment).
92standalone HTML, LaTeX, or RTF file, not a fragment).
81.TP
93.TP
94+.B \-o FILE, \-\-output=FILE
95+Write output to \fIFILE\fR instead of STDOUT.
96+.TP
82.B \-p, \-\-preserve-tabs
97.B \-p, \-\-preserve-tabs
83Preserve tabs instead of converting them to spaces.
98Preserve tabs instead of converting them to spaces.
84.TP
99.TP
85−.B \-\-tab-stop=TABSTOP
100+.B \-\-tab-stop=\fITABSTOP\fB
86Specify tab stop (default is 4).
101Specify tab stop (default is 4).
87.TP
102.TP
88.B \-R, \-\-parse-raw
103.B \-R, \-\-parse-raw
89−Parse untranslatable HTML codes and LaTeX environments as raw HTML or
104+Parse untranslatable HTML codes and LaTeX environments as raw HTML
90−LaTeX, instead of ignoring them.
105+or LaTeX, instead of ignoring them.
91.TP
106.TP
92.B \-S, \-\-smartypants
107.B \-S, \-\-smartypants
93Use smart quotes, dashes, and ellipses in HTML output.
108Use smart quotes, dashes, and ellipses in HTML output.
@@ -99,41 +114,50 @@ Use ASCIIMathML to display embedded LaTeX math in HTML output.
99Make list items in S5 display incrementally (one by one).
114Make list items in S5 display incrementally (one by one).
100.TP
115.TP
101.B \-N, \-\-number-sections
116.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.)
103.TP
119.TP
104−.B \-c CSS, \-\-css=CSS
120+.B \-c \fICSS\fB, \-\-css=\fICSS\fB
105Link to a CSS style sheet.
121Link to a CSS style sheet.
106.I CSS
122.I CSS
107is the pathname of the style sheet.
123is the pathname of the style sheet.
108.TP
124.TP
109−.B \-H FILENAME, \-\-include-in-header=FILENAME
125+.B \-H \fIFILE\fB, \-\-include-in-header=\fIFILE\fB
110−Include contents of \fIFILENAME\fR at the end of the header. Implies
126+Include contents of \fIFILE\fR at the end of the header. Implies
111\fB\-s\fR.
127\fB\-s\fR.
112.TP
128.TP
113−.B \-B FILENAME, \-\-include-before-body=FILENAME
129+.B \-B \fIFILE\fB, \-\-include-before-body=\fIFILE\fB
114−Include contents of \fIFILENAME\fR at the beginning of the document body.
130+Include contents of \fIFILE\fR at the beginning of the document
131+body.
115.TP
132.TP
116−.B \-A FILENAME, \-\-include-after-body=FILENAME
133+.B \-A \fIFILE\fB, \-\-include-after-body=\fIFILE\fB
117−Include contents of \fIFILENAME\fR at the end of the document body.
134+Include contents of \fIFILE\fR at the end of the document body.
118.TP
135.TP
119−.B \-\-custom-header=FILENAME
136+.B \-C \fIFILE\fB, \-\-custom-header=\fIFILE\fB
120−Use contents of \fIFILENAME\fR
121−as the document header (overriding the default header, which can be
137+Use contents of \fIFILE\fR as the document header (overriding the
122−printed by using the \fB\-D\fR option). Implies
138+default header, which can be printed by using the \fB\-D\fR option).
123−\fB-s\fR.
139+Implies \fB-s\fR.
124.TP
140.TP
125−.B \-D FORMAT, \-\-print-default-header=FORMAT
141+.B \-D \fIFORMAT\fB, \-\-print-default-header=\fIFORMAT\fB
126−Print the default header for \fIFORMAT\fR
142+Print the default header for \fIFORMAT\fR (\fIhtml, s5, latex,
127−(\fIhtml, s5, latex, markdown, rst, rtf\fR).
143+markdown, rst, rtf\fR).
128.TP
144.TP
129−.B \-T STRING, \-\-title-prefix=STRING
145+.B \-T \fISTRING\fB, \-\-title-prefix=\fISTRING\fB
130Specify \fISTRING\fR as a prefix to the HTML window title.
146Specify \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.
131
158
132.SH "SEE ALSO"
159.SH "SEE ALSO"
133−\fBmarkdown2html\fR(1),
160+\fBweb2markdown\fR(1),
134−\fBhtml2markdown\fR(1),
135−\fBmarkdown2latex\fR(1),
136−\fBlatex2markdown\fR(1),
137\fBmarkdown2pdf\fR(1),
161\fBmarkdown2pdf\fR(1),
138\fBiconv\fR(1)
162\fBiconv\fR(1)
139
163
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,
45 defaultRTFHeader, defaultS5Header, defaultLaTeXHeader )
45 defaultRTFHeader, defaultS5Header, defaultLaTeXHeader )
46import Text.Pandoc.Definition
46import Text.Pandoc.Definition
47import Text.Pandoc.Shared
47import Text.Pandoc.Shared
48+import Text.Regex ( mkRegex, splitRegex )
48import System ( exitWith, getArgs, getProgName )
49import System ( exitWith, getArgs, getProgName )
49import System.Exit
50import System.Exit
50import System.Console.GetOpt
51import System.Console.GetOpt
@@ -57,6 +58,9 @@ import Control.Monad ( (>>=) )
57version :: String
58version :: String
58version = "0.3"
59version = "0.3"
59
60
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+
60-- | Association list of formats and readers.
64-- | Association list of formats and readers.
61readers :: [(String, ParserState -> String -> Pandoc)]
65readers :: [(String, ParserState -> String -> Pandoc)]
62readers = [("native" , readPandoc)
66readers = [("native" , readPandoc)
@@ -101,10 +105,13 @@ data Opt = Opt
101 , optCustomHeader :: String -- ^ Custom header to use, or "DEFAULT"
105 , optCustomHeader :: String -- ^ Custom header to use, or "DEFAULT"
102 , optDefaultHeader :: String -- ^ Default header
106 , optDefaultHeader :: String -- ^ Default header
103 , optTitlePrefix :: String -- ^ Optional prefix for HTML title
107 , optTitlePrefix :: String -- ^ Optional prefix for HTML title
108+ , optOutputFile :: String -- ^ Name of output file
104 , optNumberSections :: Bool -- ^ If @True@, number sections in LaTeX
109 , optNumberSections :: Bool -- ^ If @True@, number sections in LaTeX
105 , optIncremental :: Bool -- ^ If @True@, incremental lists in S5
110 , optIncremental :: Bool -- ^ If @True@, incremental lists in S5
106 , optSmart :: Bool -- ^ If @True@, use smart typography
111 , optSmart :: Bool -- ^ If @True@, use smart typography
107 , optASCIIMathML :: Bool -- ^ If @True@, use ASCIIMathML in HTML
112 , optASCIIMathML :: Bool -- ^ If @True@, use ASCIIMathML in HTML
113+ , optShowUsage :: Bool -- ^ If @True@, show usage message
114+ , optDebug :: Bool -- ^ If @True@, output debug messages
108 }
115 }
109
116
110-- | Defaults for command-line options.
117-- | Defaults for command-line options.
@@ -123,32 +130,20 @@ startOpt = Opt
123 , optCustomHeader = "DEFAULT"
130 , optCustomHeader = "DEFAULT"
124 , optDefaultHeader = defaultHtmlHeader
131 , optDefaultHeader = defaultHtmlHeader
125 , optTitlePrefix = ""
132 , optTitlePrefix = ""
133+ , optOutputFile = "" -- null for stdout
126 , optNumberSections = False
134 , optNumberSections = False
127 , optIncremental = False
135 , optIncremental = False
128 , optSmart = False
136 , optSmart = False
129 , optASCIIMathML = False
137 , optASCIIMathML = False
138+ , optShowUsage = False
139+ , optDebug = False
130 }
140 }
131
141
132-- | A list of functions, each transforming the options data structure in response
142-- | A list of functions, each transforming the options data structure in response
133-- to a command-line option.
143-- to a command-line option.
134−options :: [OptDescr (Opt -> IO Opt)]
144+allOptions :: [OptDescr (Opt -> IO Opt)]
135−options =
145+allOptions =
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"]
146+ [ Option "fr" ["from","read"]
152 (ReqArg
147 (ReqArg
153 (\arg opt -> case (lookup (map toLower arg) readers) of
148 (\arg opt -> case (lookup (map toLower arg) readers) of
154 Just reader -> return opt { optReader = reader }
149 Just reader -> return opt { optReader = reader }
@@ -172,6 +167,13 @@ options =
172 (\opt -> return opt { optStandalone = True }))
167 (\opt -> return opt { optStandalone = True }))
173 "Include needed header and footer on output"
168 "Include needed header and footer on output"
174
169
170+ , Option "o" ["output"]
171+ (ReqArg
172+ (\arg opt -> do
173+ return opt { optOutputFile = arg })
174+ "FILENAME")
175+ "Name of output file"
176+
175 , Option "p" ["preserve-tabs"]
177 , Option "p" ["preserve-tabs"]
176 (NoArg
178 (NoArg
177 (\opt -> return opt { optPreserveTabs = True }))
179 (\opt -> return opt { optPreserveTabs = True }))
@@ -241,7 +243,7 @@ options =
241 "FILENAME")
243 "FILENAME")
242 "File to include after document body"
244 "File to include after document body"
243
245
244− , Option "" ["custom-header"]
246+ , Option "C" ["custom-header"]
245 (ReqArg
247 (ReqArg
246 (\arg opt -> do
248 (\arg opt -> do
247 text <- readFile arg
249 text <- readFile arg
@@ -263,18 +265,87 @@ options =
263 let header = case (lookup arg writers) of
265 let header = case (lookup arg writers) of
264 Just (writer, head) -> head
266 Just (writer, head) -> head
265 Nothing -> error ("Unknown reader: " ++ arg)
267 Nothing -> error ("Unknown reader: " ++ arg)
266− hPutStrLn stdout header
268+ hPutStr stdout header
267 exitWith ExitSuccess)
269 exitWith ExitSuccess)
268 "FORMAT")
270 "FORMAT")
269 "Print default header for FORMAT"
271 "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"
270 ]
291 ]
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+
271main = do
318main = do
272
319
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+
273 args <- getArgs
335 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 ()
275
346
276 -- thread option data structure through all supplied option actions
347 -- thread option data structure through all supplied option actions
277− opts <- foldl (>>=) (return startOpt) actions
348+ opts <- foldl (>>=) (return defaultOpts) actions
278
349
279 let Opt { optPreserveTabs = preserveTabs
350 let Opt { optPreserveTabs = preserveTabs
280 , optTabStop = tabStop
351 , optTabStop = tabStop
@@ -289,12 +360,31 @@ main = do
289 , optCustomHeader = customHeader
360 , optCustomHeader = customHeader
290 , optDefaultHeader = defaultHeader
361 , optDefaultHeader = defaultHeader
291 , optTitlePrefix = titlePrefix
362 , optTitlePrefix = titlePrefix
363+ , optOutputFile = outputFile
292 , optNumberSections = numberSections
364 , optNumberSections = numberSections
293 , optIncremental = incremental
365 , optIncremental = incremental
294 , optSmart = smart
366 , optSmart = smart
295 , optASCIIMathML = asciiMathML
367 , optASCIIMathML = asciiMathML
368+ , optShowUsage = showUsage
369+ , optDebug = debug
296 } = opts
370 } = opts
297
371
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+
298 let writingS5 = (defaultHeader == defaultS5Header)
388 let writingS5 = (defaultHeader == defaultS5Header)
299 let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)
389 let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)
300 let addBlank str = str ++ "\n\n"
390 let addBlank str = str ++ "\n\n"
@@ -323,13 +413,13 @@ main = do
323 writerIncludeBefore = includeBefore,
413 writerIncludeBefore = includeBefore,
324 writerIncludeAfter = includeAfter }
414 writerIncludeAfter = includeAfter }
325
415
326− (readSources sources) >>= (putStr . encodeUTF8 . (writer writerOptions) .
416+ (readSources sources) >>= (hPutStr output . encodeUTF8 .
417+ (writer writerOptions) .
327 (reader startParserState) . filter .
418 (reader startParserState) . filter .
328− decodeUTF8 . (joinWithSep "\n"))
419+ decodeUTF8 . (joinWithSep "\n")) >> hClose output
329
420
330 where
421 where
331 readSources [] = mapM readSource ["-"]
422 readSources [] = mapM readSource ["-"]
332 readSources sources = mapM readSource sources
423 readSources sources = mapM readSource sources
333− readSource "-" = getContents
424+ readSource "-" = getContents
334 readSource source = readFile source
425 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=
8err () { echo "$*" | fold -s -w ${COLUMNS:-110} >&2; }
8err () { echo "$*" | fold -s -w ${COLUMNS:-110} >&2; }
9errn () { printf "$*" | fold -s -w ${COLUMNS:-110} >&2; }
9errn () { printf "$*" | fold -s -w ${COLUMNS:-110} >&2; }
10
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).
11# Portable which(1).
28pathfind () {
12pathfind () {
29 oldifs="$IFS"; IFS=':'
13 oldifs="$IFS"; IFS=':'
@@ -37,17 +21,6 @@ pathfind () {
37 return 1
21 return 1
38}
22}
39
23
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−
51for p in pandoc $REQUIRED; do
24for p in pandoc $REQUIRED; do
52 pathfind $p || {
25 pathfind $p || {
53 err "You need '$p' to use this program!"
26 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 @@
1#!/bin/sh -e
1#!/bin/sh -e
2−# converts markdown to latex, then uses latex to make a PDF
3
2
4−REQUIRED=pdflatex
3+REQUIRED="markdown2latex pdflatex"
5
4
6### common.sh
5### common.sh
7
6
8−outfile=
7+### tempdir.sh
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
8
20−### checkin.sh
9+texname=output
10+logfile=$THIS_TEMPDIR/log
21
11
22−if [ -z "$outfile" ]; then
12+if ! markdown2latex -s -d "$@" >$THIS_TEMPDIR/$texname.tex 2>$logfile; then
23− if [ -n "$1" ]; then
13+ [ -f $logfile ] && sed -e 's/markdown2latex/markdown2pdf/g' \
24− outfile="${1%.*}"
14+ -e '/^INPUT=/d' -e '/^OUTPUT=/d' $logfile >&2
25− else
15+ exit 1
26− outfile="stdin" # input is STDIN, since no argument given
27− fi
28fi
16fi
29−case "$outfile" in
30−*.*) ;; # skip appending extension if one is already present
31−*) outfile="${outfile%.*}.pdf";;
32−esac
33
17
34−### tempdir.sh
18+outfile="$(sed -ne 's/^OUTPUT=//p' $logfile)"
35−
19+IFS="$NEWLINE"
36−# We should use a filename without white spaces for pdflatex.
20+set -- $(sed -ne 's/^INPUT=//p' $logfile)
37−TEXNAME=$THIS
21+firstinfilebase="${1%.*}"
22+defaultdest="${firstinfilebase:-stdin}.pdf"
23+destname="${outfile:-$defaultdest}"
38
24
39−to_utf8 "$@" | runpandoc -w latex -s >$THIS_TEMPDIR/$TEXNAME.tex
40(
25(
41 cd $THIS_TEMPDIR
26 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
43 err "LaTeX errors:"
28 err "LaTeX errors:"
44− from_utf8 $TEXNAME.log | sed -ne '/^!/,/^ *$/p' >&2
29+ sed -ne '/^!/,/^ *$/p' $texname.log >&2
45− if grep -q "File \`ucs.sty' not found" $TEXNAME.log; then
30+ if grep -q "File \`ucs.sty' not found" $texname.log; then
46− err "Please install the 'unicode' package from ctan.org."
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/"
47 fi
37 fi
48 exit 1
38 exit 1
49 fi
39 fi
50−)
40+) || exit $?
51
41
52is_target_exists=
42is_target_exists=
53−if [ -f "$outfile" ]; then
43+if [ -f "$destname" ]; then
54 is_target_exists=1
44 is_target_exists=1
55− mv -f "$outfile" "$outfile~"
45+ mv "$destname" "$destname~"
56fi
46fi
57
47
58−mv -f $THIS_TEMPDIR/$TEXNAME.pdf "$outfile"
48+mv -f $THIS_TEMPDIR/$texname.pdf "$destname"
59
49
60−errn "Created '$outfile'"
50+errn "Created $destname"
61[ -z "$is_target_exists" ] || {
51[ -z "$is_target_exists" ] || {
62− errn " (previous file has been backed up as '$outfile~')"
52+ errn " (previous file has been backed up as $destname~)"
63}
53}
64err .
54err .
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