2006-12-20 20:54:23 +00:00
|
|
|
{-
|
2007-07-07 22:51:55 +00:00
|
|
|
Copyright (C) 2006-7 John MacFarlane <jgm@berkeley.edu>
|
2006-12-20 20:54:23 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
-}
|
|
|
|
|
2006-12-20 06:50:14 +00:00
|
|
|
{- |
|
|
|
|
Module : Text.Pandoc.Readers.LaTeX
|
2007-07-07 22:51:55 +00:00
|
|
|
Copyright : Copyright (C) 2006-7 John MacFarlane
|
2006-12-20 06:50:14 +00:00
|
|
|
License : GNU GPL, version 2 or above
|
|
|
|
|
2007-07-07 22:51:55 +00:00
|
|
|
Maintainer : John MacFarlane <jgm@berkeley.edu>
|
2006-12-20 20:20:10 +00:00
|
|
|
Stability : alpha
|
2006-12-20 06:50:14 +00:00
|
|
|
Portability : portable
|
|
|
|
|
|
|
|
Conversion of LaTeX to 'Pandoc' document.
|
|
|
|
-}
|
2006-10-17 14:22:29 +00:00
|
|
|
module Text.Pandoc.Readers.LaTeX (
|
|
|
|
readLaTeX,
|
|
|
|
rawLaTeXInline,
|
|
|
|
rawLaTeXEnvironment
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Text.ParserCombinators.Parsec
|
2007-07-09 03:39:25 +00:00
|
|
|
import Text.Pandoc.ParserCombinators
|
2006-10-17 14:22:29 +00:00
|
|
|
import Text.Pandoc.Definition
|
|
|
|
import Text.Pandoc.Shared
|
Extensive changes stemming from a rethinking of the Pandoc data
structure. Key and Note blocks have been removed. Link and image URLs
are now stored directly in Link and Image inlines, and note blocks
are stored in Note inlines. This requires changes in both parsers
and writers. Markdown and RST parsers need to extract data from key
and note blocks and insert them into the relevant inline elements.
Other parsers can be simplified, since there is no longer any need to
construct separate key and note blocks. Markdown, RST, and HTML writers
need to construct lists of notes; Markdown and RST writers need to
construct lists of link references (when the --reference-links option
is specified); and the RST writer needs to construct a list of image
substitution references. All writers have been rewritten to use the
State monad when state is required. This rewrite yields a small speed
boost and considerably cleaner code.
* Text/Pandoc/Definition.hs:
+ blocks: removed Key and Note
+ inlines: removed NoteRef, added Note
+ modified Target: there is no longer a 'Ref' target; all targets
are explicit URL, title pairs
* Text/Pandoc/Shared.hs:
+ Added 'Reference', 'isNoteBlock', 'isKeyBlock', 'isLineClump',
used in some of the readers.
+ Removed 'generateReference', 'keyTable', 'replaceReferenceLinks',
'replaceRefLinksBlockList', along with some auxiliary functions
used only by them. These are no longer needed, since
reference links are resolved in the Markdown and RST readers.
+ Moved 'inTags', 'selfClosingTag', 'inTagsSimple', and 'inTagsIndented'
to the Docbook writer, since that is now the only module that uses
them.
+ Changed name of 'escapeSGMLString' to 'escapeStringForXML'
+ Added KeyTable and NoteTable types
+ Removed fields from ParserState; 'stateKeyBlocks', 'stateKeysUsed',
'stateNoteBlocks', 'stateNoteIdentifiers', 'stateInlineLinks'.
Added 'stateKeys' and 'stateNotes'.
+ Added clause for Note to 'prettyBlock'.
+ Added 'writerNotes', 'writerReferenceLinks' fields to WriterOptions.
* Text/Pandoc/Entities.hs: Renamed 'escapeSGMLChar' and
'escapeSGMLString' to 'escapeCharForXML' and 'escapeStringForXML'
* Text/ParserCombinators/Pandoc.hs: Added lineClump parser: parses a raw
line block up to and including following blank lines.
* Main.hs: Replaced --inline-links with --reference-links.
* README:
+ Documented --reference-links and removed description of --inline-links.
+ Added note that footnotes may occur anywhere in the document, but must
be at the outer level, not embedded in block elements.
* man/man1/pandoc.1, man/man1/html2markdown.1: Removed --inline-links
option, added --reference-links option
* Markdown and RST readers:
+ Rewrote to fit new Pandoc definition. Since there are no longer
Note or Key blocks, all note and key blocks are parsed on a first pass
through the document. Once tables of notes and keys have been constructed,
the remaining parts of the document are reassembled and parsed.
+ Refactored link parsers.
* LaTeX and HTML readers: Rewrote to fit new Pandoc definition. Since
there are no longer Note or Key blocks, notes and references can be
parsed in a single pass through the document.
* RST, Markdown, and HTML writers: Rewrote using state monad new Pandoc
and definition. State is used to hold lists of references footnotes to
and be printed at the end of the document.
* RTF and LaTeX writers: Rewrote using new Pandoc definition. (Because
of the different treatment of footnotes, the "notes" parameter is no
longer needed in the block and inline conversion functions.)
* Docbook writer:
+ Moved the functions 'attributeList', 'inTags', 'selfClosingTag',
'inTagsSimple', 'inTagsIndented' from Text/Pandoc/Shared, since
they are now used only by the Docbook writer.
+ Rewrote using new Pandoc definition. (Because of the different
treatment of footnotes, the "notes" parameter is no longer needed
in the block and inline conversion functions.)
* Updated test suite
* Throughout: old haskell98 module names replaced by hierarchical module
names, e.g. List by Data.List.
* debian/control: Include libghc6-xhtml-dev instead of libghc6-html-dev
in "Build-Depends."
* cabalize:
+ Remove haskell98 from BASE_DEPENDS (since now the new hierarchical
module names are being used throughout)
+ Added mtl to BASE_DEPENDS (needed for state monad)
+ Removed html from GHC66_DEPENDS (not needed since xhtml is now used)
git-svn-id: https://pandoc.googlecode.com/svn/trunk@580 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-04-10 01:56:50 +00:00
|
|
|
import Data.Maybe ( fromMaybe )
|
|
|
|
import Data.Char ( chr )
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
-- | Parse LaTeX from string and return 'Pandoc' document.
|
|
|
|
readLaTeX :: ParserState -- ^ Parser state, including options for parser
|
|
|
|
-> String -- ^ String to parse
|
|
|
|
-> Pandoc
|
|
|
|
readLaTeX = readWith parseLaTeX
|
|
|
|
|
|
|
|
-- for testing
|
|
|
|
testString = testStringWith parseLaTeX
|
|
|
|
|
|
|
|
-- characters with special meaning
|
2007-01-06 09:54:58 +00:00
|
|
|
specialChars = "\\$%&^&_~#{}\n \t|<>'\"-"
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- utility functions
|
|
|
|
--
|
|
|
|
|
|
|
|
-- | Returns text between brackets and its matching pair.
|
2006-11-26 07:01:37 +00:00
|
|
|
bracketedText openB closeB = try (do
|
|
|
|
char openB
|
|
|
|
result <- many (choice [ oneOfStrings [ ['\\', openB], ['\\', closeB] ],
|
|
|
|
count 1 (noneOf [openB, closeB]),
|
|
|
|
bracketedText openB closeB ])
|
|
|
|
char closeB
|
|
|
|
return ([openB] ++ (concat result) ++ [closeB]))
|
2006-10-17 14:22:29 +00:00
|
|
|
|
2006-12-17 18:41:26 +00:00
|
|
|
-- | Returns an option or argument of a LaTeX command.
|
2006-11-26 07:01:37 +00:00
|
|
|
optOrArg = choice [ (bracketedText '{' '}'), (bracketedText '[' ']') ]
|
2006-10-17 14:22:29 +00:00
|
|
|
|
2006-12-17 18:41:26 +00:00
|
|
|
-- | True if the string begins with '{'.
|
2006-11-26 07:08:46 +00:00
|
|
|
isArg ('{':rest) = True
|
|
|
|
isArg other = False
|
|
|
|
|
2006-12-17 18:41:26 +00:00
|
|
|
-- | Returns list of options and arguments of a LaTeX command.
|
2006-11-26 07:01:37 +00:00
|
|
|
commandArgs = many optOrArg
|
|
|
|
|
2006-12-17 18:41:26 +00:00
|
|
|
-- | Parses LaTeX command, returns (name, star, list of options or arguments).
|
2006-10-17 14:22:29 +00:00
|
|
|
command = try (do
|
|
|
|
char '\\'
|
|
|
|
name <- many1 alphaNum
|
|
|
|
star <- option "" (string "*") -- some commands have starred versions
|
|
|
|
args <- commandArgs
|
2006-11-26 07:01:37 +00:00
|
|
|
return (name, star, args))
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
begin name = try (do
|
|
|
|
string "\\begin{"
|
|
|
|
string name
|
|
|
|
char '}'
|
|
|
|
option [] commandArgs
|
|
|
|
spaces
|
|
|
|
return name)
|
|
|
|
|
|
|
|
end name = try (do
|
|
|
|
string "\\end{"
|
|
|
|
string name
|
|
|
|
char '}'
|
|
|
|
spaces
|
|
|
|
return name)
|
|
|
|
|
2006-12-20 06:50:14 +00:00
|
|
|
-- | Returns a list of block elements containing the contents of an
|
|
|
|
-- environment.
|
2006-10-17 14:22:29 +00:00
|
|
|
environment name = try (do
|
|
|
|
begin name
|
|
|
|
spaces
|
|
|
|
contents <- manyTill block (end name)
|
|
|
|
return contents)
|
|
|
|
|
|
|
|
anyEnvironment = try (do
|
|
|
|
string "\\begin{"
|
|
|
|
name <- many alphaNum
|
|
|
|
star <- option "" (string "*") -- some environments have starred variants
|
|
|
|
char '}'
|
|
|
|
option [] commandArgs
|
|
|
|
spaces
|
|
|
|
contents <- manyTill block (end (name ++ star))
|
|
|
|
return (BlockQuote contents))
|
|
|
|
|
|
|
|
--
|
|
|
|
-- parsing documents
|
|
|
|
--
|
|
|
|
|
2006-12-17 18:41:26 +00:00
|
|
|
-- | Process LaTeX preamble, extracting metadata.
|
2007-01-06 09:54:58 +00:00
|
|
|
processLaTeXPreamble = try (do
|
2006-12-20 06:50:14 +00:00
|
|
|
manyTill (choice [bibliographic, comment, unknownCommand, nullBlock])
|
|
|
|
(try (string "\\begin{document}"))
|
2007-01-06 09:54:58 +00:00
|
|
|
spaces)
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
-- | Parse LaTeX and return 'Pandoc'.
|
|
|
|
parseLaTeX = do
|
2006-12-20 06:50:14 +00:00
|
|
|
option () processLaTeXPreamble -- preamble might not be present (fragment)
|
2006-10-17 14:22:29 +00:00
|
|
|
blocks <- parseBlocks
|
|
|
|
spaces
|
2007-02-12 17:14:11 +00:00
|
|
|
option "" (try (string "\\end{document}")) -- might not be present (in fragment)
|
2006-10-17 14:22:29 +00:00
|
|
|
spaces
|
|
|
|
eof
|
|
|
|
state <- getState
|
|
|
|
let blocks' = filter (/= Null) blocks
|
2006-11-26 07:01:37 +00:00
|
|
|
let title' = stateTitle state
|
|
|
|
let authors' = stateAuthors state
|
|
|
|
let date' = stateDate state
|
Extensive changes stemming from a rethinking of the Pandoc data
structure. Key and Note blocks have been removed. Link and image URLs
are now stored directly in Link and Image inlines, and note blocks
are stored in Note inlines. This requires changes in both parsers
and writers. Markdown and RST parsers need to extract data from key
and note blocks and insert them into the relevant inline elements.
Other parsers can be simplified, since there is no longer any need to
construct separate key and note blocks. Markdown, RST, and HTML writers
need to construct lists of notes; Markdown and RST writers need to
construct lists of link references (when the --reference-links option
is specified); and the RST writer needs to construct a list of image
substitution references. All writers have been rewritten to use the
State monad when state is required. This rewrite yields a small speed
boost and considerably cleaner code.
* Text/Pandoc/Definition.hs:
+ blocks: removed Key and Note
+ inlines: removed NoteRef, added Note
+ modified Target: there is no longer a 'Ref' target; all targets
are explicit URL, title pairs
* Text/Pandoc/Shared.hs:
+ Added 'Reference', 'isNoteBlock', 'isKeyBlock', 'isLineClump',
used in some of the readers.
+ Removed 'generateReference', 'keyTable', 'replaceReferenceLinks',
'replaceRefLinksBlockList', along with some auxiliary functions
used only by them. These are no longer needed, since
reference links are resolved in the Markdown and RST readers.
+ Moved 'inTags', 'selfClosingTag', 'inTagsSimple', and 'inTagsIndented'
to the Docbook writer, since that is now the only module that uses
them.
+ Changed name of 'escapeSGMLString' to 'escapeStringForXML'
+ Added KeyTable and NoteTable types
+ Removed fields from ParserState; 'stateKeyBlocks', 'stateKeysUsed',
'stateNoteBlocks', 'stateNoteIdentifiers', 'stateInlineLinks'.
Added 'stateKeys' and 'stateNotes'.
+ Added clause for Note to 'prettyBlock'.
+ Added 'writerNotes', 'writerReferenceLinks' fields to WriterOptions.
* Text/Pandoc/Entities.hs: Renamed 'escapeSGMLChar' and
'escapeSGMLString' to 'escapeCharForXML' and 'escapeStringForXML'
* Text/ParserCombinators/Pandoc.hs: Added lineClump parser: parses a raw
line block up to and including following blank lines.
* Main.hs: Replaced --inline-links with --reference-links.
* README:
+ Documented --reference-links and removed description of --inline-links.
+ Added note that footnotes may occur anywhere in the document, but must
be at the outer level, not embedded in block elements.
* man/man1/pandoc.1, man/man1/html2markdown.1: Removed --inline-links
option, added --reference-links option
* Markdown and RST readers:
+ Rewrote to fit new Pandoc definition. Since there are no longer
Note or Key blocks, all note and key blocks are parsed on a first pass
through the document. Once tables of notes and keys have been constructed,
the remaining parts of the document are reassembled and parsed.
+ Refactored link parsers.
* LaTeX and HTML readers: Rewrote to fit new Pandoc definition. Since
there are no longer Note or Key blocks, notes and references can be
parsed in a single pass through the document.
* RST, Markdown, and HTML writers: Rewrote using state monad new Pandoc
and definition. State is used to hold lists of references footnotes to
and be printed at the end of the document.
* RTF and LaTeX writers: Rewrote using new Pandoc definition. (Because
of the different treatment of footnotes, the "notes" parameter is no
longer needed in the block and inline conversion functions.)
* Docbook writer:
+ Moved the functions 'attributeList', 'inTags', 'selfClosingTag',
'inTagsSimple', 'inTagsIndented' from Text/Pandoc/Shared, since
they are now used only by the Docbook writer.
+ Rewrote using new Pandoc definition. (Because of the different
treatment of footnotes, the "notes" parameter is no longer needed
in the block and inline conversion functions.)
* Updated test suite
* Throughout: old haskell98 module names replaced by hierarchical module
names, e.g. List by Data.List.
* debian/control: Include libghc6-xhtml-dev instead of libghc6-html-dev
in "Build-Depends."
* cabalize:
+ Remove haskell98 from BASE_DEPENDS (since now the new hierarchical
module names are being used throughout)
+ Added mtl to BASE_DEPENDS (needed for state monad)
+ Removed html from GHC66_DEPENDS (not needed since xhtml is now used)
git-svn-id: https://pandoc.googlecode.com/svn/trunk@580 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-04-10 01:56:50 +00:00
|
|
|
return (Pandoc (Meta title' authors' date') blocks')
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- parsing blocks
|
|
|
|
--
|
|
|
|
|
|
|
|
parseBlocks = do
|
|
|
|
spaces
|
|
|
|
result <- many block
|
|
|
|
return result
|
|
|
|
|
2006-12-20 06:50:14 +00:00
|
|
|
block = choice [ hrule, codeBlock, header, list, blockQuote, mathBlock,
|
|
|
|
comment, bibliographic, para, specialEnvironment,
|
|
|
|
itemBlock, unknownEnvironment, unknownCommand ] <?>
|
|
|
|
"block"
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- header blocks
|
|
|
|
--
|
|
|
|
|
|
|
|
header = choice (map headerLevel (enumFromTo 1 5)) <?> "header"
|
|
|
|
|
|
|
|
headerLevel n = try (do
|
|
|
|
let subs = concat $ replicate (n - 1) "sub"
|
|
|
|
string ("\\" ++ subs ++ "section")
|
|
|
|
option ' ' (char '*')
|
|
|
|
char '{'
|
|
|
|
title <- manyTill inline (char '}')
|
|
|
|
spaces
|
|
|
|
return (Header n (normalizeSpaces title)))
|
|
|
|
|
|
|
|
--
|
|
|
|
-- hrule block
|
|
|
|
--
|
|
|
|
|
|
|
|
hrule = try (do
|
2006-12-20 06:50:14 +00:00
|
|
|
oneOfStrings [ "\\begin{center}\\rule{3in}{0.4pt}\\end{center}\n\n",
|
|
|
|
"\\newpage" ]
|
2006-10-17 14:22:29 +00:00
|
|
|
spaces
|
|
|
|
return HorizontalRule)
|
|
|
|
|
|
|
|
--
|
|
|
|
-- code blocks
|
|
|
|
--
|
|
|
|
|
|
|
|
codeBlock = try (do
|
2006-12-20 06:50:14 +00:00
|
|
|
string "\\begin{verbatim}" -- don't use begin function because it
|
|
|
|
-- gobbles whitespace
|
|
|
|
option "" blanklines -- we want to gobble blank lines, but not
|
|
|
|
-- leading space
|
2006-10-17 14:22:29 +00:00
|
|
|
contents <- manyTill anyChar (try (string "\\end{verbatim}"))
|
|
|
|
spaces
|
|
|
|
return (CodeBlock (stripTrailingNewlines contents)))
|
|
|
|
|
|
|
|
--
|
|
|
|
-- block quotes
|
|
|
|
--
|
|
|
|
|
|
|
|
blockQuote = choice [ blockQuote1, blockQuote2 ] <?> "blockquote"
|
|
|
|
|
|
|
|
blockQuote1 = try (do
|
|
|
|
blocks <- environment "quote"
|
|
|
|
spaces
|
|
|
|
return (BlockQuote blocks))
|
|
|
|
|
|
|
|
blockQuote2 = try (do
|
|
|
|
blocks <- environment "quotation"
|
|
|
|
spaces
|
|
|
|
return (BlockQuote blocks))
|
|
|
|
|
|
|
|
--
|
|
|
|
-- math block
|
|
|
|
--
|
|
|
|
|
|
|
|
mathBlock = mathBlockWith (begin "equation") (end "equation") <|>
|
|
|
|
mathBlockWith (begin "displaymath") (end "displaymath") <|>
|
|
|
|
mathBlockWith (string "\\[") (string "\\]") <?> "math block"
|
|
|
|
|
|
|
|
mathBlockWith start end = try (do
|
|
|
|
start
|
|
|
|
spaces
|
|
|
|
result <- manyTill anyChar end
|
|
|
|
spaces
|
|
|
|
return (BlockQuote [Para [TeX ("$" ++ result ++ "$")]]))
|
|
|
|
|
|
|
|
--
|
|
|
|
-- list blocks
|
|
|
|
--
|
|
|
|
|
|
|
|
list = bulletList <|> orderedList <?> "list"
|
|
|
|
|
|
|
|
listItem = try (do
|
2006-11-26 07:01:37 +00:00
|
|
|
("item", _, _) <- command
|
2006-10-17 14:22:29 +00:00
|
|
|
spaces
|
|
|
|
state <- getState
|
|
|
|
let oldParserContext = stateParserContext state
|
|
|
|
updateState (\state -> state {stateParserContext = ListItemState})
|
|
|
|
blocks <- many block
|
|
|
|
updateState (\state -> state {stateParserContext = oldParserContext})
|
|
|
|
return blocks)
|
|
|
|
|
|
|
|
orderedList = try (do
|
|
|
|
begin "enumerate"
|
|
|
|
spaces
|
|
|
|
items <- many listItem
|
|
|
|
end "enumerate"
|
|
|
|
spaces
|
|
|
|
return (OrderedList items))
|
|
|
|
|
|
|
|
bulletList = try (do
|
|
|
|
begin "itemize"
|
|
|
|
spaces
|
|
|
|
items <- many listItem
|
|
|
|
end "itemize"
|
|
|
|
spaces
|
|
|
|
return (BulletList items))
|
|
|
|
|
|
|
|
--
|
|
|
|
-- paragraph block
|
|
|
|
--
|
|
|
|
|
|
|
|
para = try (do
|
|
|
|
result <- many1 inline
|
|
|
|
spaces
|
|
|
|
return (Para (normalizeSpaces result)))
|
|
|
|
|
|
|
|
--
|
|
|
|
-- title authors date
|
|
|
|
--
|
|
|
|
|
|
|
|
bibliographic = choice [ maketitle, title, authors, date ]
|
|
|
|
|
|
|
|
maketitle = try (do
|
|
|
|
string "\\maketitle"
|
|
|
|
spaces
|
|
|
|
return Null)
|
|
|
|
|
|
|
|
title = try (do
|
|
|
|
string "\\title{"
|
|
|
|
tit <- manyTill inline (char '}')
|
|
|
|
spaces
|
|
|
|
updateState (\state -> state { stateTitle = tit })
|
|
|
|
return Null)
|
|
|
|
|
|
|
|
authors = try (do
|
|
|
|
string "\\author{"
|
|
|
|
authors <- manyTill anyChar (char '}')
|
|
|
|
spaces
|
2006-12-20 06:50:14 +00:00
|
|
|
let authors' = map removeLeadingTrailingSpace $ lines $
|
2007-01-22 22:52:39 +00:00
|
|
|
substitute "\\\\" "\n" authors
|
2006-10-17 14:22:29 +00:00
|
|
|
updateState (\state -> state { stateAuthors = authors' })
|
|
|
|
return Null)
|
|
|
|
|
|
|
|
date = try (do
|
|
|
|
string "\\date{"
|
|
|
|
date' <- manyTill anyChar (char '}')
|
|
|
|
spaces
|
|
|
|
updateState (\state -> state { stateDate = date' })
|
|
|
|
return Null)
|
|
|
|
|
|
|
|
--
|
|
|
|
-- item block
|
|
|
|
-- for use in unknown environments that aren't being parsed as raw latex
|
|
|
|
--
|
|
|
|
|
|
|
|
-- this forces items to be parsed in different blocks
|
|
|
|
itemBlock = try (do
|
2006-11-26 07:01:37 +00:00
|
|
|
("item", _, args) <- command
|
2006-10-17 14:22:29 +00:00
|
|
|
state <- getState
|
2006-12-20 06:50:14 +00:00
|
|
|
if (stateParserContext state == ListItemState)
|
|
|
|
then fail "item should be handled by list block"
|
|
|
|
else if null args
|
|
|
|
then return Null
|
|
|
|
else return (Plain [Str (stripFirstAndLast (head args))]))
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- raw LaTeX
|
|
|
|
--
|
|
|
|
|
|
|
|
specialEnvironment = do -- these are always parsed as raw
|
2007-02-15 01:10:15 +00:00
|
|
|
lookAhead (choice (map (\name -> begin name) ["tabular", "figure",
|
2006-12-20 06:50:14 +00:00
|
|
|
"tabbing", "eqnarry", "picture", "table", "verse", "theorem"]))
|
2006-10-17 14:22:29 +00:00
|
|
|
rawLaTeXEnvironment
|
|
|
|
|
2006-12-17 18:41:26 +00:00
|
|
|
-- | Parse any LaTeX environment and return a Para block containing
|
2006-10-17 14:22:29 +00:00
|
|
|
-- the whole literal environment as raw TeX.
|
|
|
|
rawLaTeXEnvironment :: GenParser Char st Block
|
|
|
|
rawLaTeXEnvironment = try (do
|
|
|
|
string "\\begin"
|
|
|
|
char '{'
|
|
|
|
name <- many1 alphaNum
|
|
|
|
star <- option "" (string "*") -- for starred variants
|
|
|
|
let name' = name ++ star
|
|
|
|
char '}'
|
|
|
|
args <- option [] commandArgs
|
2006-11-26 07:01:37 +00:00
|
|
|
let argStr = concat args
|
2006-10-17 14:22:29 +00:00
|
|
|
contents <- manyTill (choice [(many1 (noneOf "\\")),
|
2006-12-20 06:50:14 +00:00
|
|
|
(do
|
|
|
|
(Para [TeX str]) <- rawLaTeXEnvironment
|
|
|
|
return str),
|
|
|
|
string "\\" ])
|
|
|
|
(end name')
|
2006-10-17 14:22:29 +00:00
|
|
|
spaces
|
2006-11-26 07:01:37 +00:00
|
|
|
return (Para [TeX ("\\begin{" ++ name' ++ "}" ++ argStr ++
|
2006-12-20 06:50:14 +00:00
|
|
|
(concat contents) ++ "\\end{" ++ name' ++ "}")]))
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
unknownEnvironment = try (do
|
|
|
|
state <- getState
|
2006-12-20 06:50:14 +00:00
|
|
|
result <- if stateParseRaw state -- check whether we should include raw TeX
|
|
|
|
then rawLaTeXEnvironment -- if so, get whole raw environment
|
|
|
|
else anyEnvironment -- otherwise just the contents
|
2006-10-17 14:22:29 +00:00
|
|
|
return result)
|
|
|
|
|
|
|
|
unknownCommand = try (do
|
|
|
|
notFollowedBy' (string "\\end{itemize}")
|
|
|
|
notFollowedBy' (string "\\end{enumerate}")
|
|
|
|
notFollowedBy' (string "\\end{document}")
|
2006-11-26 07:01:37 +00:00
|
|
|
(name, star, args) <- command
|
2006-10-17 14:22:29 +00:00
|
|
|
spaces
|
2006-11-26 07:01:37 +00:00
|
|
|
let argStr = concat args
|
2006-10-17 14:22:29 +00:00
|
|
|
state <- getState
|
2006-12-20 06:50:14 +00:00
|
|
|
if (name == "item") && ((stateParserContext state) == ListItemState)
|
|
|
|
then fail "should not be parsed as raw"
|
|
|
|
else string ""
|
|
|
|
if stateParseRaw state
|
|
|
|
then return (Plain [TeX ("\\" ++ name ++ star ++ argStr)])
|
|
|
|
else return (Plain [Str (joinWithSep " " args)]))
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
-- latex comment
|
|
|
|
comment = try (do
|
|
|
|
char '%'
|
|
|
|
result <- manyTill anyChar newline
|
|
|
|
spaces
|
|
|
|
return Null)
|
|
|
|
|
|
|
|
--
|
|
|
|
-- inline
|
|
|
|
--
|
|
|
|
|
2007-07-22 05:14:43 +00:00
|
|
|
inline = choice [ strong, emph, strikeout, ref, lab, code, linebreak, spacer,
|
|
|
|
math, ellipses, emDash, enDash, hyphen, quoted, apostrophe,
|
2006-12-20 06:50:14 +00:00
|
|
|
accentedChar, specialChar, specialInline, escapedChar,
|
|
|
|
unescapedChar, str, endline, whitespace ] <?> "inline"
|
2006-10-17 14:22:29 +00:00
|
|
|
|
2007-01-06 09:54:58 +00:00
|
|
|
specialInline = choice [ link, image, footnote, rawLaTeXInline ]
|
|
|
|
<?> "link, raw TeX, note, or image"
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
accentedChar = normalAccentedChar <|> specialAccentedChar
|
|
|
|
|
|
|
|
normalAccentedChar = try (do
|
|
|
|
char '\\'
|
|
|
|
accent <- oneOf "'`^\"~"
|
|
|
|
character <- choice [ between (char '{') (char '}') anyChar, anyChar ]
|
|
|
|
let table = fromMaybe [] $ lookup character accentTable
|
|
|
|
let result = case lookup accent table of
|
|
|
|
Just num -> chr num
|
|
|
|
Nothing -> '?'
|
|
|
|
return (Str [result]))
|
|
|
|
|
|
|
|
-- an association list of letters and association list of accents
|
|
|
|
-- and decimal character numbers.
|
|
|
|
accentTable =
|
|
|
|
[ ('A', [('`', 192), ('\'', 193), ('^', 194), ('~', 195), ('"', 196)]),
|
|
|
|
('E', [('`', 200), ('\'', 201), ('^', 202), ('"', 203)]),
|
|
|
|
('I', [('`', 204), ('\'', 205), ('^', 206), ('"', 207)]),
|
|
|
|
('N', [('~', 209)]),
|
|
|
|
('O', [('`', 210), ('\'', 211), ('^', 212), ('~', 213), ('"', 214)]),
|
|
|
|
('U', [('`', 217), ('\'', 218), ('^', 219), ('"', 220)]),
|
|
|
|
('a', [('`', 224), ('\'', 225), ('^', 227), ('"', 228)]),
|
|
|
|
('e', [('`', 232), ('\'', 233), ('^', 234), ('"', 235)]),
|
|
|
|
('i', [('`', 236), ('\'', 237), ('^', 238), ('"', 239)]),
|
|
|
|
('n', [('~', 241)]),
|
|
|
|
('o', [('`', 242), ('\'', 243), ('^', 244), ('~', 245), ('"', 246)]),
|
|
|
|
('u', [('`', 249), ('\'', 250), ('^', 251), ('"', 252)]) ]
|
|
|
|
|
2006-12-20 06:50:14 +00:00
|
|
|
specialAccentedChar = choice [ ccedil, aring, iuml, szlig, aelig,
|
|
|
|
oslash, pound, euro, copyright, sect ]
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
ccedil = try (do
|
|
|
|
char '\\'
|
2007-02-12 17:18:20 +00:00
|
|
|
letter <- oneOfStrings ["cc", "cC"]
|
2006-10-17 14:22:29 +00:00
|
|
|
let num = if letter == "cc" then 231 else 199
|
|
|
|
return (Str [chr num]))
|
|
|
|
|
|
|
|
aring = try (do
|
|
|
|
char '\\'
|
2007-02-12 17:18:20 +00:00
|
|
|
letter <- oneOfStrings ["aa", "AA"]
|
2006-10-17 14:22:29 +00:00
|
|
|
let num = if letter == "aa" then 229 else 197
|
|
|
|
return (Str [chr num]))
|
|
|
|
|
|
|
|
iuml = try (do
|
|
|
|
string "\\\""
|
2007-02-12 17:18:20 +00:00
|
|
|
oneOfStrings ["\\i", "{\\i}"]
|
2006-10-17 14:22:29 +00:00
|
|
|
return (Str [chr 239]))
|
|
|
|
|
|
|
|
icirc = try (do
|
|
|
|
string "\\^"
|
2007-02-12 17:18:20 +00:00
|
|
|
oneOfStrings ["\\i", "{\\i}"]
|
2006-10-17 14:22:29 +00:00
|
|
|
return (Str [chr 238]))
|
|
|
|
|
|
|
|
szlig = try (do
|
|
|
|
string "\\ss"
|
|
|
|
return (Str [chr 223]))
|
|
|
|
|
|
|
|
oslash = try (do
|
|
|
|
char '\\'
|
|
|
|
letter <- choice [char 'o', char 'O']
|
|
|
|
let num = if letter == 'o' then 248 else 216
|
|
|
|
return (Str [chr num]))
|
|
|
|
|
|
|
|
aelig = try (do
|
|
|
|
char '\\'
|
2007-02-12 17:18:20 +00:00
|
|
|
letter <- oneOfStrings ["ae", "AE"]
|
2006-10-17 14:22:29 +00:00
|
|
|
let num = if letter == "ae" then 230 else 198
|
|
|
|
return (Str [chr num]))
|
|
|
|
|
|
|
|
pound = try (do
|
|
|
|
string "\\pounds"
|
|
|
|
return (Str [chr 163]))
|
|
|
|
|
|
|
|
euro = try (do
|
|
|
|
string "\\euro"
|
|
|
|
return (Str [chr 8364]))
|
|
|
|
|
|
|
|
copyright = try (do
|
|
|
|
string "\\copyright"
|
|
|
|
return (Str [chr 169]))
|
|
|
|
|
|
|
|
sect = try (do
|
|
|
|
string "\\S"
|
|
|
|
return (Str [chr 167]))
|
|
|
|
|
2006-11-27 06:51:03 +00:00
|
|
|
escapedChar = do
|
2007-07-22 18:26:10 +00:00
|
|
|
result <- escaped (oneOf " $%&_#{}\n")
|
2006-11-27 06:51:03 +00:00
|
|
|
return (if result == Str "\n" then Str " " else result)
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
unescapedChar = do -- ignore standalone, nonescaped special characters
|
|
|
|
oneOf "$^&_#{}|<>"
|
|
|
|
return (Str "")
|
|
|
|
|
2007-07-22 18:26:10 +00:00
|
|
|
specialChar = choice [ backslash, tilde, caret, bar, lt, gt ]
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
backslash = try (do
|
|
|
|
string "\\textbackslash"
|
|
|
|
return (Str "\\"))
|
|
|
|
|
2007-07-22 18:26:10 +00:00
|
|
|
tilde = try (do
|
|
|
|
string "\\ensuremath{\\sim}"
|
|
|
|
return (Str "~"))
|
|
|
|
|
|
|
|
caret = try (do
|
|
|
|
string "\\^{}"
|
|
|
|
return (Str "^"))
|
|
|
|
|
2006-10-17 14:22:29 +00:00
|
|
|
bar = try (do
|
|
|
|
string "\\textbar"
|
|
|
|
return (Str "\\"))
|
|
|
|
|
|
|
|
lt = try (do
|
|
|
|
string "\\textless"
|
|
|
|
return (Str "<"))
|
|
|
|
|
|
|
|
gt = try (do
|
|
|
|
string "\\textgreater"
|
|
|
|
return (Str ">"))
|
|
|
|
|
|
|
|
code = try (do
|
|
|
|
string "\\verb"
|
|
|
|
marker <- anyChar
|
|
|
|
result <- manyTill anyChar (char marker)
|
|
|
|
let result' = removeLeadingTrailingSpace result
|
|
|
|
return (Code result'))
|
|
|
|
|
|
|
|
emph = try (do
|
|
|
|
oneOfStrings [ "\\emph{", "\\textit{" ]
|
|
|
|
result <- manyTill inline (char '}')
|
|
|
|
return (Emph result))
|
|
|
|
|
2007-07-22 05:14:43 +00:00
|
|
|
strikeout = try $ do
|
|
|
|
string "\\sout{"
|
|
|
|
result <- manyTill inline (char '}')
|
|
|
|
return (Strikeout result)
|
|
|
|
|
2007-01-06 09:54:58 +00:00
|
|
|
apostrophe = do
|
|
|
|
char '\''
|
|
|
|
return Apostrophe
|
|
|
|
|
|
|
|
quoted = do
|
|
|
|
doubleQuoted <|> singleQuoted
|
|
|
|
|
|
|
|
singleQuoted = try (do
|
|
|
|
result <- enclosed singleQuoteStart singleQuoteEnd inline
|
|
|
|
return $ Quoted SingleQuote $ normalizeSpaces result)
|
|
|
|
|
|
|
|
doubleQuoted = try (do
|
|
|
|
result <- enclosed doubleQuoteStart doubleQuoteEnd inline
|
|
|
|
return $ Quoted DoubleQuote $ normalizeSpaces result)
|
|
|
|
|
|
|
|
singleQuoteStart = char '`'
|
|
|
|
|
|
|
|
singleQuoteEnd = try (do
|
|
|
|
char '\''
|
|
|
|
notFollowedBy alphaNum)
|
|
|
|
|
|
|
|
doubleQuoteStart = try (string "``")
|
|
|
|
|
|
|
|
doubleQuoteEnd = try (string "''")
|
|
|
|
|
|
|
|
ellipses = try (do
|
|
|
|
string "\\ldots"
|
2007-02-12 17:14:11 +00:00
|
|
|
option "" (try (string "{}"))
|
2007-01-06 09:54:58 +00:00
|
|
|
return Ellipses)
|
|
|
|
|
|
|
|
enDash = try (do
|
|
|
|
string "--"
|
|
|
|
notFollowedBy (char '-')
|
|
|
|
return EnDash)
|
|
|
|
|
|
|
|
emDash = try (do
|
|
|
|
string "---"
|
|
|
|
return EmDash)
|
|
|
|
|
|
|
|
hyphen = do
|
|
|
|
char '-'
|
|
|
|
return (Str "-")
|
|
|
|
|
2006-10-17 14:22:29 +00:00
|
|
|
lab = try (do
|
|
|
|
string "\\label{"
|
|
|
|
result <- manyTill anyChar (char '}')
|
|
|
|
return (Str ("(" ++ result ++ ")")))
|
|
|
|
|
|
|
|
ref = try (do
|
|
|
|
string "\\ref{"
|
|
|
|
result <- manyTill anyChar (char '}')
|
|
|
|
return (Str (result)))
|
|
|
|
|
|
|
|
strong = try (do
|
|
|
|
string "\\textbf{"
|
|
|
|
result <- manyTill inline (char '}')
|
|
|
|
return (Strong result))
|
|
|
|
|
|
|
|
whitespace = do
|
|
|
|
many1 (oneOf "~ \t")
|
|
|
|
return Space
|
|
|
|
|
|
|
|
-- hard line break
|
|
|
|
linebreak = try (do
|
|
|
|
string "\\\\"
|
|
|
|
return LineBreak)
|
|
|
|
|
2007-01-24 08:14:43 +00:00
|
|
|
spacer = try $ do
|
|
|
|
string "\\,"
|
|
|
|
return (Str "")
|
|
|
|
|
2006-10-17 14:22:29 +00:00
|
|
|
str = do
|
|
|
|
result <- many1 (noneOf specialChars)
|
2007-01-06 09:54:58 +00:00
|
|
|
return (Str result)
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
-- endline internal to paragraph
|
|
|
|
endline = try (do
|
|
|
|
newline
|
|
|
|
notFollowedBy blankline
|
|
|
|
return Space)
|
|
|
|
|
|
|
|
-- math
|
|
|
|
math = math1 <|> math2 <?> "math"
|
|
|
|
|
|
|
|
math1 = try (do
|
|
|
|
char '$'
|
|
|
|
result <- many (noneOf "$")
|
|
|
|
char '$'
|
|
|
|
return (TeX ("$" ++ result ++ "$")))
|
|
|
|
|
|
|
|
math2 = try (do
|
|
|
|
string "\\("
|
|
|
|
result <- many (noneOf "$")
|
|
|
|
string "\\)"
|
|
|
|
return (TeX ("$" ++ result ++ "$")))
|
|
|
|
|
|
|
|
--
|
|
|
|
-- links and images
|
|
|
|
--
|
|
|
|
|
|
|
|
link = try (do
|
|
|
|
string "\\href{"
|
|
|
|
url <- manyTill anyChar (char '}')
|
|
|
|
char '{'
|
|
|
|
label <- manyTill inline (char '}')
|
Extensive changes stemming from a rethinking of the Pandoc data
structure. Key and Note blocks have been removed. Link and image URLs
are now stored directly in Link and Image inlines, and note blocks
are stored in Note inlines. This requires changes in both parsers
and writers. Markdown and RST parsers need to extract data from key
and note blocks and insert them into the relevant inline elements.
Other parsers can be simplified, since there is no longer any need to
construct separate key and note blocks. Markdown, RST, and HTML writers
need to construct lists of notes; Markdown and RST writers need to
construct lists of link references (when the --reference-links option
is specified); and the RST writer needs to construct a list of image
substitution references. All writers have been rewritten to use the
State monad when state is required. This rewrite yields a small speed
boost and considerably cleaner code.
* Text/Pandoc/Definition.hs:
+ blocks: removed Key and Note
+ inlines: removed NoteRef, added Note
+ modified Target: there is no longer a 'Ref' target; all targets
are explicit URL, title pairs
* Text/Pandoc/Shared.hs:
+ Added 'Reference', 'isNoteBlock', 'isKeyBlock', 'isLineClump',
used in some of the readers.
+ Removed 'generateReference', 'keyTable', 'replaceReferenceLinks',
'replaceRefLinksBlockList', along with some auxiliary functions
used only by them. These are no longer needed, since
reference links are resolved in the Markdown and RST readers.
+ Moved 'inTags', 'selfClosingTag', 'inTagsSimple', and 'inTagsIndented'
to the Docbook writer, since that is now the only module that uses
them.
+ Changed name of 'escapeSGMLString' to 'escapeStringForXML'
+ Added KeyTable and NoteTable types
+ Removed fields from ParserState; 'stateKeyBlocks', 'stateKeysUsed',
'stateNoteBlocks', 'stateNoteIdentifiers', 'stateInlineLinks'.
Added 'stateKeys' and 'stateNotes'.
+ Added clause for Note to 'prettyBlock'.
+ Added 'writerNotes', 'writerReferenceLinks' fields to WriterOptions.
* Text/Pandoc/Entities.hs: Renamed 'escapeSGMLChar' and
'escapeSGMLString' to 'escapeCharForXML' and 'escapeStringForXML'
* Text/ParserCombinators/Pandoc.hs: Added lineClump parser: parses a raw
line block up to and including following blank lines.
* Main.hs: Replaced --inline-links with --reference-links.
* README:
+ Documented --reference-links and removed description of --inline-links.
+ Added note that footnotes may occur anywhere in the document, but must
be at the outer level, not embedded in block elements.
* man/man1/pandoc.1, man/man1/html2markdown.1: Removed --inline-links
option, added --reference-links option
* Markdown and RST readers:
+ Rewrote to fit new Pandoc definition. Since there are no longer
Note or Key blocks, all note and key blocks are parsed on a first pass
through the document. Once tables of notes and keys have been constructed,
the remaining parts of the document are reassembled and parsed.
+ Refactored link parsers.
* LaTeX and HTML readers: Rewrote to fit new Pandoc definition. Since
there are no longer Note or Key blocks, notes and references can be
parsed in a single pass through the document.
* RST, Markdown, and HTML writers: Rewrote using state monad new Pandoc
and definition. State is used to hold lists of references footnotes to
and be printed at the end of the document.
* RTF and LaTeX writers: Rewrote using new Pandoc definition. (Because
of the different treatment of footnotes, the "notes" parameter is no
longer needed in the block and inline conversion functions.)
* Docbook writer:
+ Moved the functions 'attributeList', 'inTags', 'selfClosingTag',
'inTagsSimple', 'inTagsIndented' from Text/Pandoc/Shared, since
they are now used only by the Docbook writer.
+ Rewrote using new Pandoc definition. (Because of the different
treatment of footnotes, the "notes" parameter is no longer needed
in the block and inline conversion functions.)
* Updated test suite
* Throughout: old haskell98 module names replaced by hierarchical module
names, e.g. List by Data.List.
* debian/control: Include libghc6-xhtml-dev instead of libghc6-html-dev
in "Build-Depends."
* cabalize:
+ Remove haskell98 from BASE_DEPENDS (since now the new hierarchical
module names are being used throughout)
+ Added mtl to BASE_DEPENDS (needed for state monad)
+ Removed html from GHC66_DEPENDS (not needed since xhtml is now used)
git-svn-id: https://pandoc.googlecode.com/svn/trunk@580 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-04-10 01:56:50 +00:00
|
|
|
return (Link (normalizeSpaces label) (url, "")))
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
image = try (do
|
2006-11-26 07:01:37 +00:00
|
|
|
("includegraphics", _, args) <- command
|
2006-11-26 07:08:46 +00:00
|
|
|
let args' = filter isArg args -- filter out options
|
2006-11-26 07:01:37 +00:00
|
|
|
let src = if null args' then
|
Extensive changes stemming from a rethinking of the Pandoc data
structure. Key and Note blocks have been removed. Link and image URLs
are now stored directly in Link and Image inlines, and note blocks
are stored in Note inlines. This requires changes in both parsers
and writers. Markdown and RST parsers need to extract data from key
and note blocks and insert them into the relevant inline elements.
Other parsers can be simplified, since there is no longer any need to
construct separate key and note blocks. Markdown, RST, and HTML writers
need to construct lists of notes; Markdown and RST writers need to
construct lists of link references (when the --reference-links option
is specified); and the RST writer needs to construct a list of image
substitution references. All writers have been rewritten to use the
State monad when state is required. This rewrite yields a small speed
boost and considerably cleaner code.
* Text/Pandoc/Definition.hs:
+ blocks: removed Key and Note
+ inlines: removed NoteRef, added Note
+ modified Target: there is no longer a 'Ref' target; all targets
are explicit URL, title pairs
* Text/Pandoc/Shared.hs:
+ Added 'Reference', 'isNoteBlock', 'isKeyBlock', 'isLineClump',
used in some of the readers.
+ Removed 'generateReference', 'keyTable', 'replaceReferenceLinks',
'replaceRefLinksBlockList', along with some auxiliary functions
used only by them. These are no longer needed, since
reference links are resolved in the Markdown and RST readers.
+ Moved 'inTags', 'selfClosingTag', 'inTagsSimple', and 'inTagsIndented'
to the Docbook writer, since that is now the only module that uses
them.
+ Changed name of 'escapeSGMLString' to 'escapeStringForXML'
+ Added KeyTable and NoteTable types
+ Removed fields from ParserState; 'stateKeyBlocks', 'stateKeysUsed',
'stateNoteBlocks', 'stateNoteIdentifiers', 'stateInlineLinks'.
Added 'stateKeys' and 'stateNotes'.
+ Added clause for Note to 'prettyBlock'.
+ Added 'writerNotes', 'writerReferenceLinks' fields to WriterOptions.
* Text/Pandoc/Entities.hs: Renamed 'escapeSGMLChar' and
'escapeSGMLString' to 'escapeCharForXML' and 'escapeStringForXML'
* Text/ParserCombinators/Pandoc.hs: Added lineClump parser: parses a raw
line block up to and including following blank lines.
* Main.hs: Replaced --inline-links with --reference-links.
* README:
+ Documented --reference-links and removed description of --inline-links.
+ Added note that footnotes may occur anywhere in the document, but must
be at the outer level, not embedded in block elements.
* man/man1/pandoc.1, man/man1/html2markdown.1: Removed --inline-links
option, added --reference-links option
* Markdown and RST readers:
+ Rewrote to fit new Pandoc definition. Since there are no longer
Note or Key blocks, all note and key blocks are parsed on a first pass
through the document. Once tables of notes and keys have been constructed,
the remaining parts of the document are reassembled and parsed.
+ Refactored link parsers.
* LaTeX and HTML readers: Rewrote to fit new Pandoc definition. Since
there are no longer Note or Key blocks, notes and references can be
parsed in a single pass through the document.
* RST, Markdown, and HTML writers: Rewrote using state monad new Pandoc
and definition. State is used to hold lists of references footnotes to
and be printed at the end of the document.
* RTF and LaTeX writers: Rewrote using new Pandoc definition. (Because
of the different treatment of footnotes, the "notes" parameter is no
longer needed in the block and inline conversion functions.)
* Docbook writer:
+ Moved the functions 'attributeList', 'inTags', 'selfClosingTag',
'inTagsSimple', 'inTagsIndented' from Text/Pandoc/Shared, since
they are now used only by the Docbook writer.
+ Rewrote using new Pandoc definition. (Because of the different
treatment of footnotes, the "notes" parameter is no longer needed
in the block and inline conversion functions.)
* Updated test suite
* Throughout: old haskell98 module names replaced by hierarchical module
names, e.g. List by Data.List.
* debian/control: Include libghc6-xhtml-dev instead of libghc6-html-dev
in "Build-Depends."
* cabalize:
+ Remove haskell98 from BASE_DEPENDS (since now the new hierarchical
module names are being used throughout)
+ Added mtl to BASE_DEPENDS (needed for state monad)
+ Removed html from GHC66_DEPENDS (not needed since xhtml is now used)
git-svn-id: https://pandoc.googlecode.com/svn/trunk@580 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-04-10 01:56:50 +00:00
|
|
|
("", "")
|
2006-11-26 07:01:37 +00:00
|
|
|
else
|
Extensive changes stemming from a rethinking of the Pandoc data
structure. Key and Note blocks have been removed. Link and image URLs
are now stored directly in Link and Image inlines, and note blocks
are stored in Note inlines. This requires changes in both parsers
and writers. Markdown and RST parsers need to extract data from key
and note blocks and insert them into the relevant inline elements.
Other parsers can be simplified, since there is no longer any need to
construct separate key and note blocks. Markdown, RST, and HTML writers
need to construct lists of notes; Markdown and RST writers need to
construct lists of link references (when the --reference-links option
is specified); and the RST writer needs to construct a list of image
substitution references. All writers have been rewritten to use the
State monad when state is required. This rewrite yields a small speed
boost and considerably cleaner code.
* Text/Pandoc/Definition.hs:
+ blocks: removed Key and Note
+ inlines: removed NoteRef, added Note
+ modified Target: there is no longer a 'Ref' target; all targets
are explicit URL, title pairs
* Text/Pandoc/Shared.hs:
+ Added 'Reference', 'isNoteBlock', 'isKeyBlock', 'isLineClump',
used in some of the readers.
+ Removed 'generateReference', 'keyTable', 'replaceReferenceLinks',
'replaceRefLinksBlockList', along with some auxiliary functions
used only by them. These are no longer needed, since
reference links are resolved in the Markdown and RST readers.
+ Moved 'inTags', 'selfClosingTag', 'inTagsSimple', and 'inTagsIndented'
to the Docbook writer, since that is now the only module that uses
them.
+ Changed name of 'escapeSGMLString' to 'escapeStringForXML'
+ Added KeyTable and NoteTable types
+ Removed fields from ParserState; 'stateKeyBlocks', 'stateKeysUsed',
'stateNoteBlocks', 'stateNoteIdentifiers', 'stateInlineLinks'.
Added 'stateKeys' and 'stateNotes'.
+ Added clause for Note to 'prettyBlock'.
+ Added 'writerNotes', 'writerReferenceLinks' fields to WriterOptions.
* Text/Pandoc/Entities.hs: Renamed 'escapeSGMLChar' and
'escapeSGMLString' to 'escapeCharForXML' and 'escapeStringForXML'
* Text/ParserCombinators/Pandoc.hs: Added lineClump parser: parses a raw
line block up to and including following blank lines.
* Main.hs: Replaced --inline-links with --reference-links.
* README:
+ Documented --reference-links and removed description of --inline-links.
+ Added note that footnotes may occur anywhere in the document, but must
be at the outer level, not embedded in block elements.
* man/man1/pandoc.1, man/man1/html2markdown.1: Removed --inline-links
option, added --reference-links option
* Markdown and RST readers:
+ Rewrote to fit new Pandoc definition. Since there are no longer
Note or Key blocks, all note and key blocks are parsed on a first pass
through the document. Once tables of notes and keys have been constructed,
the remaining parts of the document are reassembled and parsed.
+ Refactored link parsers.
* LaTeX and HTML readers: Rewrote to fit new Pandoc definition. Since
there are no longer Note or Key blocks, notes and references can be
parsed in a single pass through the document.
* RST, Markdown, and HTML writers: Rewrote using state monad new Pandoc
and definition. State is used to hold lists of references footnotes to
and be printed at the end of the document.
* RTF and LaTeX writers: Rewrote using new Pandoc definition. (Because
of the different treatment of footnotes, the "notes" parameter is no
longer needed in the block and inline conversion functions.)
* Docbook writer:
+ Moved the functions 'attributeList', 'inTags', 'selfClosingTag',
'inTagsSimple', 'inTagsIndented' from Text/Pandoc/Shared, since
they are now used only by the Docbook writer.
+ Rewrote using new Pandoc definition. (Because of the different
treatment of footnotes, the "notes" parameter is no longer needed
in the block and inline conversion functions.)
* Updated test suite
* Throughout: old haskell98 module names replaced by hierarchical module
names, e.g. List by Data.List.
* debian/control: Include libghc6-xhtml-dev instead of libghc6-html-dev
in "Build-Depends."
* cabalize:
+ Remove haskell98 from BASE_DEPENDS (since now the new hierarchical
module names are being used throughout)
+ Added mtl to BASE_DEPENDS (needed for state monad)
+ Removed html from GHC66_DEPENDS (not needed since xhtml is now used)
git-svn-id: https://pandoc.googlecode.com/svn/trunk@580 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-04-10 01:56:50 +00:00
|
|
|
(stripFirstAndLast (head args'), "")
|
2006-11-26 07:01:37 +00:00
|
|
|
return (Image [Str "image"] src))
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
footnote = try (do
|
2006-11-27 06:51:03 +00:00
|
|
|
(name, _, (contents:[])) <- command
|
2006-12-20 06:50:14 +00:00
|
|
|
if ((name == "footnote") || (name == "thanks"))
|
|
|
|
then string ""
|
|
|
|
else fail "not a footnote or thanks command"
|
2006-11-26 07:01:37 +00:00
|
|
|
let contents' = stripFirstAndLast contents
|
2006-12-21 09:02:06 +00:00
|
|
|
-- parse the extracted block, which may contain various block elements:
|
|
|
|
rest <- getInput
|
|
|
|
setInput $ contents'
|
|
|
|
blocks <- parseBlocks
|
|
|
|
setInput rest
|
Extensive changes stemming from a rethinking of the Pandoc data
structure. Key and Note blocks have been removed. Link and image URLs
are now stored directly in Link and Image inlines, and note blocks
are stored in Note inlines. This requires changes in both parsers
and writers. Markdown and RST parsers need to extract data from key
and note blocks and insert them into the relevant inline elements.
Other parsers can be simplified, since there is no longer any need to
construct separate key and note blocks. Markdown, RST, and HTML writers
need to construct lists of notes; Markdown and RST writers need to
construct lists of link references (when the --reference-links option
is specified); and the RST writer needs to construct a list of image
substitution references. All writers have been rewritten to use the
State monad when state is required. This rewrite yields a small speed
boost and considerably cleaner code.
* Text/Pandoc/Definition.hs:
+ blocks: removed Key and Note
+ inlines: removed NoteRef, added Note
+ modified Target: there is no longer a 'Ref' target; all targets
are explicit URL, title pairs
* Text/Pandoc/Shared.hs:
+ Added 'Reference', 'isNoteBlock', 'isKeyBlock', 'isLineClump',
used in some of the readers.
+ Removed 'generateReference', 'keyTable', 'replaceReferenceLinks',
'replaceRefLinksBlockList', along with some auxiliary functions
used only by them. These are no longer needed, since
reference links are resolved in the Markdown and RST readers.
+ Moved 'inTags', 'selfClosingTag', 'inTagsSimple', and 'inTagsIndented'
to the Docbook writer, since that is now the only module that uses
them.
+ Changed name of 'escapeSGMLString' to 'escapeStringForXML'
+ Added KeyTable and NoteTable types
+ Removed fields from ParserState; 'stateKeyBlocks', 'stateKeysUsed',
'stateNoteBlocks', 'stateNoteIdentifiers', 'stateInlineLinks'.
Added 'stateKeys' and 'stateNotes'.
+ Added clause for Note to 'prettyBlock'.
+ Added 'writerNotes', 'writerReferenceLinks' fields to WriterOptions.
* Text/Pandoc/Entities.hs: Renamed 'escapeSGMLChar' and
'escapeSGMLString' to 'escapeCharForXML' and 'escapeStringForXML'
* Text/ParserCombinators/Pandoc.hs: Added lineClump parser: parses a raw
line block up to and including following blank lines.
* Main.hs: Replaced --inline-links with --reference-links.
* README:
+ Documented --reference-links and removed description of --inline-links.
+ Added note that footnotes may occur anywhere in the document, but must
be at the outer level, not embedded in block elements.
* man/man1/pandoc.1, man/man1/html2markdown.1: Removed --inline-links
option, added --reference-links option
* Markdown and RST readers:
+ Rewrote to fit new Pandoc definition. Since there are no longer
Note or Key blocks, all note and key blocks are parsed on a first pass
through the document. Once tables of notes and keys have been constructed,
the remaining parts of the document are reassembled and parsed.
+ Refactored link parsers.
* LaTeX and HTML readers: Rewrote to fit new Pandoc definition. Since
there are no longer Note or Key blocks, notes and references can be
parsed in a single pass through the document.
* RST, Markdown, and HTML writers: Rewrote using state monad new Pandoc
and definition. State is used to hold lists of references footnotes to
and be printed at the end of the document.
* RTF and LaTeX writers: Rewrote using new Pandoc definition. (Because
of the different treatment of footnotes, the "notes" parameter is no
longer needed in the block and inline conversion functions.)
* Docbook writer:
+ Moved the functions 'attributeList', 'inTags', 'selfClosingTag',
'inTagsSimple', 'inTagsIndented' from Text/Pandoc/Shared, since
they are now used only by the Docbook writer.
+ Rewrote using new Pandoc definition. (Because of the different
treatment of footnotes, the "notes" parameter is no longer needed
in the block and inline conversion functions.)
* Updated test suite
* Throughout: old haskell98 module names replaced by hierarchical module
names, e.g. List by Data.List.
* debian/control: Include libghc6-xhtml-dev instead of libghc6-html-dev
in "Build-Depends."
* cabalize:
+ Remove haskell98 from BASE_DEPENDS (since now the new hierarchical
module names are being used throughout)
+ Added mtl to BASE_DEPENDS (needed for state monad)
+ Removed html from GHC66_DEPENDS (not needed since xhtml is now used)
git-svn-id: https://pandoc.googlecode.com/svn/trunk@580 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-04-10 01:56:50 +00:00
|
|
|
return (Note blocks))
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
-- | Parse any LaTeX command and return it in a raw TeX inline element.
|
|
|
|
rawLaTeXInline :: GenParser Char ParserState Inline
|
|
|
|
rawLaTeXInline = try (do
|
2006-11-26 07:01:37 +00:00
|
|
|
(name, star, args) <- command
|
|
|
|
let argStr = concat args
|
2006-10-17 14:22:29 +00:00
|
|
|
state <- getState
|
2006-12-20 06:50:14 +00:00
|
|
|
if ((name == "begin") || (name == "end") || (name == "item"))
|
|
|
|
then fail "not an inline command"
|
|
|
|
else string ""
|
2006-11-26 07:01:37 +00:00
|
|
|
return (TeX ("\\" ++ name ++ star ++ argStr)))
|
2007-01-06 09:54:58 +00:00
|
|
|
|