git.iko.soy/typeable/pandoc
on master help sign in
+ Removed the convenience symlinks (which don't work on Windows under
a1a30d6fiddlosopher
Makefile+3−16
@@ -26,8 +26,6 @@ EXECSBASE := $(shell sed -ne 's/^[Ee]xecutable:[[:space:]]*//p' $(CABAL).in)
26# Install targets
26# Install targets
27#-------------------------------------------------------------------------------
27#-------------------------------------------------------------------------------
28WRAPPERS := web2markdown markdown2pdf
28WRAPPERS := web2markdown markdown2pdf
29−SYMLINKS := markdown2html markdown2latex markdown2s5 markdown2rst \
30− markdown2rtf html2markdown latex2markdown rst2markdown
31# Add .exe extensions if we're running Windows/Cygwin.
29# Add .exe extensions if we're running Windows/Cygwin.
32EXTENSION := $(shell uname | tr '[:upper:]' '[:lower:]' | \
30EXTENSION := $(shell uname | tr '[:upper:]' '[:lower:]' | \
33 sed -ne 's/^cygwin.*$$/\.exe/p')
31 sed -ne 's/^cygwin.*$$/\.exe/p')
@@ -96,12 +94,6 @@ all: build-program
96templates: $(SRCDIR)/templates
94templates: $(SRCDIR)/templates
97 $(MAKE) -C $(SRCDIR)/templates
95 $(MAKE) -C $(SRCDIR)/templates
98
96
99−.PHONY: symlinks
100−cleanup_files+=$(SYMLINKS)
101−symlinks: $(SYMLINKS)
102−$(SYMLINKS): $(MAIN)
103− ln -sf ./$(MAIN) $@
104−
105define generate-shell-script
97define generate-shell-script
106echo "Generating $@..."; \
98echo "Generating $@..."; \
107awk ' \
99awk ' \
@@ -141,7 +133,7 @@ build: configure
141 $(BUILDCMD) build
133 $(BUILDCMD) build
142
134
143.PHONY: build-exec
135.PHONY: build-exec
144−build-exec: $(PROGS) $(SYMLINKS)
136+build-exec: $(PROGS)
145cleanup_files+=$(EXECS)
137cleanup_files+=$(EXECS)
146$(EXECS): build
138$(EXECS): build
147 for f in $@; do \
139 for f in $@; do \
@@ -201,9 +193,8 @@ install-exec: build-exec
201 fi; \
193 fi; \
202 $(INSTALL_PROGRAM) $$f $(BINPATH)/; \
194 $(INSTALL_PROGRAM) $$f $(BINPATH)/; \
203 done
195 done
204− cd $(BINPATH); for f in $(SYMLINKS); do ln -sf $(MAIN) $$f; done
205uninstall-exec:
196uninstall-exec:
206− -for f in $(notdir $(PROGS) $(SYMLINKS)); do rm -f $(BINPATH)/$$f; done ;
197+ -for f in $(notdir $(PROGS)); do rm -f $(BINPATH)/$$f; done ;
207
198
208# Program + user documents installation.
199# Program + user documents installation.
209.PHONY: install-program uninstall-program
200.PHONY: install-program uninstall-program
@@ -295,15 +286,11 @@ $(osx_dmg_name): $(osx_pkg_name)
295
286
296.PHONY: win-pkg
287.PHONY: win-pkg
297win_pkg_name:=$(RELNAME).zip
288win_pkg_name:=$(RELNAME).zip
298−win_docs:=COPYING.txt COPYRIGHT.txt BUGS.txt README-WINDOWS.txt README-WINDOWS.html
289+win_docs:=COPYING.txt COPYRIGHT.txt BUGS.txt README.txt README.html
299cleanup_files+=$(win_pkg_name) $(win_docs)
290cleanup_files+=$(win_pkg_name) $(win_docs)
300win-pkg: $(win_pkg_name)
291win-pkg: $(win_pkg_name)
301$(win_pkg_name): $(THIS).exe $(win_docs)
292$(win_pkg_name): $(THIS).exe $(win_docs)
302 zip -r $(win_pkg_name) $(THIS).exe $(win_docs)
293 zip -r $(win_pkg_name) $(THIS).exe $(win_docs)
303−cleanup_files+=README-WINDOWS
304−README-WINDOWS: README
305− sed -e '/^Requirements/,/^\[fancyvrb\]:/ d' \
306− -e '/^Character encodings/,/mysite.com$$/ d' $< > $@
307
294
308.PHONY: test test-markdown
295.PHONY: test test-markdown
309test: $(MAIN)
296test: $(MAIN)
README+64−75
@@ -36,14 +36,11 @@ Requirements
36============
36============
37
37
38The `pandoc` program itself does not depend on any external libraries
38The `pandoc` program itself does not depend on any external libraries
39−or programs. The convenience programs `markdown2html`, `markdown2latex`,
39+or programs.
40−`markdown2rst`, `markdown2rtf`, `markdown2s5`, `html2markdown`,
41−`latex2markdown`, and `rst2markdown` are implemented as symbolic links to
42−`pandoc`.
43
40
44The wrapper script `web2markdown` requires
41The wrapper script `web2markdown` requires
45
42
46− - `html2markdown` (included with Pandoc)
43+ - `pandoc` (which must be in the PATH)
47 - a POSIX-compliant shell (installed by default on all linux and unix
44 - a POSIX-compliant shell (installed by default on all linux and unix
48 systems, including Mac OS X, and in [Cygwin] for Windows),
45 systems, including Mac OS X, and in [Cygwin] for Windows),
49 - `HTML Tidy`
46 - `HTML Tidy`
@@ -56,7 +53,7 @@ The wrapper script `web2markdown` requires
56
53
57The wrapper script `markdown2pdf` requires
54The wrapper script `markdown2pdf` requires
58
55
59− - `markdown2latex` (included with Pandoc)
56+ - `pandoc` (which must be in the PATH)
60 - a POSIX-compliant shell
57 - a POSIX-compliant shell
61 - `pdflatex`, which should be part of any [LaTeX] distribution
58 - `pdflatex`, which should be part of any [LaTeX] distribution
62 - the [unicode] and [fancyvrb] LaTeX packages, which are included
59 - the [unicode] and [fancyvrb] LaTeX packages, which are included
@@ -80,47 +77,11 @@ Using Pandoc
80
77
81If you run `pandoc` without arguments, it will accept input from
78If you run `pandoc` without arguments, it will accept input from
82STDIN. If you run it with file names as arguments, it will take input
79STDIN. If you run it with file names as arguments, it will take input
83−from those files. It accepts several command-line options. For a
84−list, type
85−
86− pandoc -h
87−
88−The most important options specify the format of the source file and
89−the output. The default reader is markdown; the default writer is
90−HTML. So if you don't specify a reader or writer, `pandoc` will
91−convert markdown to HTML. For example,
92−
93− pandoc hello.txt
94−
95−will convert `hello.txt` from markdown to HTML. For other conversions,
96−you must specify a reader and/or a writer using the `-r` and `-w`
97−flags. To convert markdown to LaTeX, you would write:
98−
99− pandoc -w latex hello.txt
100−
101−To convert html to markdown:
102−
103− pandoc -r html -w markdown hello.txt
104−
105−Supported writers include `markdown`, `latex`, `html`, `rtf` (rich text
106−format), `rst` (reStructuredText), and `s5` (which produces an HTML
107−file that acts like powerpoint). Supported readers include `markdown`,
108−`html`, `latex`, and `rst`. Note that the `rst` reader only parses
109−a subset of reStructuredText syntax. For example, it doesn't handle
110−tables, definition lists, option lists, or footnotes. It handles only the
111−constructs expressible in unextended markdown. But for simple documents
112−it should be adequate. The `latex` and `html` readers are also limited
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
80+from those files. By default, `pandoc` writes its output to STDOUT.
118−write to a file, use the `-o` option or shell redirection:
81+If you want to write to a file, use the `-o` option:
119
82
120 pandoc -o hello.html hello.txt
83 pandoc -o hello.html hello.txt
121
84
122− pandoc hello.txt > hello.html
123−
124Note that you can specify multiple input files on the command line.
85Note that you can specify multiple input files on the command line.
125`pandoc` will concatenate them all (with blank lines between them)
86`pandoc` will concatenate them all (with blank lines between them)
126before parsing:
87before parsing:
@@ -131,6 +92,44 @@ before parsing:
131with a proper header, rather than a fragment. For more details on this
92with a proper header, rather than a fragment. For more details on this
132and many other command-line options, see below.)
93and many other command-line options, see below.)
133
94
95+The format of the input and output can be specified explicitly using
96+command-line options. The input format can be specified using the
97+`-r/--read` or `-f/--from` options, the output format using the
98+`-w/--write` or `-t/--to` options. Thus, to convert `hello.txt` from
99+markdown to LaTeX, you could type:
100+
101+ pandoc -f markdown -t latex hello.txt
102+
103+To convert `hello.html` from html to markdown:
104+
105+ pandoc -f html -t markdown hello.html
106+
107+Supported output formats include `markdown`, `latex`, `html`, `rtf`
108+(rich text format), `rst` (reStructuredText), and `s5` (which produces
109+an HTML file that acts like powerpoint). Supported input formats
110+include `markdown`, `html`, `latex`, and `rst`. Note that the `rst`
111+reader only parses a subset of reStructuredText syntax. For example,
112+it doesn't handle tables, definition lists, option lists, or footnotes.
113+It handles only the constructs expressible in unextended markdown.
114+But for simple documents it should be adequate. The `latex` and `html`
115+readers are also limited in what they can do. Because the `html`
116+reader is picky about the HTML it parses, it is recommended that you
117+pipe HTML through [HTML Tidy] before sending it to `pandoc`, or use the
118+`web2markdown` script described below.
119+
120+If you don't specify a reader or writer explicitly, `pandoc` will
121+try to determine the input and output format from the extensions of
122+the input and output filenames. Thus, for example,
123+
124+ pandoc -o hello.tex hello.txt
125+
126+will convert `hello.txt` from markdown to LaTeX. If no output file
127+is specified (so that output goes to STDOUT), or if the output file's
128+extension is unknown, the output format will default to HTML.
129+If no input file is specified (so that input comes from STDIN), or
130+if the input files' extensions are unknown, the input format will
131+be assumed to be markdown unless explicitly specified.
132+
134Character encodings
133Character encodings
135-------------------
134-------------------
136
135
@@ -150,31 +149,16 @@ The shell scripts (described below) automatically convert the input
150from the local encoding to UTF-8 before running them through `pandoc`,
149from the local encoding to UTF-8 before running them through `pandoc`,
151then convert the output back to the local encoding.
150then convert the output back to the local encoding.
152
151
153−Convenience programs and wrapper scripts
152+`markdown2pdf` and `web2markdown`
154−========================================
153+=================================
155−
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.)
167−
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:
171
154
172− markdown2latex -s sample.txt > sample.tex
155+Two shell scripts, `markdown2pdf` and `web2markdown`, are included in
173−
156+the standard Pandoc installation. (They are not included in the Windows
174−Two shell scripts have also been included:
157+binary package, as they require a POSIX shell, but they may be used
158+in Windows under Cygwin.)
175
159
1761. `markdown2pdf` produces a PDF file from markdown-formatted
1601. `markdown2pdf` produces a PDF file from markdown-formatted
177− text, using `markdown2latex` and `pdflatex`. The default
161+ text, using `pandoc` and `pdflatex`. The default
178 behavior of `markdown2pdf` is to create a file with the same
162 behavior of `markdown2pdf` is to create a file with the same
179 base name as the first argument and the extension `pdf`; thus,
163 base name as the first argument and the extension `pdf`; thus,
180 for example,
164 for example,
@@ -190,7 +174,7 @@ Two shell scripts have also been included:
190 If no input file is specified, input will be taken from STDIN.
174 If no input file is specified, input will be taken from STDIN.
191
175
1922. `web2markdown` grabs a web page from a file or URL and converts
1762. `web2markdown` grabs a web page from a file or URL and converts
193− it to markdown-formatted text, using `tidy` and `html2markdown`.
177+ it to markdown-formatted text, using `tidy` and `pandoc`.
194 Unless input is from STDIN, an attempt is made to determine the
178 Unless input is from STDIN, an attempt is made to determine the
195 character encoding of the page from the "Content-type" meta tag.
179 character encoding of the page from the "Content-type" meta tag.
196 If this is not present, UTF-8 is assumed. Alternatively, a character
180 If this is not present, UTF-8 is assumed. Alternatively, a character
@@ -207,9 +191,20 @@ Command-line options
207====================
191====================
208
192
209Various command-line options can be used to customize the output.
193Various command-line options can be used to customize the output.
210−For a complete list, type
211
194
212− pandoc --help
195+`-f`, `--from`, `-r`, or `--read` can be used to specify the input
196+format -- the format Pandoc will be converting *from*. Available
197+formats are `native`, `markdown`, `rst`, `html`, and `latex`.
198+
199+`-t`, `--to`, `-w`, or `--write` can be used to specify the output
200+format -- the format Pandoc will be converting *to*. Available formats
201+are `native`, `html`, `s5`, `latex`, `markdown`, `rst`, and `rtf`.
202+
203+`-s` or `--standalone` indicates that a standalone document is to be
204+produced (with appropriate headers and footers), rather than a fragment.
205+
206+`-o` or `--output` specifies the name of the output file. If no output
207+filename is given, output will be sent to STDOUT.
213
208
214`-p` or `--preserve-tabs` causes tabs in the source text to be
209`-p` or `--preserve-tabs` causes tabs in the source text to be
215preserved, rather than converted to spaces (the default).
210preserved, rather than converted to spaces (the default).
@@ -225,12 +220,6 @@ untranslatable HTML codes and LaTeX environments. (The LaTeX reader
225does pass through untranslatable LaTeX commands, even if `-R` is not
220does pass through untranslatable LaTeX commands, even if `-R` is not
226specified.)
221specified.)
227
222
228−`-s` or `--standalone` causes `pandoc` to produce a standalone file,
229−complete with appropriate document headers. By default, `pandoc`
230−produces a fragment.
231−
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
223`-C` or `--custom-header` can be used to specify a custom document
235header. To see the headers used by default, use the `-D` option:
224header. To see the headers used by default, use the `-D` option:
236for example, `pandoc -D html` prints the default HTML header.
225for example, `pandoc -D html` prints the default HTML header.
man/man1/html2markdown.1deleted−1
@@ -1 +0,0 @@
1−.so man1/pandoc.1
man/man1/latex2markdown.1deleted−1
@@ -1 +0,0 @@
1−.so man1/pandoc.1
man/man1/markdown2html.1deleted−1
@@ -1 +0,0 @@
1−.so man1/pandoc.1
man/man1/markdown2latex.1deleted−1
@@ -1 +0,0 @@
1−.so man1/pandoc.1
man/man1/markdown2pdf.1+11−16
@@ -6,14 +6,13 @@ markdown2pdf \- converts markdown-formatted text to PDF, using pdflatex
6.SH DESCRIPTION
6.SH DESCRIPTION
7\fBmarkdown2pdf\fR converts \fIinput\-file\fR (or text from standard
7\fBmarkdown2pdf\fR converts \fIinput\-file\fR (or text from standard
8input) from markdown\-formatted plain text to PDF, using \fBpdflatex\fR.
8input) from markdown\-formatted plain text to PDF, using \fBpdflatex\fR.
9−If no output filename is specified, the name of the output file is
9+If no output filename is specified (using the \fB\-o\fR option),
10−derived from the input file; thus, for example, if the input file
10+the name of the output file is derived from the input file; thus, for
11−is \fIhello.txt\fR, the output file will be \fIhello.pdf\fR. If
11+example, if the input file is \fIhello.txt\fR, the output file will be
12−the input is read from STDIN and no output filename is
12+\fIhello.pdf\fR. If the input is read from STDIN and no output filename
13−specified, the output file will be named \fIstdin.pdf\fR. If
13+is specified, the output file will be named \fIstdin.pdf\fR. If multiple
14−multiple input files are specified, they will be concatenated before
14+input files are specified, they will be concatenated before conversion,
15−conversion, and the name of the output file will be derived from
15+and the name of the output file will be derived from the first input file.
16−the first input file.
17.PP
16.PP
18Input is assumed to be in the UTF\-8 character encoding. If your
17Input is assumed to be in the UTF\-8 character encoding. If your
19local character encoding is not UTF\-8, you should pipe input and
18local character encoding is not UTF\-8, you should pipe input and
@@ -21,11 +20,11 @@ output through \fBiconv\fR:
21.IP
20.IP
22.B iconv \-t utf\-8 input.txt | pandoc | iconv \-f utf\-8
21.B iconv \-t utf\-8 input.txt | pandoc | iconv \-f utf\-8
23.PP
22.PP
24−\fBmarkdown2pdf\fR assumes that the 'unicode' package
23+\fBmarkdown2pdf\fR assumes that the 'unicode' and 'fancyvrb' packages
25−is in latex's search path. If this package is not included in your
24+are in latex's search path. If these packages are not included in your
26−latex setup, it can be obtained from <http://ctan.org>.
25+latex setup, they can be obtained from <http://ctan.org>.
27.PP
26.PP
28−\fBmarkdown2pdf\fR is a wrapper around \fBmarkdown2latex\fR.
27+\fBmarkdown2pdf\fR is a wrapper around \fBpandoc\fR.
29.SH OPTIONS
28.SH OPTIONS
30.TP
29.TP
31.B \-o FILE, \-\-output=FILE
30.B \-o FILE, \-\-output=FILE
@@ -37,10 +36,6 @@ Preserve tabs instead of converting them to spaces.
37.B \-\-tab-stop=\fITABSTOP\fB
36.B \-\-tab-stop=\fITABSTOP\fB
38Specify tab stop (default is 4).
37Specify tab stop (default is 4).
39.TP
38.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
39.B \-N, \-\-number-sections
45Number section headings in LaTeX output. (Default is not to number them.)
40Number section headings in LaTeX output. (Default is not to number them.)
46.TP
41.TP
man/man1/markdown2rst.1deleted−1
@@ -1 +0,0 @@
1−.so man1/pandoc.1
man/man1/markdown2rtf.1deleted−1
@@ -1 +0,0 @@
1−.so man1/pandoc.1
man/man1/markdown2s5.1deleted−1
@@ -1 +0,0 @@
1−.so man1/pandoc.1
man/man1/pandoc.1+21−29
@@ -1,8 +1,6 @@
1.TH PANDOC 1 "December 15, 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
5−markup converter
3+pandoc \- general markup converter
6.SH SYNOPSIS
4.SH SYNOPSIS
7\fBpandoc\fR [\fIoptions\fR] [\fIinput\-file\fR]...
5\fBpandoc\fR [\fIoptions\fR] [\fIinput\-file\fR]...
8.SH DESCRIPTION
6.SH DESCRIPTION
@@ -13,41 +11,37 @@ slide shows.
13.PP
11.PP
14If no \fIinput\-file\fR is specified, input is read from STDIN.
12If no \fIinput\-file\fR is specified, input is read from STDIN.
15Otherwise, the \fIinput\-files\fR are concatenated (with a blank
13Otherwise, the \fIinput\-files\fR are concatenated (with a blank
16−line between each) and used as input. Output goes to standard
14+line between each) and used as input. Output goes to STDOUT by
17−output. If you want output to a file, use the \fB\-o\fR option or
15+default. For output to a file, use the \fB\-o\fR option:
18−shell redirection:
19.IP
16.IP
20.B pandoc \-o output.html input.txt
17.B pandoc \-o output.html input.txt
21−.IP
22−.B pandoc input.txt > output.html
23.PP
18.PP
24−The default behavior of \fIPandoc\fR is to convert the input from
25−markdown\-formatted plain text to HTML. Different input and output
26−formats can be specified using command\-line options. For example,
19+The input and output formats may be specified using command-line options
20+(see \fBOPTIONS\fR, below, for details). If these formats are not
21+specified explicitly, \fIPandoc\fR will attempt to determine them
22+from the extensions of the input and output filenames. If input comes
23+from STDIN or from a file with an unknown extension, the input is assumed
24+to be markdown. If no output filename is specified using the \fB\-o\fR
25+option, or if a filename is specified but its extension is unknown,
26+the output will default to HTML. Thus, for example,
27.IP
27.IP
28−.B pandoc \-f latex \-t markdown chap1.tex > chap1.txt
28+.B pandoc -o chap1.tex chap1.txt
29.PP
29.PP
30−converts \fIchap1.tex\fR from LaTeX to markdown\-formatted plain text.
30+converts \fIchap1.txt\fR from markdown to LaTeX. And
31−See below for a detailed list of command\-line options.
31+.IP
32+.B pandoc README
32.PP
33.PP
33−For convenience, eight variant programs are available:
34+converts \fIREADME\fR from markdown to HTML.
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
35.PP
46\fIPandoc\fR uses the UTF\-8 character encoding for both input and output.
36\fIPandoc\fR uses the UTF\-8 character encoding for both input and output.
47If your local character encoding is not UTF\-8, you should pipe input
37If your local character encoding is not UTF\-8, you should pipe input
48and output through \fBiconv\fR:
38and output through \fBiconv\fR:
49.IP
39.IP
50.B iconv \-t utf\-8 input.txt | pandoc | iconv \-f utf\-8
40.B iconv \-t utf\-8 input.txt | pandoc | iconv \-f utf\-8
41+.PP
42+\fIPandoc\fR's HTML parser is not very forgiving. If your input is
43+HTML, consider running it through \fBtidy\fR(1) before passing it
44+to Pandoc. Or use \fBweb2markdown\fR(1), a wrapper around \fBpandoc\fR.
51
45
52.SH OPTIONS
46.SH OPTIONS
53.TP
47.TP
@@ -158,9 +152,7 @@ Show usage message.
158
152
159.SH "SEE ALSO"
153.SH "SEE ALSO"
160\fBweb2markdown\fR(1),
154\fBweb2markdown\fR(1),
161−\fBmarkdown2pdf\fR(1),
155+\fBmarkdown2pdf\fR(1).
162−\fBiconv\fR(1)
163−
164The
156The
165.I README
157.I README
166file distributed with Pandoc contains full documentation.
158file distributed with Pandoc contains full documentation.
man/man1/rst2markdown.1deleted−1
@@ -1 +0,0 @@
1−.so man1/pandoc.1
man/man1/web2markdown.1+1−2
@@ -16,7 +16,7 @@ option.
16from STDIN, UTF-8 is assumed. A character encoding may be specified
16from STDIN, UTF-8 is assumed. A character encoding may be specified
17explicitly using the \fB\-e\fR option.
17explicitly using the \fB\-e\fR option.
18.PP
18.PP
19−\fBweb2markdown\fR is a wrapper for \fBhtml2markdown\fR.
19+\fBweb2markdown\fR is a wrapper for \fBpandoc\fR.
20.SH OPTIONS
20.SH OPTIONS
21.TP
21.TP
22.B \-s, \-\-standalone
22.B \-s, \-\-standalone
@@ -76,7 +76,6 @@ web2markdown \-g 'wget \-\-user=foo \-\-password=bar' mysite.com
76
76
77.SH "SEE ALSO"
77.SH "SEE ALSO"
78\fBpandoc\fR(1),
78\fBpandoc\fR(1),
79−\fBhtml2markdown\fR(1),
80\fBiconv\fR(1)
79\fBiconv\fR(1)
81.SH AUTHOR
80.SH AUTHOR
82John MacFarlane and Recai Oktas
81John MacFarlane and Recai Oktas
src/Main.hs+82−75
@@ -45,7 +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 )
48+import Text.Regex ( mkRegex, matchRegex )
49import System ( exitWith, getArgs, getProgName )
49import System ( exitWith, getArgs, getProgName )
50import System.Exit
50import System.Exit
51import System.Console.GetOpt
51import System.Console.GetOpt
@@ -94,8 +94,8 @@ data Opt = Opt
94 { optPreserveTabs :: Bool -- ^ If @False@, convert tabs to spaces
94 { optPreserveTabs :: Bool -- ^ If @False@, convert tabs to spaces
95 , optTabStop :: Int -- ^ Number of spaces per tab
95 , optTabStop :: Int -- ^ Number of spaces per tab
96 , optStandalone :: Bool -- ^ If @True@, include header, footer
96 , optStandalone :: Bool -- ^ If @True@, include header, footer
97− , optReader :: ParserState -> String -> Pandoc -- ^ Read format
97+ , optReader :: String -- ^ Reader format
98− , optWriter :: WriterOptions -> Pandoc -> String -- ^ Write fmt
98+ , optWriter :: String -- ^ Writer format
99 , optParseRaw :: Bool -- ^ If @True@, parse unconvertable
99 , optParseRaw :: Bool -- ^ If @True@, parse unconvertable
100 -- HTML and TeX
100 -- HTML and TeX
101 , optCSS :: String -- ^ CSS file to link to
101 , optCSS :: String -- ^ CSS file to link to
@@ -103,64 +103,55 @@ data Opt = Opt
103 , optIncludeBeforeBody :: String -- ^ File to include at top of body
103 , optIncludeBeforeBody :: String -- ^ File to include at top of body
104 , optIncludeAfterBody :: String -- ^ File to include at end of body
104 , optIncludeAfterBody :: String -- ^ File to include at end of body
105 , optCustomHeader :: String -- ^ Custom header to use, or "DEFAULT"
105 , optCustomHeader :: String -- ^ Custom header to use, or "DEFAULT"
106− , optDefaultHeader :: String -- ^ Default header
107 , optTitlePrefix :: String -- ^ Optional prefix for HTML title
106 , optTitlePrefix :: String -- ^ Optional prefix for HTML title
108 , optOutputFile :: String -- ^ Name of output file
107 , optOutputFile :: String -- ^ Name of output file
109 , optNumberSections :: Bool -- ^ If @True@, number sections in LaTeX
108 , optNumberSections :: Bool -- ^ If @True@, number sections in LaTeX
110 , optIncremental :: Bool -- ^ If @True@, incremental lists in S5
109 , optIncremental :: Bool -- ^ If @True@, incremental lists in S5
111 , optSmart :: Bool -- ^ If @True@, use smart typography
110 , optSmart :: Bool -- ^ If @True@, use smart typography
112 , optASCIIMathML :: Bool -- ^ If @True@, use ASCIIMathML in HTML
111 , optASCIIMathML :: Bool -- ^ If @True@, use ASCIIMathML in HTML
113− , optShowUsage :: Bool -- ^ If @True@, show usage message
114 , optDebug :: Bool -- ^ If @True@, output debug messages
112 , optDebug :: Bool -- ^ If @True@, output debug messages
115 }
113 }
116
114
117-- | Defaults for command-line options.
115-- | Defaults for command-line options.
118−startOpt :: Opt
116+defaultOpts :: Opt
119−startOpt = Opt
117+defaultOpts = Opt
120 { optPreserveTabs = False
118 { optPreserveTabs = False
121 , optTabStop = 4
119 , optTabStop = 4
122 , optStandalone = False
120 , optStandalone = False
123− , optReader = readMarkdown
121+ , optReader = "" -- null for default reader
124− , optWriter = writeHtml
122+ , optWriter = "" -- null for default writer
125 , optParseRaw = False
123 , optParseRaw = False
126 , optCSS = ""
124 , optCSS = ""
127 , optIncludeInHeader = ""
125 , optIncludeInHeader = ""
128 , optIncludeBeforeBody = ""
126 , optIncludeBeforeBody = ""
129 , optIncludeAfterBody = ""
127 , optIncludeAfterBody = ""
130 , optCustomHeader = "DEFAULT"
128 , optCustomHeader = "DEFAULT"
131− , optDefaultHeader = defaultHtmlHeader
132 , optTitlePrefix = ""
129 , optTitlePrefix = ""
133 , optOutputFile = "" -- null for stdout
130 , optOutputFile = "" -- null for stdout
134 , optNumberSections = False
131 , optNumberSections = False
135 , optIncremental = False
132 , optIncremental = False
136 , optSmart = False
133 , optSmart = False
137 , optASCIIMathML = False
134 , optASCIIMathML = False
138− , optShowUsage = False
139 , optDebug = False
135 , optDebug = False
140 }
136 }
141
137
142−-- | A list of functions, each transforming the options data structure in response
138+-- | A list of functions, each transforming the options data structure
143−-- to a command-line option.
139+-- in response to a command-line option.
144−allOptions :: [OptDescr (Opt -> IO Opt)]
140+options :: [OptDescr (Opt -> IO Opt)]
145−allOptions =
141+options =
146 [ Option "fr" ["from","read"]
142 [ Option "fr" ["from","read"]
147 (ReqArg
143 (ReqArg
148− (\arg opt -> case (lookup (map toLower arg) readers) of
149− Just reader -> return opt { optReader = reader }
144+ (\arg opt -> return opt { optReader = map toLower arg })
150− Nothing -> error ("Unknown reader: " ++ arg) )
151 "FORMAT")
145 "FORMAT")
152− ("Source format (" ++
146+ ("Input format (" ++ (joinWithSep ", " (map fst readers)) ++
153− (concatMap (\(name, fn) -> " " ++ name) readers) ++ " )")
147+ ")")
154
148
155 , Option "tw" ["to","write"]
149 , Option "tw" ["to","write"]
156 (ReqArg
150 (ReqArg
157− (\arg opt -> case (lookup (map toLower arg) writers) of
158− Just (writer, defaultHeader) ->
159− return opt { optWriter = writer,
151+ (\arg opt -> return opt { optWriter = map toLower arg })
160− optDefaultHeader = defaultHeader }
161− Nothing -> error ("Unknown writer: " ++ arg) )
162 "FORMAT")
152 "FORMAT")
163− ("Output format (" ++ (concatMap (\(name, fn) -> " " ++ name) writers) ++ " )")
153+ ("Output format (" ++ (joinWithSep ", " (map fst writers)) ++
154+ ")")
164
155
165 , Option "s" ["standalone"]
156 , Option "s" ["standalone"]
166 (NoArg
157 (NoArg
@@ -169,8 +160,7 @@ allOptions =
169
160
170 , Option "o" ["output"]
161 , Option "o" ["output"]
171 (ReqArg
162 (ReqArg
172− (\arg opt -> do
173− return opt { optOutputFile = arg })
163+ (\arg opt -> return opt { optOutputFile = arg })
174 "FILENAME")
164 "FILENAME")
175 "Name of output file"
165 "Name of output file"
176
166
@@ -286,57 +276,66 @@ allOptions =
286
276
287 , Option "h" ["help"]
277 , Option "h" ["help"]
288 (NoArg
278 (NoArg
289− (\opt -> return opt { optShowUsage = True }))
279+ (\_ -> do
280+ prg <- getProgName
281+ hPutStr stderr (reformatUsageInfo $
282+ usageInfo (prg ++ " [OPTIONS] [FILES]") options)
283+ exitWith $ ExitFailure 2))
290 "Show help"
284 "Show help"
291 ]
285 ]
292
286
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
287-- Reformat usage message so it doesn't wrap illegibly
288+reformatUsageInfo :: String -> String
314reformatUsageInfo = gsub " *--" " --" .
289reformatUsageInfo = gsub " *--" " --" .
315 gsub "(-[A-Za-z0-9]) *--" "\\1, --" .
290 gsub "(-[A-Za-z0-9]) *--" "\\1, --" .
316 gsub " *([^- ])" "\n\t\\1"
291 gsub " *([^- ])" "\n\t\\1"
317
292
318−main = do
293+-- Determine default reader based on source file extensions
319−
294+defaultReaderName :: [String] -> String
320− name <- getProgName
295+defaultReaderName [] = "markdown"
321− let (from, to) = parseProgName name
296+defaultReaderName (x:xs) =
297+ let x' = map toLower x in
298+ case (matchRegex (mkRegex ".*\\.(.*)") x') of
299+ Nothing -> defaultReaderName xs -- no extension
300+ Just ["xhtml"] -> "html"
301+ Just ["html"] -> "html"
302+ Just ["htm"] -> "html"
303+ Just ["tex"] -> "latex"
304+ Just ["latex"] -> "latex"
305+ Just ["ltx"] -> "latex"
306+ Just ["rst"] -> "rst"
307+ Just ["native"] -> "native"
308+ Just _ -> "markdown"
309+
310+-- Determine default writer based on output file extension
311+defaultWriterName :: String -> String
312+defaultWriterName "" = "html" -- no output file
313+defaultWriterName x =
314+ let x' = map toLower x in
315+ case (matchRegex (mkRegex ".*\\.(.*)") x') of
316+ Nothing -> "markdown" -- no extension
317+ Just [""] -> "markdown" -- empty extension
318+ Just ["tex"] -> "latex"
319+ Just ["latex"] -> "latex"
320+ Just ["ltx"] -> "latex"
321+ Just ["rtf"] -> "rtf"
322+ Just ["rst"] -> "rst"
323+ Just ["s5"] -> "s5"
324+ Just ["native"] -> "native"
325+ Just ["txt"] -> "markdown"
326+ Just ["text"] -> "markdown"
327+ Just ["md"] -> "markdown"
328+ Just ["markdown"] -> "markdown"
329+ Just _ -> "html"
322
330
323− let irrelevantOptions = if not ('2' `elem` name)
331+main = do
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
332
335 args <- getArgs
333 args <- getArgs
336 let (actions, sources, errors) = getOpt Permute options args
334 let (actions, sources, errors) = getOpt Permute options args
337
335
338 if (not (null errors))
336 if (not (null errors))
339 then do
337 then do
338+ name <- getProgName
340 mapM (\e -> hPutStrLn stderr e) errors
339 mapM (\e -> hPutStrLn stderr e) errors
341 hPutStrLn stderr (reformatUsageInfo $
340 hPutStrLn stderr (reformatUsageInfo $
342 usageInfo (name ++ " [OPTIONS] [FILES]") options)
341 usageInfo (name ++ " [OPTIONS] [FILES]") options)
@@ -350,30 +349,39 @@ main = do
350 let Opt { optPreserveTabs = preserveTabs
349 let Opt { optPreserveTabs = preserveTabs
351 , optTabStop = tabStop
350 , optTabStop = tabStop
352 , optStandalone = standalone
351 , optStandalone = standalone
353− , optReader = reader
352+ , optReader = readerName
354− , optWriter = writer
353+ , optWriter = writerName
355 , optParseRaw = parseRaw
354 , optParseRaw = parseRaw
356 , optCSS = css
355 , optCSS = css
357 , optIncludeInHeader = includeHeader
356 , optIncludeInHeader = includeHeader
358 , optIncludeBeforeBody = includeBefore
357 , optIncludeBeforeBody = includeBefore
359 , optIncludeAfterBody = includeAfter
358 , optIncludeAfterBody = includeAfter
360 , optCustomHeader = customHeader
359 , optCustomHeader = customHeader
361− , optDefaultHeader = defaultHeader
362 , optTitlePrefix = titlePrefix
360 , optTitlePrefix = titlePrefix
363 , optOutputFile = outputFile
361 , optOutputFile = outputFile
364 , optNumberSections = numberSections
362 , optNumberSections = numberSections
365 , optIncremental = incremental
363 , optIncremental = incremental
366 , optSmart = smart
364 , optSmart = smart
367 , optASCIIMathML = asciiMathML
365 , optASCIIMathML = asciiMathML
368− , optShowUsage = showUsage
369 , optDebug = debug
366 , optDebug = debug
370 } = opts
367 } = opts
371
368
372− if showUsage
369+ -- assign reader and writer based on options and filenames
373− then do
370+ let readerName' = if null readerName
374− hPutStr stderr (reformatUsageInfo $ usageInfo (name ++ " [OPTIONS] [FILES]") options)
371+ then defaultReaderName sources
375− exitWith $ ExitFailure 2
372+ else readerName
373+
374+ let writerName' = if null writerName
375+ then defaultWriterName outputFile
376+ else writerName
377+
378+ reader <- case (lookup readerName' readers) of
376− else return ()
379+ Just r -> return r
380+ Nothing -> error ("Unknown reader: " ++ readerName')
381+
382+ (writer, defaultHeader) <- case (lookup writerName' writers) of
383+ Just (w,h) -> return (w, h)
384+ Nothing -> error ("Unknown writer: " ++ writerName')
377
385
378 output <- if ((null outputFile) || debug)
386 output <- if ((null outputFile) || debug)
379 then return stdout
387 then return stdout
@@ -385,7 +393,6 @@ main = do
385 hPutStr stderr $ concatMap (\s -> "INPUT=" ++ s ++ "\n") sources
393 hPutStr stderr $ concatMap (\s -> "INPUT=" ++ s ++ "\n") sources
386 else return ()
394 else return ()
387
395
388− let writingS5 = (defaultHeader == defaultS5Header)
389 let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)
396 let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)
390 let addBlank str = str ++ "\n\n"
397 let addBlank str = str ++ "\n\n"
391 let removeCRs str = filter (/= '\r') str -- remove DOS-style line endings
398 let removeCRs str = filter (/= '\r') str -- remove DOS-style line endings
@@ -407,7 +414,7 @@ main = do
407 writerTitlePrefix = titlePrefix,
414 writerTitlePrefix = titlePrefix,
408 writerSmart = smart,
415 writerSmart = smart,
409 writerTabStop = tabStop,
416 writerTabStop = tabStop,
410− writerS5 = writingS5,
417+ writerS5 = (writerName=="s5"),
411 writerIncremental = incremental,
418 writerIncremental = incremental,
412 writerNumberSections = numberSections,
419 writerNumberSections = numberSections,
413 writerIncludeBefore = includeBefore,
420 writerIncludeBefore = includeBefore,
src/wrappers/markdown2pdf.in+7−4
@@ -1,6 +1,6 @@
1#!/bin/sh -e
1#!/bin/sh -e
2
2
3−REQUIRED="markdown2latex pdflatex"
3+REQUIRED="pdflatex"
4
4
5### common.sh
5### common.sh
6
6
@@ -9,9 +9,12 @@ REQUIRED="markdown2latex pdflatex"
9texname=output
9texname=output
10logfile=$THIS_TEMPDIR/log
10logfile=$THIS_TEMPDIR/log
11
11
12−if ! markdown2latex -s -d "$@" >$THIS_TEMPDIR/$texname.tex 2>$logfile; then
12+if ! pandoc -s -d -r markdown -w latex "$@" >$THIS_TEMPDIR/$texname.tex \
13+2>$logfile; then
13− [ -f $logfile ] && sed -e 's/markdown2latex/markdown2pdf/g' \
14+ [ -f $logfile ] && sed -e 's/^pandoc/markdown2pdf/g' \
14− -e '/^INPUT=/d' -e '/^OUTPUT=/d' $logfile >&2
15+ -e '/^INPUT=/d' -e '/^OUTPUT=/d' \
16+ -e '/^[[:space:]]*\(-f\|-t\|-s\|-R\|-S\|-m\|-i\|-c\|-T\|-D\|-d\)/,/./d'\
17+ -e 's/(implies -s)//g' $logfile >&2
15 exit 1
18 exit 1
16fi
19fi
17
20
src/wrappers/web2markdown.in+9−6
@@ -2,7 +2,7 @@
2# converts HTML from a URL, file, or stdin to markdown
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
3# uses an available program to fetch URL and tidy to normalize it first
4
4
5−REQUIRED="tidy html2markdown"
5+REQUIRED="tidy"
6
6
7### common.sh
7### common.sh
8
8
@@ -72,14 +72,16 @@ grabber=
72while [ $# -gt 0 ]; do
72while [ $# -gt 0 ]; do
73 case "$1" in
73 case "$1" in
74 -h|--help)
74 -h|--help)
75− html2markdown -h 2>&1 | sed -e 's/html2markdown/web2markdown/' 1>&2
75+ pandoc -h 2>&1 | sed -e 's/pandoc/web2markdown/' \
76+ -e '/^[[:space:]]*\(-f\|-t\|-S\|-N\|-m\|-i\|-c\|-T\|-D\|-d\)/,/./d'\
77+ 1>&2
76 err " -e ENCODING, --encoding=ENCODING"
78 err " -e ENCODING, --encoding=ENCODING"
77 err " Specify character encoding of input"
79 err " Specify character encoding of input"
78 err " -g COMMAND, --grabber=COMMAND"
80 err " -g COMMAND, --grabber=COMMAND"
79 err " Specify command to be used to grab contents of URL"
81 err " Specify command to be used to grab contents of URL"
80 exit 0 ;;
82 exit 0 ;;
81 -v|--version)
83 -v|--version)
82− html2markdown -v
84+ pandoc -v 2>&1 | sed -e 's/pandoc/web2markdown/' 1>&2
83 exit 0 ;;
85 exit 0 ;;
84 -e)
86 -e)
85 shift
87 shift
@@ -112,7 +114,7 @@ while [ $# -gt 0 ]; do
112 shift
114 shift
113done
115done
114
116
115−# Unpack options. Now "$@" will hold the html2markdown options.
117+# Unpack options. Now "$@" will hold the pandoc options.
116oldifs="$IFS"; IFS="$NEWLINE"; set -- $options; IFS="$oldifs"
118oldifs="$IFS"; IFS="$NEWLINE"; set -- $options; IFS="$oldifs"
117
119
118inurl=
120inurl=
@@ -162,10 +164,11 @@ else # assume UTF-8
162fi
164fi
163
165
164if [ -z "$argument" ]; then
166if [ -z "$argument" ]; then
165− tidy -utf8 2>/dev/null | html2markdown "$@"
167+ tidy -utf8 2>/dev/null | pandoc -r html -w markdown "$@"
166else
168else
167 if [ -f "$argument" ]; then
169 if [ -f "$argument" ]; then
168− to_utf8 "$argument" | tidy -utf8 2>/dev/null | html2markdown "$@"
170+ to_utf8 "$argument" |
171+ tidy -utf8 2>/dev/null | pandoc -r html -w markdown "$@"
169 else
172 else
170 err "File '$argument' not found."
173 err "File '$argument' not found."
171 exit 1
174 exit 1