]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Wiki/Parser.hs
Wrote many...
[Rakka.git] / Rakka / Wiki / Parser.hs
index eb236ce1e54e57bab3d8c22cbd4e7433d193dc31..6e4edeb4bc5c604aab1f6e97c0080471c1ebeff4 100644 (file)
@@ -73,16 +73,15 @@ horizontalLine = try ( do count 4 (char '-')
 
 
 listElement :: CommandTypeOf -> Parser BlockElement
-listElement cmdTypeOf = listElement' [] >>= return . List
+listElement cmdTypeOf = listElement' []
     where
-      listElement' :: [Char] -> Parser ListElement
+      listElement' :: [Char] -> Parser BlockElement
       listElement' stack
           = do t  <- oneOf "*#"
                ws
                xs <- items (stack ++ [t])
-               return (ListElement (toType t) xs)
+               return (List (toType t) xs)
 
-      -- ListItem の終了條件は、
       items :: [Char] -> Parser [ListItem]
       items stack = do xs     <- many1 $ inlineElement cmdTypeOf
                        nested <- option Nothing
@@ -91,7 +90,7 @@ listElement cmdTypeOf = listElement' [] >>= return . List
                                             string stack
                                             listElement' stack >>= return . Just
                        rest <- items stack
-                       return $ (map Right xs ++ map Left (catMaybes [nested])) : rest
+                       return $ (map Inline xs ++ map Block (catMaybes [nested])) : rest
                     <|>
                     (try $ do skipMany comment
                               newline
@@ -271,9 +270,9 @@ blockCmd cmdTypeOf
       undefinedCmdErr :: String -> BlockElement
       undefinedCmdErr name
           = Div [("class", "error")]
-            [ Paragraph [Text ("The command `" ++ name ++ "' is not defined. " ++
-                               "Make sure you haven't mistyped.")
-                        ]
+            [ Block (Paragraph [Text ("The command `" ++ name ++ "' is not defined. " ++
+                                      "Make sure you haven't mistyped.")
+                               ])
             ]
 
 
@@ -283,6 +282,7 @@ inlineElement cmdTypeOf
                foldr (<|>) pzero [ cdata
                                  , apostrophes cmdTypeOf
                                  , text
+                                 , objLink
                                  , pageLink
                                  , extLink
                                  , inlineCmd cmdTypeOf
@@ -344,6 +344,17 @@ apostrophes cmdTypeOf = foldr (<|>) pzero (map try [apos1, apos2, apos3, apos4,
       apos n = count n (char '\'') >> notFollowedBy (char '\'')
 
 
+objLink :: Parser InlineElement
+objLink = do try (string "[[[")
+             page <- many1 (noneOf "|]")
+             text <- option Nothing
+                     (char '|' >> many1 (satisfy (/= ']')) >>= return . Just)
+             string "]]]"
+             return $ ObjectLink page text
+          <?>
+          "object link"
+
+
 pageLink :: Parser InlineElement
 pageLink = do try (string "[[")
               page     <- option Nothing