From: pho Date: Sat, 13 Oct 2007 05:18:22 +0000 (+0900) Subject: implemented more markup stuffs X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=c2cc1241c50c8ff3843002526011574e77f669aa;p=Rakka.git implemented more markup stuffs darcs-hash:20071013051822-62b54-f1342a9067c1eb376d74591fd70ee2bb691c9097.gz --- diff --git a/Rakka/Wiki.hs b/Rakka/Wiki.hs index 9f8bcdc..b8be3a3 100644 --- a/Rakka/Wiki.hs +++ b/Rakka/Wiki.hs @@ -25,13 +25,15 @@ data BlockElement | HorizontalLine | List !ListElement | DefinitionList ![Definition] - | LeadingSpaced ![InlineElement] + | Preformatted ![InlineElement] | Paragraph ![InlineElement] deriving (Eq, Show) data InlineElement = Text !String + | Italic ![InlineElement] + | Bold ![InlineElement] | PageLink { linkPage :: !(Maybe PageName) , linkFragment :: !(Maybe String) diff --git a/Rakka/Wiki/Formatter.hs b/Rakka/Wiki/Formatter.hs index 1792299..95dd9ff 100644 --- a/Rakka/Wiki/Formatter.hs +++ b/Rakka/Wiki/Formatter.hs @@ -38,8 +38,8 @@ formatBlock DefinitionList list -> formatDefinitionList -< (baseURI, list) - LeadingSpaced inlines - -> formatLeadingSpaced -< (baseURI, inlines) + Preformatted inlines + -> formatPreformatted -< (baseURI, inlines) Paragraph inlines -> formatParagraph -< (baseURI, inlines) @@ -109,8 +109,8 @@ formatDefinitionList ) -< (baseURI, def) -formatLeadingSpaced :: (ArrowXml a, ArrowChoice a) => a (URI, [InlineElement]) XmlTree -formatLeadingSpaced +formatPreformatted :: (ArrowXml a, ArrowChoice a) => a (URI, [InlineElement]) XmlTree +formatPreformatted = eelem "pre" += ( (arr fst &&& arrL snd) >>> @@ -134,6 +134,22 @@ formatInline Text text -> mkText -< text + Italic inlines + -> ( eelem "i" + += ( (arr fst &&& arrL snd) + >>> + formatInline + ) + ) -< (baseURI, inlines) + + Bold inlines + -> ( eelem "b" + += ( (arr fst &&& arrL snd) + >>> + formatInline + ) + ) -< (baseURI, inlines) + link@(PageLink _ _ _) -> formatPageLink -< (baseURI, link) diff --git a/Rakka/Wiki/Parser.hs b/Rakka/Wiki/Parser.hs index 017df89..db26a49 100644 --- a/Rakka/Wiki/Parser.hs +++ b/Rakka/Wiki/Parser.hs @@ -32,6 +32,8 @@ blockElement = skipMany ( comment <|> definitionList <|> + pdata + <|> leadingSpaced <|> paragraph @@ -59,11 +61,14 @@ heading = foldr (<|>) pzero (map heading' [1..5]) horizontalLine :: Parser BlockElement -horizontalLine = try $ do count 4 (char '-') +horizontalLine = try ( do count 4 (char '-') many (char '-') ws eol return HorizontalLine + ) + + "horizontal line" listElement :: Parser BlockElement @@ -142,8 +147,25 @@ definitionList = many1 definition >>= return . DefinitionList "description of term" +pdata :: Parser BlockElement +pdata = do try (string "> string "]]>") + return [] + <|> + do x <- anyChar + xs <- pdata' + return (x:xs) + + leadingSpaced :: Parser BlockElement -leadingSpaced = char ' ' >> leadingSpaced' >>= return . LeadingSpaced +leadingSpaced = (char ' ' >> leadingSpaced' >>= return . Preformatted) + + "leading space" where leadingSpaced' :: Parser [InlineElement] leadingSpaced' = do x <- inlineElement @@ -200,29 +222,73 @@ paragraph = paragraph' >>= return . Paragraph inlineElement :: Parser InlineElement inlineElement = skipMany comment >> - ( try text + ( cdata + <|> + apostrophes <|> - try pageLink + text + <|> + pageLink ) +cdata :: Parser InlineElement +cdata = try (string "> cdata' >>= return . Text + where + cdata' :: Parser String + cdata' = do try (string "]]>") + return [] + <|> + do x <- anyChar + xs <- cdata' + return (x:xs) + + text :: Parser InlineElement text = ( char ':' >> - many (noneOf ('\n':':':inlineSymbols)) + many (noneOf ('\n':inlineSymbols)) >>= return . Text . (':' :) - -- 定義リストとの關係上、コロンは先頭にしか存在できない。 + -- 定義リストとの關係上、コロンは先頭にしか來れない。 ) <|> - ( many1 (noneOf ('\n':':':inlineSymbols)) + ( many1 (noneOf ('\n':inlineSymbols)) >>= return . Text ) + + "text" + + +apostrophes :: Parser InlineElement +apostrophes = foldr (<|>) pzero (map try [apos1, apos2, apos3, apos4, apos5]) + where + apos1 = apos 1 >> return (Text "'") + + apos2 = do apos 2 + xs <- many1 inlineElement + apos 2 + return (Italic xs) + + apos3 = do apos 3 + xs <- many1 inlineElement + apos 3 + return (Bold xs) + + apos4 = apos 4 >> return (Text "'") + + apos5 = do apos 5 + xs <- many1 inlineElement + apos 5 + return (Italic [Bold xs]) + + apos :: Int -> Parser () + apos n = count n (char '\'') >> notFollowedBy (char '\'') pageLink :: Parser InlineElement -pageLink = do string "[[" +pageLink = do try (string "[[") page <- option Nothing (many1 (noneOf "#|]") >>= return . Just) fragment <- option Nothing @@ -261,7 +327,7 @@ blockSymbols = " =-*#;" inlineSymbols :: [Char] -inlineSymbols = "<[" +inlineSymbols = "<[:'" -- white space ws :: Parser () diff --git a/defaultPages/Help/Syntax b/defaultPages/Help/Syntax index 88f758c..c742612 100644 --- a/defaultPages/Help/Syntax +++ b/defaultPages/Help/Syntax @@ -12,17 +12,31 @@ ===== Heading 5 ===== -== &lt;nowiki&gt; tags == -<nowiki> +== Italic and bold == +You can ''italicize text'' by putting 2 +apostrophes on each side. + +3 apostrophes will bold '''the text'''. + +5 apostrophes will bold and italicize +'''''the text'''''. + +(Using 4 apostrophes doesn't do anything +special -- there are just '''' left +over ones'''' that are included as part of the text.) + + +== CDATA section == +<![CDATA[ [[Wiki]] markup is ignored here but the text is reformatted. -</nowiki> +]]> -== &lt;pre&gt; tags == -<pre> +== PDATA section == +<![PDATA[ [[Wiki]] markup is ignored here and reformatting is also disabled. -</pre> +]]> == Leading spaces == This @@ -34,6 +48,13 @@ but the text is reformatted. == Horizontal Line == ---- +== Inline Object == +<object data="Foo" float="right" framed="yes"> + This is a caption containing [[Foo|markups]]. +</object> + +blah blah blah... + == Quotation == <blockquote> blah blah blah... diff --git a/defaultPages/MainPage b/defaultPages/MainPage index 5ae8b00..69c5ece 100644 --- a/defaultPages/MainPage +++ b/defaultPages/MainPage @@ -8,15 +8,30 @@ Hello, world! Another paragraph... -= Syntax Help = +== Italic and bold == +You can ''italicize text'' by putting 2 +apostrophes on each side. -== Heading == +3 apostrophes will bold '''the text'''. -=== Heading 3 === +5 apostrophes will bold and italicize +'''''the text'''''. -==== Heading 4 ==== +(Using 4 apostrophes doesn't do anything +special -- there are just '''' left +over ones'''' that are included as part of the text.) -===== Heading 5 ===== +== CDATA section == +<![CDATA[ +[[Wiki]] markup is ignored here +but the text is reformatted. +]]> + +== PDATA section == +<![PDATA[ +[[Wiki]] markup is ignored here + and reformatting is also disabled. +]]> == Leading spaces == This @@ -24,40 +39,5 @@ Another paragraph... preformatted text. [[Foo|Wiki markup is interpreted here.]] - -== Horizontal Line == ----- - -== Listing == -* foo -* bar -** baz - -aaaaa - -# foo -## bar -### baz - -* foo -*# bar -*#* 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]] diff --git a/test/WikiParserTest.hs b/test/WikiParserTest.hs index 5434015..384cc5f 100644 --- a/test/WikiParserTest.hs +++ b/test/WikiParserTest.hs @@ -151,21 +151,21 @@ testData = [ (parseWiki "" , (parseWiki " foo" ~?= - (Right [ LeadingSpaced [ Text "foo" ] ])) + (Right [ Preformatted [ Text "foo" ] ])) , (parseWiki " foo\n bar\n" ~?= - (Right [ LeadingSpaced [ Text "foo" - , Text "\n" - , Text " bar" - ] + (Right [ Preformatted [ Text "foo" + , Text "\n" + , Text " bar" + ] ])) , (parseWiki "foo\n bar\nbaz" ~?= - (Right [ Paragraph [ Text "foo" ] - , LeadingSpaced [ Text "bar" ] - , Paragraph [ Text "baz" ] + (Right [ Paragraph [ Text "foo" ] + , Preformatted [ Text "bar" ] + , Paragraph [ Text "baz" ] ])) , (parseWiki "----" @@ -239,4 +239,42 @@ testData = [ (parseWiki "" , Text "baz" ] ] ])) + + , (parseWiki "" + ~?= + (Right [ Paragraph [ Text "foo [[bar]] baz" ] ])) + + , (parseWiki "" + ~?= + (Right [ Preformatted [ Text "foo [[bar]] baz" ] ])) + + , (parseWiki "" + ~?= + (Right [ Preformatted [ Text "foo [[bar]] baz" ] ])) + + , (parseWiki "foo' bar" + ~?= + (Right [ Paragraph [ Text "foo" + , Text "'" + , Text " bar" ] + ])) + + , (parseWiki "''foo''" + ~?= + (Right [ Paragraph [ Italic [Text "foo"] ] ])) + + , (parseWiki "'''foo'''" + ~?= + (Right [ Paragraph [ Bold [Text "foo"] ] ])) + + , (parseWiki "foo''''" + ~?= + (Right [ Paragraph [ Text "foo" + , Text "'" + ] + ])) + + , (parseWiki "'''''foo'''''" + ~?= + (Right [ Paragraph [ Italic [Bold [Text "foo"]] ] ])) ]