, ListElement(..)
, ListType(..)
, ListItem
+
+ , Definition(..)
)
where
}
| HorizontalLine
| List !ListElement
+ | DefinitionList ![Definition]
| LeadingSpaced ![InlineElement]
| Paragraph ![InlineElement]
deriving (Eq, Show)
type ListItem = [Either ListElement InlineElement]
+
+
+data Definition
+ = Definition {
+ defTerm :: ![InlineElement]
+ , defDesc :: ![InlineElement]
+ }
+ deriving (Eq, Show)
\ No newline at end of file
List list
-> formatListElement -< (baseURI, list)
+ DefinitionList list
+ -> formatDefinitionList -< (baseURI, list)
+
LeadingSpaced inlines
-> formatLeadingSpaced -< (baseURI, inlines)
Right inline -> formatInline -< (baseURI, inline )
+formatDefinitionList :: (ArrowXml a, ArrowChoice a) => a (URI, [Definition]) XmlTree
+formatDefinitionList
+ = proc (baseURI, list)
+ -> ( eelem "dl"
+ += ( (arr fst &&& arrL snd)
+ >>>
+ formatDefinition
+ )
+ ) -< (baseURI, list)
+ where
+ formatDefinition :: (ArrowXml a, ArrowChoice a) => a (URI, Definition) XmlTree
+ formatDefinition
+ = proc (baseURI, def)
+ -> ( eelem "dt"
+ += ( (arr fst &&& arrL (defTerm . snd))
+ >>>
+ formatInline
+ )
+ <+>
+ eelem "dd"
+ += ( (arr fst &&& arrL (defDesc . snd))
+ >>>
+ formatInline
+ )
+ ) -< (baseURI, def)
+
+
formatLeadingSpaced :: (ArrowXml a, ArrowChoice a) => a (URI, [InlineElement]) XmlTree
formatLeadingSpaced
= eelem "pre"
<|>
listElement
<|>
+ definitionList
+ <|>
leadingSpaced
<|>
paragraph
)
<|>
return []
-{-
- items stack = do nested <- listElement' stack
- rest <- items stack
- return (Left nested : rest)
- <|>
- do xs <- many1 inlineElement
- rest <- items stack
- return (Right xs : rest)
- <|>
- try ( newline
- >>
- string stack
- >>
- items stack
- )
- <|>
- return []
--}
toType :: Char -> ListType
toType '*' = Bullet
toType '#' = Numbered
+definitionList :: Parser BlockElement
+definitionList = many1 definition >>= return . DefinitionList
+ where
+ definition :: Parser Definition
+ definition = do char ';'
+ ws
+ tHead <- inlineElement
+ tRest <- term
+ d <- description
+ return (Definition (tHead:tRest) d)
+ <?>
+ "definition list"
+
+ term :: Parser [InlineElement]
+ term = (char ':' >> ws >> return [])
+ <|>
+ (newline >> char ':' >> ws >> return [])
+ <|>
+ do x <- inlineElement
+ xs <- term
+ return (x:xs)
+ <?>
+ "term to be defined"
+
+ description :: Parser [InlineElement]
+ description = do x <- inlineElement
+ xs <- description
+ return (x:xs)
+ <|>
+ try ( do newline
+ char ':'
+ ws
+ xs <- description
+ return (Text "\n" : xs)
+ )
+ <|>
+ (newline >> return [])
+ <|>
+ (eof >> return [])
+ <?>
+ "description of term"
+
+
leadingSpaced :: Parser BlockElement
leadingSpaced = char ' ' >> leadingSpaced' >>= return . LeadingSpaced
where
text :: Parser InlineElement
-text = many1 (noneOf ('\n':inlineSymbols)) >>= return . Text
+text = ( char ':'
+ >>
+ many (noneOf ('\n':':':inlineSymbols))
+ >>=
+ return . Text . (':' :)
+ -- 定義リストとの關係上、コロンは先頭にしか存在できない。
+ )
+ <|>
+ ( many1 (noneOf ('\n':':':inlineSymbols))
+ >>=
+ return . Text
+ )
pageLink :: Parser InlineElement
blockSymbols :: [Char]
-blockSymbols = " =-*#"
+blockSymbols = " =-*#;"
inlineSymbols :: [Char]
* bar
** baz
+aaaaa
+
# foo
## bar
### baz
*#* baz
*# bar
+== Definition ==
+; AAA : aaaaaaaaaaaaaaaaa
+; BBBBBBBBB
+: bbb
+: ccccccccccc
+
== Link ==
-[[Page]]
-[[page]]
-[[space in a page name]]
-[[Page|Link to "Page"]]
-[[Page#Heading]]
-[[#Heading]]
-[[Page#Heading|Link to "Page#Heading"]]
-[[#example]]
+* [[Page]]
+* [[page]]
+* [[space in a page name]]
+* [[Page|Link to "Page"]]
+* [[Page#Heading]]
+* [[#Heading]]
+* [[Page#Heading|Link to "Page#Heading"]]
+* [[#example]]
</textData>
</page>
margin-left: 20px;
}
+.body dl {
+ margin: 1em 2em;
+}
+.body dt {
+ font-weight: bold;
+}
+.body dd {
+ margin-left: 3em;
+ margin-top: 0.1em;
+}
+.body dd + dt {
+ margin-top: 0.9em;
+}
+
.side-bar .content {
padding: 20px;
}
(Right [ List (ListElement Bullet [ [Right (Text "a")] ])
, List (ListElement Numbered [ [Right (Text "b")] ])
]))
+
+ , (parseWiki "foo:bar"
+ ~?=
+ (Right [ Paragraph [ Text "foo"
+ , Text ":bar"
+ ]
+ ]))
+
+ , (parseWiki "; foo: bar"
+ ~?=
+ (Right [ DefinitionList [Definition [Text "foo"] [Text "bar"]] ]))
+
+ , (parseWiki "; foo: bar\n"
+ ~?=
+ (Right [ DefinitionList [Definition [Text "foo"] [Text "bar"]] ]))
+
+ , (parseWiki "; foo\n: bar\n; bar\n: baz\n: baz"
+ ~?=
+ (Right [ DefinitionList [ Definition [Text "foo"] [ Text "bar" ]
+ , Definition [Text "bar"] [ Text "baz"
+ , Text "\n"
+ , Text "baz" ]
+ ]
+ ]))
]