jira-wiki-markup 1.2.0 → 1.2.1
raw patch · 10 files changed
+78/−19 lines, 10 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.Jira.Parser.Shared: colorName :: Parsec Text u String
Files
- CHANGELOG.md +23/−0
- jira-wiki-markup.cabal +1/−1
- src/Text/Jira/Parser/Block.hs +3/−5
- src/Text/Jira/Parser/Core.hs +2/−0
- src/Text/Jira/Parser/Inline.hs +1/−4
- src/Text/Jira/Parser/Shared.hs +6/−0
- src/Text/Jira/Printer.hs +8/−4
- test/Text/Jira/Parser/BlockTests.hs +23/−3
- test/Text/Jira/Parser/InlineTests.hs +2/−2
- test/Text/Jira/PrinterTests.hs +9/−0
CHANGELOG.md view
@@ -4,6 +4,29 @@ `jira-wiki-markup` uses [PVP Versioning][1]. The changelog is available [on GitHub][2]. +1.2.1+-----++Released 2020-04-02++* Fixed rendering of image attributes: image attributes are+ separated by commas instead of pipes; the latter are used in+ block parameters.++* Fixed parsing of blockquotes which are not preceeded by blank+ lines.++* Ensure parsing of single-line blockquotes is possible even if+ there is no space between `bq.` marker and contents.++* Fixed parsing of colors: parsing no longer fails for hexcolors+ which contain non-decimal digits.++* Changes to module `Text.Jira.Parser.Shared`:++ - New parsing function `colorName` which parses a color+ descriptor, i.e. either a name or a hexcolor.+ 1.2.0 -----
jira-wiki-markup.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.0 name: jira-wiki-markup-version: 1.2.0+version: 1.2.1 synopsis: Handle Jira wiki markup description: Parse jira wiki text into an abstract syntax tree for easy transformation to other formats.
src/Text/Jira/Parser/Block.hs view
@@ -30,6 +30,7 @@ import Text.Jira.Markup import Text.Jira.Parser.Core import Text.Jira.Parser.Inline+import Text.Jira.Parser.Shared (colorName) import Text.Parsec -- | Parses any block element.@@ -166,7 +167,7 @@ blockQuote = try $ singleLineBq <|> multiLineBq where singleLineBq = BlockQuote . (:[]) . Para <$>- (string "bq. " *> skipMany (char ' ') *>+ (string "bq." *> skipMany (char ' ') *> inline `manyTill` (void newline <|> eof)) multiLineBq = BlockQuote <$> (string "{quote}" *> optional blankline *>@@ -194,12 +195,9 @@ -- | Parses colored text into a @'Color'@ element. color :: JiraParser Block color= try $ do- name <- string "{color:" *> (colorName <|> colorCode) <* char '}'+ name <- string "{color:" *> colorName <* char '}' content <- block `manyTill` try (string "{color}" *> blankline) return $ Color (ColorName $ pack name) content- where- colorName = many letter- colorCode = optional (char '#') *> count 6 digit -- | Skip whitespace till we reach the next block skipWhitespace :: JiraParser ()
src/Text/Jira/Parser/Core.hs view
@@ -136,12 +136,14 @@ endOfPara = eof <|> lookAhead blankline <|> lookAhead headerStart+ <|> lookAhead quoteStart <|> lookAhead horizontalRule <|> lookAhead listItemStart <|> lookAhead tableStart <|> lookAhead panelStart where headerStart = void $ char 'h' *> oneOf "123456" <* char '.'+ quoteStart = void $ string "bq." listItemStart = void $ skipSpaces *> many1 (oneOf "#*-") <* char ' ' tableStart = void $ skipSpaces *> many1 (char '|') panelStart = void $ char '{' *> choice (map (try . string) blockNames)
src/Text/Jira/Parser/Inline.hs view
@@ -207,12 +207,9 @@ -- | Text in a different color. colorInline :: JiraParser Inline colorInline = try $ do- name <- string "{color:" *> (colorName <|> colorCode) <* char '}'+ name <- string "{color:" *> colorName <* char '}' content <- inline `manyTill` try (string "{color}") return $ ColorInline (ColorName $ pack name) content- where- colorName = many1 letter- colorCode = (:) <$> option '#' (char '#') <*> count 6 digit -- -- Markup
@@ -12,6 +12,7 @@ -} module Text.Jira.Parser.Shared ( icon+ , colorName ) where import Data.Char (isLetter)@@ -60,3 +61,8 @@ "flag" -> pure IconFlag "flagoff" -> pure IconFlagOff _ -> fail ("not a known emoji" ++ name)++colorName :: Parsec Text u String+colorName = many1 letter <|> hexColor+ where+ hexColor = (:) <$> option '#' (char '#') <*> count 6 hexDigit
src/Text/Jira/Printer.hs view
@@ -226,10 +226,7 @@ prettyInlines ils <> "{color}" Emoji icon -> iconText icon Entity entity -> "&" <> entity <> ";"- Image params url -> "!" <> urlText url <>- if null params- then "!"- else "|" <> renderParams params <> "!"+ Image ps url -> "!" <> urlText url <> renderImageParams ps <> "!" Linebreak -> "\n" Link inlines (URL url) -> "[" <> prettyInlines inlines <> "|" <> url <> "]" Monospaced inlines -> "{{" <> prettyInlines inlines <> "}}"@@ -258,6 +255,13 @@ -- | Text rendering of an URL. urlText :: URL -> Text urlText (URL url) = url++-- | Render image parameters (i.e., separate by comma).+renderImageParams :: [Parameter] -> Text+renderImageParams = \case+ [] -> ""+ ps | "thumbnail" `elem` map parameterKey ps -> "|thumbnail"+ ps -> "|" <> T.intercalate ", " (map renderParam ps) renderWrapped :: Char -> [Inline] -> Text renderWrapped c = T.cons c . flip T.snoc c . prettyInlines
test/Text/Jira/Parser/BlockTests.hs view
@@ -333,10 +333,16 @@ parseJira color "{color:red}This is red.\n{color}\n" @?= Right (Color (ColorName "red") [Para [Str "This", Space, Str "is", Space, Str "red."]])++ , testCase "paragraph preceeded by newline" $+ parseJira color "{color:#cccccc}\nThis is gray.\n{color}\n" @?=+ Right (Color (ColorName "#cccccc")+ [Para [ Linebreak, Str "This", Space+ , Str "is", Space, Str "gray."]]) ] , testGroup "blockQuote"- [ testCase "single line quite before eof" $+ [ testCase "single line right before eof" $ parseJira blockQuote "bq. this text" @?= Right (BlockQuote [Para [Str "this", Space, Str "text"]]) @@ -344,6 +350,10 @@ parseJira blockQuote "bq. this test\n" @?= Right (BlockQuote [Para [Str "this", Space, Str "test"]]) + , testCase "single line w\\o leading space" $+ parseJira blockQuote "bq.another test\n" @?=+ Right (BlockQuote [Para [Str "another", Space, Str "test"]])+ , testCase "multi-paragraph block quote" $ parseJira blockQuote "{quote}\npara1\n\npara2\n{quote}\n" @?= Right (BlockQuote [ Para [Str "para1"]@@ -368,13 +378,23 @@ parseJira ((,) <$> block <*> block) "h2.header\nparagraph\n" @?= Right (Header 2 [Str "header"], Para [Str "paragraph"]) - , testCase "para before horizontal rule " $+ , testCase "para before horizontal rule" $ parseJira ((,) <$> block <*> return HorizontalRule) "paragraph\n----\n" @?= Right (Para [Str "paragraph"], HorizontalRule) - , testCase "para after horizontal rule " $+ , testCase "para after horizontal rule" $ parseJira ((,) <$> block <*> block) "----\nparagraph\n" @?= Right (HorizontalRule, Para [Str "paragraph"])++ , testCase "para before blockquote" $+ parseJira ((,) <$> block <*> block) "before\nbq. a quote\n" @?=+ Right ( Para [Str "before"]+ , BlockQuote [Para [Str "a", Space, Str "quote"]])++ , testCase "para after blockquote" $+ parseJira ((,) <$> block <*> block) "bq. a quote\nafter\n" @?=+ Right ( BlockQuote [Para [Str "a", Space, Str "quote"]]+ , Para [Str "after"] ) , testCase "para after list" $ parseJira ((,) <$> block <*> block) "* foo\n\nbar\n" @?=
test/Text/Jira/Parser/InlineTests.hs view
@@ -279,8 +279,8 @@ Right (ColorInline (ColorName "#526487") [Str "blueish"]) , testCase "hex color without hash" $- parseJira colorInline "{color:526487}blueish{color}" @?=- Right (ColorInline (ColorName "#526487") [Str "blueish"])+ parseJira colorInline "{color:526Ab7}blueish{color}" @?=+ Right (ColorInline (ColorName "#526Ab7") [Str "blueish"]) ] ]
test/Text/Jira/PrinterTests.hs view
@@ -119,6 +119,15 @@ , testCase "Emoji" $ renderInline (Emoji IconSmiling) @?= ":D" + , testCase "thumbnail" $+ renderInline (Image [Parameter "thumbnail" ""] (URL "example.jpg")) @?=+ "!example.jpg|thumbnail!"++ , testCase "image attributes" $+ let params = [Parameter "align" "right", Parameter "vspace" "4"]+ in renderInline (Image params (URL "example.jpg")) @?=+ "!example.jpg|align=right, vspace=4!"+ , testCase "Styled Emphasis" $ renderInline (Styled Emphasis [Str "Hello,", Space, Str "World!"]) @?= "_Hello, World!_"