diff --git a/README b/README index 109158fb9..b291734dc 100644 --- a/README +++ b/README @@ -437,45 +437,76 @@ cases" involving lists. Consider this source: 3. Third -Pandoc transforms this into a "compact list" (with no `
` tags -around "First", "Second", or "Third"), while markdown puts `
` -tags around "Second" and "Third" (but not "First"), because of -the blank space around "Third". Pandoc follows a simple rule: -if the text is followed by a blank line, it is treated as a -paragraph. Since "Second" is followed by a list, and not a blank -line, it isn't treated as a paragraph. The fact that the list -is followed by a blank line is irrelevant. (Note: Pandoc works -this way even when the `--strict` option is specified. This -behavior is consistent with the official markdown syntax -description, even though it is different from that of `Markdown.pl`.) +Pandoc transforms this into a "compact list" (with no `
` tags around +"First", "Second", or "Third"), while markdown puts `
` tags around
+"Second" and "Third" (but not "First"), because of the blank space
+around "Third". Pandoc follows a simple rule: if the text is followed by
+a blank line, it is treated as a paragraph. Since "Second" is followed
+by a list, and not a blank line, it isn't treated as a paragraph. The
+fact that the list is followed by a blank line is irrelevant. (Note:
+Pandoc works this way even when the `--strict` option is specified. This
+behavior is consistent with the official markdown syntax description,
+even though it is different from that of `Markdown.pl`.)
-Unlike standard markdown, Pandoc allows ordered list items to be
-marked with single lowercase letters (from 'a' to 'n'), instead of
-numbers. So, for example, this source yields a nested ordered list:
+Unlike standard markdown, Pandoc allows ordered list items to be marked
+with uppercase and lowercase letters and roman numerals, in addition to
+arabic numerals. (This behavior can be turned off using the `--strict`
+option.) List markers may be enclosed in parentheses or followed by a
+single right-parentheses or period. Pandoc also pays attention to the
+type of list marker used, and to the starting number, and both of these
+are preserved where possible in the output format. Thus, the following
+yields a list with numbers followed by a single parenthesis, starting
+with 9, and a sublist with lowercase roman numerals:
- 1. First
- 2. Second
- a. Fee
- b. Fie
- 3. Third
+ 9) Ninth
+ 10) Tenth
+ 11) Eleventh
+ i. subone
+ ii. subtwo
+ iii. subthree
-The letters may be followed by either '.' or ')':
+Note that Pandoc pays attention only to the *starting* number in a list.
+So, the following yields a list numbered sequentially starting from 2:
- 1. First
- 2. Second
- a) Fee
- b) Fie
- 3. Third
+ (2) Two
+ (5) Three
+ (2) Four
-Note that Pandoc pays no attention to the *type* of ordered list
-item marker used. Thus, the following is treated just the same as
-the example above:
+If default list markers are desired, use '`#.`':
- a) First
- 1. Second
- 2. Fee
- b) Fie
- c. Third
+ #. one
+ #. two
+ #. three
+
+If you change list style in mid-list, Pandoc will notice and assume you
+are starting a sublist. So,
+
+ 1. One
+ 2. Two
+ A. Sub
+ B. Sub
+ 3. Three
+
+gets treated as if it were
+
+ 1. One
+ 2. Two
+ A. Sub
+ B. Sub
+ 3. Three
+
+Note that a list beginning with a single letter will be interpreted as
+an alphabetic list. So you are out of luck if you want a roman-numbered
+list starting with 100 (C).
+
+Note also that a paragraph starting with a capital letter and a period
+(for example, an initial) will be interpreted as a list:
+
+ B. Russell was an English philosopher.
+
+To avoid this, use backslash escapes:
+
+ B\. Russell was an English philosopher.
Definition lists
----------------
diff --git a/src/Text/Pandoc/Definition.hs b/src/Text/Pandoc/Definition.hs
index a1abfcb50..3d3858b7e 100644
--- a/src/Text/Pandoc/Definition.hs
+++ b/src/Text/Pandoc/Definition.hs
@@ -45,6 +45,23 @@ data Alignment = AlignLeft
| AlignCenter
| AlignDefault deriving (Eq, Show, Read)
+-- | List attributes.
+type ListAttributes = (Int, ListNumberStyle, ListNumberDelim)
+
+-- | Style of list numbers.
+data ListNumberStyle = DefaultStyle
+ | Decimal
+ | LowerRoman
+ | UpperRoman
+ | LowerAlpha
+ | UpperAlpha deriving (Eq, Show, Read)
+
+-- | Delimiter of list numbers.
+data ListNumberDelim = DefaultDelim
+ | Period
+ | OneParen
+ | TwoParens deriving (Eq, Show, Read)
+
-- | Block element.
data Block
= Plain [Inline] -- ^ Plain text, not a paragraph
@@ -53,8 +70,8 @@ data Block
| CodeBlock String -- ^ Code block (literal)
| RawHtml String -- ^ Raw HTML block (literal)
| BlockQuote [Block] -- ^ Block quote (list of blocks)
- | OrderedList [[Block]] -- ^ Ordered list (list of items, each
- -- a list of blocks)
+ | OrderedList ListAttributes [[Block]] -- ^ Ordered list (attributes,
+ -- and a list of items, each a list of blocks)
| BulletList [[Block]] -- ^ Bullet list (list of items, each
-- a list of blocks)
| DefinitionList [([Inline],[Block])] -- ^ Definition list
diff --git a/src/Text/Pandoc/ParserCombinators.hs b/src/Text/Pandoc/ParserCombinators.hs
index 189f97182..559a654cc 100644
--- a/src/Text/Pandoc/ParserCombinators.hs
+++ b/src/Text/Pandoc/ParserCombinators.hs
@@ -40,7 +40,10 @@ module Text.Pandoc.ParserCombinators (
stringAnyCase,
parseFromString,
lineClump,
- charsInBalanced
+ charsInBalanced,
+ charsInBalanced',
+ romanNumeral,
+ withHorizDisplacement
) where
import Text.ParserCombinators.Parsec
import Data.Char ( toUpper, toLower )
@@ -127,7 +130,8 @@ lineClump = do
-- and a close character, including text between balanced
-- pairs of open and close. For example,
-- @charsInBalanced '(' ')'@ will parse "(hello (there))"
--- and return "hello (there)".
+-- and return "hello (there)". Stop if a blank line is
+-- encountered.
charsInBalanced :: Char -> Char -> GenParser Char st String
charsInBalanced open close = try $ do
char open
@@ -138,3 +142,57 @@ charsInBalanced open close = try $ do
(char close)
return $ concat raw
+-- | Like charsInBalanced, but allow blank lines in the content.
+charsInBalanced' :: Char -> Char -> GenParser Char st String
+charsInBalanced' open close = try $ do
+ char open
+ raw <- manyTill ( (do res <- charsInBalanced open close
+ return $ [open] ++ res ++ [close])
+ <|> count 1 anyChar)
+ (char close)
+ return $ concat raw
+
+-- | Parses a roman numeral (uppercase or lowercase), returns number.
+romanNumeral :: Bool -> -- ^ Uppercase if true
+ GenParser Char st Int
+romanNumeral upper = try $ do
+ let char' c = char (if upper then toUpper c else c)
+ let one = char' 'i'
+ let five = char' 'v'
+ let ten = char' 'x'
+ let fifty = char' 'l'
+ let hundred = char' 'c'
+ let fivehundred = char' 'd'
+ let thousand = char' 'm'
+ thousands <- many thousand >>= (return . (1000 *) . length)
+ ninehundreds <- option 0 $ try $ hundred >> thousand >> return 900
+ fivehundreds <- many fivehundred >>= (return . (500 *) . length)
+ fourhundreds <- option 0 $ try $ hundred >> fivehundred >> return 400
+ hundreds <- many hundred >>= (return . (100 *) . length)
+ nineties <- option 0 $ try $ ten >> hundred >> return 90
+ fifties <- many fifty >>= (return . (50 *) . length)
+ forties <- option 0 $ try $ ten >> fifty >> return 40
+ tens <- many ten >>= (return . (10 *) . length)
+ nines <- option 0 $ try $ one >> ten >> return 9
+ fives <- many five >>= (return . (5*) . length)
+ fours <- option 0 $ try $ one >> five >> return 4
+ ones <- many one >>= (return . length)
+ let total = thousands + ninehundreds + fivehundreds + fourhundreds +
+ hundreds + nineties + fifties + forties + tens + nines +
+ fives + fours + ones
+ if total == 0
+ then fail "not a roman numeral"
+ else return total
+
+-- | Applies a parser, returns tuple of its results and its horizontal
+-- displacement (the difference between the source column at the end
+-- and the source column at the beginning). Vertical displacement
+-- (source row) is ignored.
+withHorizDisplacement :: GenParser Char st a -- ^ Parser to apply
+ -> GenParser Char st (a, Int) -- ^ (result, displacement)
+withHorizDisplacement parser = do
+ pos1 <- getPosition
+ result <- parser
+ pos2 <- getPosition
+ return (result, sourceColumn pos2 - sourceColumn pos1)
+
diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs
index 270c7ba21..1742667b8 100644
--- a/src/Text/Pandoc/Readers/HTML.hs
+++ b/src/Text/Pandoc/Readers/HTML.hs
@@ -354,11 +354,26 @@ blockQuote = try (do
list = choice [ bulletList, orderedList, definitionList ] > "list"
orderedList = try $ do
- htmlTag "ol"
+ (_, attribs) <- htmlTag "ol"
+ (start, style) <- option (1, DefaultStyle) $
+ do failIfStrict
+ let sta = fromMaybe "1" $
+ lookup "start" attribs
+ let sty = fromMaybe (fromMaybe "" $
+ lookup "style" attribs) $
+ lookup "class" attribs
+ let sty' = case sty of
+ "lower-roman" -> LowerRoman
+ "upper-roman" -> UpperRoman
+ "lower-alpha" -> LowerAlpha
+ "upper-alpha" -> UpperAlpha
+ "decimal" -> Decimal
+ _ -> DefaultStyle
+ return (read sta, sty')
spaces
items <- sepEndBy1 (blocksIn "li") spaces
htmlEndTag "ol"
- return (OrderedList items)
+ return (OrderedList (start, style, DefaultDelim) items)
bulletList = try $ do
htmlTag "ul"
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 77ed4607a..73a3e4a8f 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -59,12 +59,8 @@ specialChars = "\\$%&^&_~#{}\n \t|<>'\"-"
-- | Returns text between brackets and its matching pair.
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]))
+ result <- charsInBalanced' openB closeB
+ return ([openB] ++ result ++ [closeB]))
-- | Returns an option or argument of a LaTeX command.
optOrArg = choice [ (bracketedText '{' '}'), (bracketedText '[' ']') ]
@@ -255,12 +251,30 @@ listItem = try $ do
return (opt, blocks)
orderedList = try $ do
- begin "enumerate"
+ string "\\begin{enumerate}"
+ (_, style, delim) <- option (1, DefaultStyle, DefaultDelim) $
+ try $ do failIfStrict
+ char '['
+ res <- anyOrderedListMarker
+ char ']'
+ return res
spaces
+ option "" $ try $ do string "\\setlength{\\itemindent}"
+ char '{'
+ manyTill anyChar (char '}')
+ spaces
+ start <- option 1 $ try $ do failIfStrict
+ string "\\setcounter{enum"
+ many1 (char 'i')
+ string "}{"
+ num <- many1 digit
+ char '}'
+ spaces
+ return $ (read num) + 1
items <- many listItem
end "enumerate"
spaces
- return (OrderedList $ map snd items)
+ return $ OrderedList (start, style, delim) $ map snd items
bulletList = try $ do
begin "itemize"
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 0ecb09178..3ccb74ba7 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -243,6 +243,8 @@ header = choice [ setextHeader, atxHeader ] > "header"
atxHeader = try (do
lead <- many1 (char '#')
+ notFollowedBy (char '.') -- this would be a list
+ notFollowedBy (char ')')
skipSpaces
txt <- manyTill inline atxClosing
return (Header (length lead) (normalizeSpaces txt)))
@@ -354,27 +356,33 @@ blockQuote = do
list = choice [ bulletList, orderedList, definitionList ] > "list"
-bulletListStart = try (do
+bulletListStart = try $ do
option ' ' newline -- if preceded by a Plain block in a list context
nonindentSpaces
notFollowedBy' hrule -- because hrules start out just like lists
oneOf bulletListMarkers
spaceChar
- skipSpaces)
+ skipSpaces
-standardOrderedListStart = try (do
- many1 digit
- char '.')
-
-extendedOrderedListStart = try (do
- failIfStrict
- oneOf ['a'..'n']
- oneOf ".)")
-
-orderedListStart = try $ do
+anyOrderedListStart = try $ do
option ' ' newline -- if preceded by a Plain block in a list context
nonindentSpaces
- standardOrderedListStart <|> extendedOrderedListStart
+ state <- getState
+ if stateStrict state
+ then do many1 digit
+ char '.'
+ return (1, DefaultStyle, DefaultDelim)
+ else anyOrderedListMarker
+
+orderedListStart style delim = try $ do
+ option ' ' newline -- if preceded by a Plain block in a list context
+ nonindentSpaces
+ state <- getState
+ if stateStrict state
+ then do many1 digit
+ char '.'
+ return 1
+ else orderedListMarker style delim
oneOf spaceChars
skipSpaces
@@ -385,7 +393,7 @@ listLine start = try (do
notFollowedBy' (do
indentSpaces
many (spaceChar)
- choice [bulletListStart, orderedListStart])
+ choice [bulletListStart, anyOrderedListStart >> return ()])
line <- manyTill anyChar newline
return (line ++ "\n"))
@@ -431,9 +439,10 @@ listItem start = try (do
return contents)
orderedList = try (do
- items <- many1 (listItem orderedListStart)
+ (start, style, delim) <- lookAhead anyOrderedListStart
+ items <- many1 (listItem (orderedListStart style delim))
let items' = compactify items
- return (OrderedList items'))
+ return (OrderedList (start, style, delim) items'))
bulletList = try (do
items <- many1 (listItem bulletListStart)
@@ -906,7 +915,7 @@ endline = try (do
else return ()
-- parse potential list-starts differently if in a list:
if (stateParserContext st) == ListItemState
- then notFollowedBy' (orderedListStart <|> bulletListStart)
+ then notFollowedBy' $ choice [bulletListStart, anyOrderedListStart >> return ()]
else return ()
return Space)
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index 83c5383bd..a36c33d92 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -379,46 +379,11 @@ bulletListStart = try (do
let len = length (marker:white)
return len)
-withPeriodSuffix parser = try (do
- a <- parser
- b <- char '.'
- return (a ++ [b]))
-
-withParentheses parser = try (do
- a <- char '('
- b <- parser
- c <- char ')'
- return ([a] ++ b ++ [c]))
-
-withRightParen parser = try (do
- a <- parser
- b <- char ')'
- return (a ++ [b]))
-
-upcaseWord = map toUpper
-
-romanNumeral = do
- let lowerNumerals = ["i", "ii", "iii", "iiii", "iv", "v", "vi",
- "vii", "viii", "ix", "x", "xi", "xii", "xiii",
- "xiv", "xv", "xvi", "xvii", "xviii", "xix", "xx",
- "xxi", "xxii", "xxiii", "xxiv" ]
- let upperNumerals = map upcaseWord lowerNumerals
- result <- choice $ map string (lowerNumerals ++ upperNumerals)
- return result
-
-orderedListEnumerator = choice [ many1 digit,
- count 1 (char '#'),
- count 1 letter,
- romanNumeral ]
-
-- parses ordered list start and returns its length (inc following whitespace)
-orderedListStart = try (do
- marker <- choice [ withPeriodSuffix orderedListEnumerator,
- withParentheses orderedListEnumerator,
- withRightParen orderedListEnumerator ]
+orderedListStart style delim = try $ do
+ (_, markerLen) <- withHorizDisplacement (orderedListMarker style delim)
white <- many1 spaceChar
- let len = length (marker ++ white)
- return len)
+ return $ markerLen + length white
-- parse a line of a list item
listLine markerLength = try (do
@@ -437,11 +402,11 @@ indentWith num = do
(try (do {char '\t'; count (num - tabStop) (char ' ')})) ]
-- parse raw text for one list item, excluding start marker and continuations
-rawListItem start = try (do
+rawListItem start = try $ do
markerLength <- start
firstLine <- manyTill anyChar newline
restLines <- many (listLine markerLength)
- return (markerLength, (firstLine ++ "\n" ++ (concat restLines))))
+ return (markerLength, (firstLine ++ "\n" ++ (concat restLines)))
-- continuation of a list item - indented and separated by blankline or
-- (in compact lists) endline.
@@ -473,10 +438,11 @@ listItem start = try (do
updateState (\st -> st {stateParserContext = oldContext})
return parsed)
-orderedList = try (do
- items <- many1 (listItem orderedListStart)
+orderedList = try $ do
+ (start, style, delim) <- lookAhead anyOrderedListMarker
+ items <- many1 (listItem (orderedListStart style delim))
let items' = compactify items
- return (OrderedList items'))
+ return (OrderedList (start, style, delim) items')
bulletList = try (do
items <- many1 (listItem bulletListStart)
@@ -611,7 +577,8 @@ endline = try (do
-- parse potential list-starts at beginning of line differently in a list:
st <- getState
if ((stateParserContext st) == ListItemState)
- then notFollowedBy' (choice [orderedListStart, bulletListStart])
+ then do notFollowedBy' anyOrderedListMarker
+ notFollowedBy' bulletListStart
else option () pzero
return Space)
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index b79af235d..587e3891a 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -43,6 +43,8 @@ module Text.Pandoc.Shared (
removeLeadingSpace,
removeTrailingSpace,
stripFirstAndLast,
+ camelCaseToHyphenated,
+ toRomanNumeral,
-- * Parsing
readWith,
testStringWith,
@@ -59,9 +61,12 @@ module Text.Pandoc.Shared (
nullBlock,
failIfStrict,
escaped,
+ anyOrderedListMarker,
+ orderedListMarker,
-- * Native format prettyprinting
prettyPandoc,
-- * Pandoc block and inline list processing
+ orderedListMarkers,
normalizeSpaces,
compactify,
Element (..),
@@ -77,8 +82,9 @@ module Text.Pandoc.Shared (
) where
import Text.Pandoc.Definition
import Text.ParserCombinators.Parsec
+import Text.Pandoc.ParserCombinators
import Text.Pandoc.Entities ( decodeEntities, escapeStringForXML )
-import Data.Char ( toLower, ord )
+import Data.Char ( toLower, toUpper, ord, chr, isLower, isUpper )
import Data.List ( find, groupBy, isPrefixOf )
-- | Parse a string with a given parser and state.
@@ -199,6 +205,105 @@ escaped parser = try (do
result <- parser
return (Str [result]))
+-- | Parses an uppercase roman numeral and returns (UpperRoman, number).
+upperRoman :: GenParser Char st (ListNumberStyle, Int)
+upperRoman = do
+ num <- romanNumeral True
+ return (UpperRoman, num)
+
+-- | Parses a lowercase roman numeral and returns (LowerRoman, number).
+lowerRoman :: GenParser Char st (ListNumberStyle, Int)
+lowerRoman = do
+ num <- romanNumeral False
+ return (LowerRoman, num)
+
+-- | Parses a decimal numeral and returns (Decimal, number).
+decimal :: GenParser Char st (ListNumberStyle, Int)
+decimal = do
+ num <- many1 digit
+ return (Decimal, read num)
+
+-- | Parses a '#' returns (DefaultStyle, 1).
+defaultNum :: GenParser Char st (ListNumberStyle, Int)
+defaultNum = do
+ char '#'
+ return (DefaultStyle, 1)
+
+-- | Parses a lowercase letter and returns (LowerAlpha, number).
+lowerAlpha :: GenParser Char st (ListNumberStyle, Int)
+lowerAlpha = do
+ ch <- oneOf ['a'..'z']
+ return (LowerAlpha, ord ch - ord 'a' + 1)
+
+-- | Parses an uppercase letter and returns (UpperAlpha, number).
+upperAlpha :: GenParser Char st (ListNumberStyle, Int)
+upperAlpha = do
+ ch <- oneOf ['A'..'Z']
+ return (UpperAlpha, ord ch - ord 'A' + 1)
+
+-- | Parses a roman numeral i or I
+romanOne :: GenParser Char st (ListNumberStyle, Int)
+romanOne = (do char 'i'
+ return (LowerRoman, 1)) <|>
+ (do char 'I'
+ return (UpperRoman, 1))
+
+-- | Parses an ordered list marker and returns list attributes.
+anyOrderedListMarker :: GenParser Char st ListAttributes
+anyOrderedListMarker = choice $ [delimParser numParser | delimParser <-
+ [inPeriod, inOneParen, inTwoParens],
+ numParser <- [decimal, defaultNum, romanOne,
+ lowerAlpha, lowerRoman, upperAlpha, upperRoman]]
+
+-- | Parses a list number (num) followed by a period, returns list attributes.
+inPeriod :: GenParser Char st (ListNumberStyle, Int)
+ -> GenParser Char st ListAttributes
+inPeriod num = try $ do
+ (style, start) <- num
+ char '.'
+ let delim = if style == DefaultStyle
+ then DefaultDelim
+ else Period
+ return (start, style, delim)
+
+-- | Parses a list number (num) followed by a paren, returns list attributes.
+inOneParen :: GenParser Char st (ListNumberStyle, Int)
+ -> GenParser Char st ListAttributes
+inOneParen num = try $ do
+ (style, start) <- num
+ char ')'
+ return (start, style, OneParen)
+
+-- | Parses a list number (num) enclosed in parens, returns list attributes.
+inTwoParens :: GenParser Char st (ListNumberStyle, Int)
+ -> GenParser Char st ListAttributes
+inTwoParens num = try $ do
+ char '('
+ (style, start) <- num
+ char ')'
+ return (start, style, TwoParens)
+
+-- | Parses an ordered list marker with a given style and delimiter,
+-- returns number.
+orderedListMarker :: ListNumberStyle
+ -> ListNumberDelim
+ -> GenParser Char st Int
+orderedListMarker style delim = do
+ let num = case style of
+ DefaultStyle -> decimal <|> defaultNum
+ Decimal -> decimal
+ UpperRoman -> upperRoman
+ LowerRoman -> lowerRoman
+ UpperAlpha -> upperAlpha
+ LowerAlpha -> lowerAlpha
+ let context = case delim of
+ DefaultDelim -> inPeriod
+ Period -> inPeriod
+ OneParen -> inOneParen
+ TwoParens -> inTwoParens
+ (start, style, delim) <- context num
+ return start
+
-- | Indent string as a block.
indentBy :: Int -- ^ Number of spaces to indent the block
-> Int -- ^ Number of spaces (rel to block) to indent first line
@@ -222,9 +327,10 @@ prettyBlockList indent blocks = indentBy indent (-2) $ "[ " ++
prettyBlock :: Block -> String
prettyBlock (BlockQuote blocks) = "BlockQuote\n " ++
(prettyBlockList 2 blocks)
-prettyBlock (OrderedList blockLists) =
- "OrderedList\n" ++ indentBy 2 0 ("[ " ++ (joinWithSep ", "
- (map (\blocks -> prettyBlockList 2 blocks) blockLists))) ++ " ]"
+prettyBlock (OrderedList attribs blockLists) =
+ "OrderedList " ++ show attribs ++ "\n" ++ indentBy 2 0 ("[ " ++
+ (joinWithSep ", " $ map (\blocks -> prettyBlockList 2 blocks)
+ blockLists)) ++ " ]"
prettyBlock (BulletList blockLists) = "BulletList\n" ++
indentBy 2 0 ("[ " ++ (joinWithSep ", "
(map (\blocks -> prettyBlockList 2 blocks) blockLists))) ++ " ]"
@@ -317,9 +423,17 @@ removeTrailingSpace :: String -> String
removeTrailingSpace = reverse . removeLeadingSpace . reverse
-- | Strip leading and trailing characters from string
+stripFirstAndLast :: String -> String
stripFirstAndLast str =
drop 1 $ take ((length str) - 1) str
+-- | Change CamelCase word to hyphenated lowercase (e.g., camel-case).
+camelCaseToHyphenated :: String -> String
+camelCaseToHyphenated "" = ""
+camelCaseToHyphenated (a:b:rest) | isLower a && isUpper b =
+ a:'-':(toLower b):(camelCaseToHyphenated rest)
+camelCaseToHyphenated (a:rest) = (toLower a):(camelCaseToHyphenated rest)
+
-- | Replace each occurrence of one sublist in a list with another.
substitute :: (Eq a) => [a] -> [a] -> [a] -> [a]
substitute _ _ [] = []
@@ -344,6 +458,46 @@ splitByIndices (x:xs) lst =
let (first, rest) = splitAt x lst in
first:(splitByIndices (map (\y -> y - x) xs) rest)
+-- | Generate infinite lazy list of markers for an ordered list,
+-- depending on list attributes.
+orderedListMarkers :: (Int, ListNumberStyle, ListNumberDelim) -> [String]
+orderedListMarkers (start, numstyle, numdelim) =
+ let singleton c = [c]
+ seq = case numstyle of
+ DefaultStyle -> map show [start..]
+ Decimal -> map show [start..]
+ UpperAlpha -> drop (start - 1) $ cycle $ map singleton ['A'..'Z']
+ LowerAlpha -> drop (start - 1) $ cycle $ map singleton ['a'..'z']
+ UpperRoman -> map toRomanNumeral [start..]
+ LowerRoman -> map (map toLower . toRomanNumeral) [start..]
+ inDelim str = case numdelim of
+ DefaultDelim -> str ++ "."
+ Period -> str ++ "."
+ OneParen -> str ++ ")"
+ TwoParens -> "(" ++ str ++ ")"
+ in map inDelim seq
+
+-- | Convert number < 4000 to uppercase roman numeral.
+toRomanNumeral :: Int -> String
+toRomanNumeral x =
+ if x >= 4000 || x < 0
+ then "?"
+ else case x of
+ x | x >= 1000 -> "M" ++ toRomanNumeral (x - 1000)
+ x | x >= 900 -> "CM" ++ toRomanNumeral (x - 900)
+ x | x >= 500 -> "D" ++ toRomanNumeral (x - 500)
+ x | x >= 400 -> "CD" ++ toRomanNumeral (x - 400)
+ x | x >= 100 -> "C" ++ toRomanNumeral (x - 100)
+ x | x >= 90 -> "XC" ++ toRomanNumeral (x - 90)
+ x | x >= 50 -> "L" ++ toRomanNumeral (x - 50)
+ x | x >= 40 -> "XL" ++ toRomanNumeral (x - 40)
+ x | x >= 10 -> "X" ++ toRomanNumeral (x - 10)
+ x | x >= 9 -> "IX" ++ toRomanNumeral (x - 5)
+ x | x >= 5 -> "V" ++ toRomanNumeral (x - 5)
+ x | x >= 4 -> "IV" ++ toRomanNumeral (x - 4)
+ x | x >= 1 -> "I" ++ toRomanNumeral (x - 1)
+ 0 -> ""
+
-- | Normalize a list of inline elements: remove leading and trailing
-- @Space@ elements, collapse double @Space@s into singles, and
-- remove empty Str elements.
@@ -383,8 +537,8 @@ containsPara [] = False
containsPara ((Para a):rest) = True
containsPara ((BulletList items):rest) = (any containsPara items) ||
(containsPara rest)
-containsPara ((OrderedList items):rest) = (any containsPara items) ||
- (containsPara rest)
+containsPara ((OrderedList _ items):rest) = (any containsPara items) ||
+ (containsPara rest)
containsPara (x:rest) = containsPara rest
-- | Data structure for defining hierarchical Pandoc documents
diff --git a/src/Text/Pandoc/Writers/ConTeXt.hs b/src/Text/Pandoc/Writers/ConTeXt.hs
index d5f0ba1d0..1f93787b0 100644
--- a/src/Text/Pandoc/Writers/ConTeXt.hs
+++ b/src/Text/Pandoc/Writers/ConTeXt.hs
@@ -122,9 +122,20 @@ blockToConTeXt (RawHtml str) = return ""
blockToConTeXt (BulletList lst) = do
contents <- mapM listItemToConTeXt lst
return $ "\\startltxitem\n" ++ concat contents ++ "\\stopltxitem\n"
-blockToConTeXt (OrderedList lst) = do
- contents <- mapM listItemToConTeXt lst
- return $ "\\startltxenum\n" ++ concat contents ++ "\\stopltxenum\n"
+blockToConTeXt (OrderedList attribs lst) = case attribs of
+ (1, DefaultStyle, DefaultDelim) -> do
+ contents <- mapM listItemToConTeXt lst
+ return $ "\\startltxenum\n" ++ concat contents ++ "\\stopltxenum\n"
+ _ -> do
+ let markers = take (length lst) $ orderedListMarkers attribs
+ contents <- zipWithM orderedListItemToConTeXt markers lst
+ let markerWidth = maximum $ map length markers
+ let markerWidth' = if markerWidth < 3
+ then ""
+ else "[width=" ++
+ show ((markerWidth + 2) `div` 2) ++ "em]"
+ return $ "\\startitemize" ++ markerWidth' ++ "\n" ++ concat contents ++
+ "\\stopitemize\n"
blockToConTeXt (DefinitionList lst) =
mapM defListItemToConTeXt lst >>= (return . (++ "\n") . concat)
blockToConTeXt HorizontalRule = return "\\thinrule\n\n"
@@ -163,6 +174,10 @@ listItemToConTeXt list = do
contents <- blockListToConTeXt list
return $ "\\item " ++ contents
+orderedListItemToConTeXt marker list = do
+ contents <- blockListToConTeXt list
+ return $ "\\sym{" ++ marker ++ "} " ++ contents
+
defListItemToConTeXt (term, def) = do
term' <- inlineListToConTeXt term
def' <- blockListToConTeXt def
diff --git a/src/Text/Pandoc/Writers/Docbook.hs b/src/Text/Pandoc/Writers/Docbook.hs
index 4824f81da..ecd27ee0c 100644
--- a/src/Text/Pandoc/Writers/Docbook.hs
+++ b/src/Text/Pandoc/Writers/Docbook.hs
@@ -173,8 +173,21 @@ blockToDocbook opts (CodeBlock str) =
text "
and now 3
with a continuation
Nesting:
Autonumbering:
--+ do laundry @@ -321,7 +321,7 @@ These should not be escaped: \$ \\ \> \[ \{ Tight: -+ First @@ -341,7 +341,7 @@ These should not be escaped: \$ \\ \> \[ \{ and: -+ One @@ -361,7 +361,7 @@ These should not be escaped: \$ \\ \> \[ \{ Loose using tabs: -+ First @@ -381,7 +381,7 @@ These should not be escaped: \$ \\ \> \[ \{ and using spaces: -+ One @@ -401,7 +401,7 @@ These should not be escaped: \$ \\ \> \[ \{ Multiple paragraphs: -+ Item 1, graf one. @@ -449,7 +449,7 @@ These should not be escaped: \$ \\ \> \[ \{ Here's another: -+ First @@ -486,7 +486,7 @@ These should not be escaped: \$ \\ \> \[ \{ Same thing but with paragraphs: -+ + First @@ -548,6 +548,101 @@ These should not be escaped: \$ \\ \> \[ \{ + Fancy list markers ++ ++ ++ begins with 2 + ++ ++ and now 3 + ++ with a continuation + ++ ++ ++ sublist with roman numerals, starting with 4 + ++ ++ more items + ++ ++ ++ a subsublist + ++ ++ a subsublist + ++ Nesting: + ++ ++ ++ Upper Alpha + ++ ++ ++ Upper Roman. + ++ ++ ++ Decimal start with 6 + ++ ++ ++ Lower alpha with paren + ++ Autonumbering: + ++ ++ ++ Autonumber. + ++ ++ More. + ++ ++ ++ Nested. + +Definition Lists @@ -1158,7 +1253,7 @@ or here: <http://example.com/>
A list:
- do laundry
- Ordered
Tight:
- First
and:
- One
Loose using tabs:
First
and using spaces:
One
Multiple paragraphs:
Item 1, graf one.
Here’s another:
- First
Same thing but with paragraphs:
First
Fancy list markers
- begins with 2
and now 3
with a continuation
- sublist with roman numerals, starting with 4
- more items
- a subsublist
- a subsublist
Nesting:
- Upper Alpha
- Upper Roman.
- Decimal start with 6
- Lower alpha with paren
Autonumbering:
- Autonumber.
- More.
- Nested.
Definition Lists
'+''+e+''+'<\/'+ >