git.iko.soy/typeable/pandoc
on master help sign in
Added support for definition lists to LaTeX reader.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@780 788f1e2b-df1e-0410-8736-df70ead52e1b

commit1296273c8577465a1bb17161909c2596f84c8bd8 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateMon 23 Jul 2007, 00:19 (19 years ago) parentcaef362
1 file changed+23−11
src/Text/Pandoc/Readers/LaTeX.hs+23−11
src/Text/Pandoc/Readers/LaTeX.hs+23−11
@@ -39,6 +39,7 @@ import Text.Pandoc.Definition
3939import Text.Pandoc.Shared
4040import Data.Maybe ( fromMaybe )
4141import Data.Char ( chr )
42+import Data.List ( isPrefixOf, isSuffixOf )
4243
4344-- | Parse LaTeX from string and return 'Pandoc' document.
4445readLaTeX :: ParserState -- ^ Parser state, including options for parser
@@ -228,33 +229,45 @@ mathBlockWith start end = try (do
228229-- list blocks
229230--
230231
231−list = bulletList <|> orderedList <?> "list"
232+list = bulletList <|> orderedList <|> definitionList <?> "list"
232233
233−listItem = try (do
234− ("item", _, _) <- command
234+listItem = try $ do
235+ ("item", _, args) <- command
235236 spaces
236237 state <- getState
237238 let oldParserContext = stateParserContext state
238239 updateState (\state -> state {stateParserContext = ListItemState})
239240 blocks <- many block
240241 updateState (\state -> state {stateParserContext = oldParserContext})
241− return blocks)
242+ opt <- case args of
243+ ([x]) | "[" `isPrefixOf` x && "]" `isSuffixOf` x ->
244+ parseFromString (many inline) $ tail $ init x
245+ _ -> return []
246+ return (opt, blocks)
242247
243−orderedList = try (do
248+orderedList = try $ do
244249 begin "enumerate"
245250 spaces
246251 items <- many listItem
247252 end "enumerate"
248253 spaces
249− return (OrderedList items))
254+ return (OrderedList $ map snd items)
250255
251−bulletList = try (do
256+bulletList = try $ do
252257 begin "itemize"
253258 spaces
254259 items <- many listItem
255260 end "itemize"
256261 spaces
257− return (BulletList items))
262+ return (BulletList $ map snd items)
263+
264+definitionList = try $ do
265+ begin "description"
266+ spaces
267+ items <- many listItem
268+ end "description"
269+ spaces
270+ return (DefinitionList items)
258271
259272--
260273-- paragraph block
@@ -353,9 +366,8 @@ unknownEnvironment = try (do
353366 return result)
354367
355368unknownCommand = try (do
356− notFollowedBy' (string "\\end{itemize}")
357− notFollowedBy' (string "\\end{enumerate}")
358− notFollowedBy' (string "\\end{document}")
369+ notFollowedBy' $ choice $ map end
370+ ["itemize", "enumerate", "description", "document"]
359371 (name, star, args) <- command
360372 spaces
361373 let argStr = concat args