From 2e097f3dc350d767bc2db67a01dc00ee8e1a34a1 Mon Sep 17 00:00:00 2001 From: Yuki Izumi Date: Fri, 4 Aug 2017 18:08:08 +1000 Subject: [PATCH 1/2] Add Strikethrough to Data.Syntax.Markup --- src/Data/Syntax/Markup.hs | 6 ++++++ src/Language/Markdown/Syntax.hs | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Data/Syntax/Markup.hs b/src/Data/Syntax/Markup.hs index e72b027b4..32e524b00 100644 --- a/src/Data/Syntax/Markup.hs +++ b/src/Data/Syntax/Markup.hs @@ -110,3 +110,9 @@ data LineBreak a = LineBreak instance Eq1 LineBreak where liftEq = genericLiftEq instance Show1 LineBreak where liftShowsPrec = genericLiftShowsPrec + +newtype Strikethrough a = Strikethrough [a] + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Show, Traversable) + +instance Eq1 Strikethrough where liftEq = genericLiftEq +instance Show1 Strikethrough where liftShowsPrec = genericLiftShowsPrec diff --git a/src/Language/Markdown/Syntax.hs b/src/Language/Markdown/Syntax.hs index b8fcdd355..ea0dfaea2 100644 --- a/src/Language/Markdown/Syntax.hs +++ b/src/Language/Markdown/Syntax.hs @@ -41,6 +41,7 @@ type Syntax = , Markup.Link , Markup.Strong , Markup.Text + , Markup.Strikethrough -- Assignment errors; cmark does not provide parse errors. , Syntax.Error , [] @@ -94,7 +95,7 @@ htmlBlock = makeTerm <$> symbol HTMLBlock <*> (Markup.HTMLBlock <$> source) -- Inline elements inlineElement :: Assignment -inlineElement = strong <|> emphasis <|> text <|> link <|> htmlInline <|> image <|> code <|> lineBreak <|> softBreak +inlineElement = strong <|> emphasis <|> strikethrough <|> text <|> link <|> htmlInline <|> image <|> code <|> lineBreak <|> softBreak strong :: Assignment strong = makeTerm <$> symbol Strong <*> children (Markup.Strong <$> many inlineElement) @@ -102,6 +103,9 @@ strong = makeTerm <$> symbol Strong <*> children (Markup.Strong <$> many inlineE emphasis :: Assignment emphasis = makeTerm <$> symbol Emphasis <*> children (Markup.Emphasis <$> many inlineElement) +strikethrough :: Assignment +strikethrough = makeTerm <$> symbol Strikethrough <*> children (Markup.Strikethrough <$> many inlineElement) + text :: Assignment text = makeTerm <$> symbol Text <*> (Markup.Text <$> source) From 882c35649ec6bfb459df192c46c2334ae999d666 Mon Sep 17 00:00:00 2001 From: Yuki Izumi Date: Mon, 7 Aug 2017 13:49:21 +1000 Subject: [PATCH 2/2] Add table syntax elements --- src/Data/Syntax/Markup.hs | 18 ++++++++++++++++++ src/Language/Markdown/Syntax.hs | 13 ++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Data/Syntax/Markup.hs b/src/Data/Syntax/Markup.hs index 32e524b00..953e5b61d 100644 --- a/src/Data/Syntax/Markup.hs +++ b/src/Data/Syntax/Markup.hs @@ -66,6 +66,24 @@ data HTMLBlock a = HTMLBlock ByteString instance Eq1 HTMLBlock where liftEq = genericLiftEq instance Show1 HTMLBlock where liftShowsPrec = genericLiftShowsPrec +newtype Table a = Table [a] + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Show, Traversable) + +instance Eq1 Table where liftEq = genericLiftEq +instance Show1 Table where liftShowsPrec = genericLiftShowsPrec + +newtype TableRow a = TableRow [a] + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Show, Traversable) + +instance Eq1 TableRow where liftEq = genericLiftEq +instance Show1 TableRow where liftShowsPrec = genericLiftShowsPrec + +newtype TableCell a = TableCell [a] + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Show, Traversable) + +instance Eq1 TableCell where liftEq = genericLiftEq +instance Show1 TableCell where liftShowsPrec = genericLiftShowsPrec + -- Inline elements diff --git a/src/Language/Markdown/Syntax.hs b/src/Language/Markdown/Syntax.hs index ea0dfaea2..403029feb 100644 --- a/src/Language/Markdown/Syntax.hs +++ b/src/Language/Markdown/Syntax.hs @@ -33,6 +33,9 @@ type Syntax = , Markup.Section , Markup.ThematicBreak , Markup.UnorderedList + , Markup.Table + , Markup.TableRow + , Markup.TableCell -- Inline elements , Markup.Code , Markup.Emphasis @@ -58,7 +61,7 @@ assignment = makeTerm <$> symbol Document <*> children (Markup.Document <$> many -- Block elements blockElement :: Assignment -blockElement = paragraph <|> list <|> blockQuote <|> codeBlock <|> thematicBreak <|> htmlBlock <|> section +blockElement = paragraph <|> list <|> blockQuote <|> codeBlock <|> thematicBreak <|> htmlBlock <|> section <|> table paragraph :: Assignment paragraph = makeTerm <$> symbol Paragraph <*> children (Markup.Paragraph <$> many inlineElement) @@ -91,6 +94,14 @@ thematicBreak = makeTerm <$> symbol ThematicBreak <*> pure Markup.ThematicBreak htmlBlock :: Assignment htmlBlock = makeTerm <$> symbol HTMLBlock <*> (Markup.HTMLBlock <$> source) +table :: Assignment +table = makeTerm <$> symbol Table <*> children (Markup.Table <$> many tableRow) + +tableRow :: Assignment +tableRow = makeTerm <$> symbol TableRow <*> children (Markup.TableRow <$> many tableCell) + +tableCell :: Assignment +tableCell = makeTerm <$> symbol TableCell <*> children (Markup.TableCell <$> many inlineElement) -- Inline elements