我正在使用Text.ParserCombinators.Parsec和Text.XHtml来解析这样的输入:
- 第一个类型 A\n -- 第一个类型 B\n - 第二种 A\n -- 第一个类型 B\n --第二种类型B\n
我的输出应该是:
<h1>1 First type A\n</h1>
<h2>1.1 First type B\n</h2>
<h1>2 Second type A\n</h2>
<h2>2.1 First type B\n</h2>
<h2>2.2 Second type B\n</h2>
我已经到了这一部分,但我无法进一步了解:
title1= do{
;(count 1 (char '-'))
;s <- many1 anyChar newline
;return (h1 << s)
}
title2= do{
;(count 2 (char '--'))
;s <- many1 anyChar newline
;return (h1 << s)
}
text=do {
;many (choice [try(title1),try(title2)])
}
main :: IO ()
main = do t putStr "Error: " >> print err
Right x -> putStrLn $ prettyHtml x
这没关系,但它不包括编号。
有任何想法吗?
谢谢!