From 4e1c15d000b88c718f5db9df71befca0b401f5ab Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Sun, 20 Jan 2019 12:10:38 +0100 Subject: [PATCH] refactor(types): use Kind field for quoted text kind (#277) Fixes #275 Signed-off-by: Xavier Coulon --- pkg/parser/delimited_block_test.go | 24 +- pkg/parser/document_attributes_test.go | 4 +- pkg/parser/footnote_test.go | 4 +- pkg/parser/inline_elements_test.go | 12 +- pkg/parser/list_test.go | 12 +- pkg/parser/paragraph_test.go | 8 +- pkg/parser/passthrough_test.go | 8 +- pkg/parser/quoted_text_test.go | 304 +++++++------------------ pkg/parser/section_test.go | 4 +- pkg/parser/table_test.go | 16 +- pkg/renderer/html5/quoted_text.go | 5 +- pkg/types/grammar_types.go | 8 +- pkg/types/grammar_types_utils_test.go | 4 +- 13 files changed, 107 insertions(+), 306 deletions(-) diff --git a/pkg/parser/delimited_block_test.go b/pkg/parser/delimited_block_test.go index fe2a864f..35d3e9b4 100644 --- a/pkg/parser/delimited_block_test.go +++ b/pkg/parser/delimited_block_test.go @@ -495,9 +495,7 @@ with *bold content* Content: "with ", }, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{ Content: "bold content", @@ -691,9 +689,7 @@ ____` Content: "some ", }, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{ Content: "quote", @@ -1055,9 +1051,7 @@ ____` Content: "some ", }, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{ Content: "verse", @@ -1340,7 +1334,7 @@ end ----` expectedResult := types.DelimitedBlock{ Attributes: types.ElementAttributes{ - types.AttrKind: types.Source, + types.AttrKind: types.Source, types.AttrLanguage: "ruby", }, Kind: types.Source, @@ -1389,7 +1383,7 @@ end ----` expectedResult := types.DelimitedBlock{ Attributes: types.ElementAttributes{ - types.AttrKind: types.Source, + types.AttrKind: types.Source, types.AttrLanguage: "ruby", types.AttrID: "id-for-source-block", types.AttrTitle: "app.rb", @@ -1446,9 +1440,7 @@ some *verse* content Content: "some ", }, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{ Content: "verse", @@ -1489,9 +1481,7 @@ bar Content: "some ", }, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{ Content: "verse", diff --git a/pkg/parser/document_attributes_test.go b/pkg/parser/document_attributes_test.go index b6c606fa..ef35f5af 100644 --- a/pkg/parser/document_attributes_test.go +++ b/pkg/parser/document_attributes_test.go @@ -810,9 +810,7 @@ a paragraph with *bold content*` { types.StringElement{Content: "a paragraph with "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold content"}, }, diff --git a/pkg/parser/footnote_test.go b/pkg/parser/footnote_test.go index 0f3d1027..89430f01 100644 --- a/pkg/parser/footnote_test.go +++ b/pkg/parser/footnote_test.go @@ -59,9 +59,7 @@ var _ = Describe("footnotes", func() { Content: "some ", }, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{ Content: "rich", diff --git a/pkg/parser/inline_elements_test.go b/pkg/parser/inline_elements_test.go index 14eb7729..596c8462 100644 --- a/pkg/parser/inline_elements_test.go +++ b/pkg/parser/inline_elements_test.go @@ -12,9 +12,7 @@ var _ = Describe("inline elements", func() { actualContent := "*some bold content*" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "some bold content"}, }, @@ -29,9 +27,7 @@ var _ = Describe("inline elements", func() { expectedResult := types.InlineElements{ types.StringElement{Content: "("}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "some bold content"}, }, @@ -62,9 +58,7 @@ var _ = Describe("inline elements", func() { actualContent := "**foo**bar" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "foo"}, }, diff --git a/pkg/parser/list_test.go b/pkg/parser/list_test.go index 0047d198..207cc056 100644 --- a/pkg/parser/list_test.go +++ b/pkg/parser/list_test.go @@ -1502,9 +1502,7 @@ another fenced block { types.StringElement{Content: "a second item with "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold content"}, }, @@ -1716,9 +1714,7 @@ another fenced block { types.StringElement{Content: "a second item with "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold content"}, }, @@ -1878,9 +1874,7 @@ another fenced block { types.StringElement{Content: "a second item with "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold content"}, }, diff --git a/pkg/parser/paragraph_test.go b/pkg/parser/paragraph_test.go index d1737829..0b4571b6 100644 --- a/pkg/parser/paragraph_test.go +++ b/pkg/parser/paragraph_test.go @@ -44,9 +44,7 @@ var _ = Describe("paragraphs", func() { { types.StringElement{Content: "a paragraph with "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "some bold content"}, }, @@ -288,9 +286,7 @@ this is a }, { types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{ Content: "caution", diff --git a/pkg/parser/passthrough_test.go b/pkg/parser/passthrough_test.go index 5a410844..ac4a13d2 100644 --- a/pkg/parser/passthrough_test.go +++ b/pkg/parser/passthrough_test.go @@ -323,9 +323,7 @@ var _ = Describe("passthroughs", func() { Kind: types.PassthroughMacro, Elements: types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{ Content: "hello", @@ -353,9 +351,7 @@ var _ = Describe("passthroughs", func() { Content: " a ", }, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{ Content: "hello", diff --git a/pkg/parser/quoted_text_test.go b/pkg/parser/quoted_text_test.go index e7926b5a..f38f3bdf 100644 --- a/pkg/parser/quoted_text_test.go +++ b/pkg/parser/quoted_text_test.go @@ -13,9 +13,7 @@ var _ = Describe("quoted texts", func() { It("bold text with 1 word", func() { actualContent := "*hello*" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "hello"}, }, @@ -26,9 +24,7 @@ var _ = Describe("quoted texts", func() { It("bold text with 2 words", func() { actualContent := "*bold content*" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold content"}, }, @@ -39,9 +35,7 @@ var _ = Describe("quoted texts", func() { It("bold text with 3 words", func() { actualContent := "*some bold content*" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "some bold content"}, }, @@ -52,9 +46,7 @@ var _ = Describe("quoted texts", func() { It("italic text with 3 words", func() { actualContent := "_some italic content_" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "some italic content"}, }, @@ -65,9 +57,7 @@ var _ = Describe("quoted texts", func() { It("monospace text with 3 words", func() { actualContent := "`some monospace content`" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "some monospace content"}, }, @@ -78,9 +68,7 @@ var _ = Describe("quoted texts", func() { It("subscript text with 3 words", func() { actualContent := "~some subscript content~" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Subscript, - }, + Kind: types.Subscript, Elements: types.InlineElements{ types.StringElement{Content: "some subscript content"}, }, @@ -91,9 +79,7 @@ var _ = Describe("quoted texts", func() { It("superscript text with 3 words", func() { actualContent := "^some superscript content^" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Superscript, - }, + Kind: types.Superscript, Elements: types.InlineElements{ types.StringElement{Content: "some superscript content"}, }, @@ -104,15 +90,11 @@ var _ = Describe("quoted texts", func() { It("bold text within italic text", func() { actualContent := "_some *bold* content_" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold"}, }, @@ -126,21 +108,15 @@ var _ = Describe("quoted texts", func() { It("monospace text within bold text within italic quote", func() { actualContent := "*some _italic and `monospaced content`_*" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "italic and "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "monospaced content"}, }, @@ -155,15 +131,11 @@ var _ = Describe("quoted texts", func() { It("italic text within italic text", func() { actualContent := "_some _very italic_ content_" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "very italic"}, }, @@ -180,9 +152,7 @@ var _ = Describe("quoted texts", func() { It("bold text of 1 word", func() { actualContent := "**hello**" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "hello"}, }, @@ -193,9 +163,7 @@ var _ = Describe("quoted texts", func() { It("italic text with 3 words", func() { actualContent := "__some italic content__" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "some italic content"}, }, @@ -206,9 +174,7 @@ var _ = Describe("quoted texts", func() { It("monospace text with 3 words", func() { actualContent := "``some monospace content``" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "some monospace content"}, }, @@ -219,9 +185,7 @@ var _ = Describe("quoted texts", func() { It("subscript text with 3 words", func() { actualContent := "~~some subscript content~~" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Subscript, - }, + Kind: types.Subscript, Elements: types.InlineElements{ types.StringElement{Content: "some subscript content"}, }, @@ -234,9 +198,7 @@ var _ = Describe("quoted texts", func() { expectedResult := types.InlineElements{ types.StringElement{Content: "O"}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Subscript, - }, + Kind: types.Subscript, Elements: types.InlineElements{ types.StringElement{Content: "2"}, }, @@ -250,9 +212,7 @@ var _ = Describe("quoted texts", func() { It("superscript text with 3 words", func() { actualContent := "^^some superscript content^^" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Superscript, - }, + Kind: types.Superscript, Elements: types.InlineElements{ types.StringElement{Content: "some superscript content"}, }, @@ -265,9 +225,7 @@ var _ = Describe("quoted texts", func() { expectedResult := types.InlineElements{ types.StringElement{Content: "M"}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Superscript, - }, + Kind: types.Superscript, Elements: types.InlineElements{ types.StringElement{Content: "me"}, }, @@ -281,15 +239,11 @@ var _ = Describe("quoted texts", func() { It("superscript text within italic text", func() { actualContent := "__some ^superscript^ content__" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Superscript, - }, + Kind: types.Superscript, Elements: types.InlineElements{ types.StringElement{Content: "superscript"}, }, @@ -303,21 +257,15 @@ var _ = Describe("quoted texts", func() { It("superscript text within italic text within bold quote", func() { actualContent := "**some _italic and ^^superscript content^^_**" expectedResult := types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "italic and "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Superscript, - }, + Kind: types.Superscript, Elements: types.InlineElements{ types.StringElement{Content: "superscript content"}, }, @@ -338,9 +286,7 @@ var _ = Describe("quoted texts", func() { expectedResult := types.InlineElements{ types.StringElement{Content: "a paragraph with "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "some bold content"}, }, @@ -378,9 +324,7 @@ var _ = Describe("quoted texts", func() { expectedResult := types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold and _italic content _ together"}, }, @@ -395,9 +339,7 @@ var _ = Describe("quoted texts", func() { expectedResult := types.InlineElements{ types.StringElement{Content: "some *bold and "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "italic content"}, }, @@ -463,15 +405,11 @@ var _ = Describe("quoted texts", func() { expectedResult := types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold and "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "italic content"}, }, @@ -489,15 +427,11 @@ var _ = Describe("quoted texts", func() { actualContent := "*some *nested bold* content*" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "nested bold"}, }, @@ -514,15 +448,11 @@ var _ = Describe("quoted texts", func() { actualContent := "**some **nested bold** content**" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "nested bold"}, }, @@ -539,15 +469,11 @@ var _ = Describe("quoted texts", func() { actualContent := "**some *nested bold* content**" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "nested bold"}, }, @@ -564,15 +490,11 @@ var _ = Describe("quoted texts", func() { actualContent := "*some **nested bold** content*" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "nested bold"}, }, @@ -589,15 +511,11 @@ var _ = Describe("quoted texts", func() { actualContent := "_some _nested italic_ content_" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "nested italic"}, }, @@ -614,15 +532,11 @@ var _ = Describe("quoted texts", func() { actualContent := "__some __nested italic__ content__" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "nested italic"}, }, @@ -639,15 +553,11 @@ var _ = Describe("quoted texts", func() { actualContent := "_some __nested italic__ content_" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "nested italic"}, }, @@ -664,15 +574,11 @@ var _ = Describe("quoted texts", func() { actualContent := "_some __nested italic__ content_" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "nested italic"}, }, @@ -689,15 +595,11 @@ var _ = Describe("quoted texts", func() { actualContent := "`some `nested monospace` content`" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "nested monospace"}, }, @@ -714,15 +616,11 @@ var _ = Describe("quoted texts", func() { actualContent := "``some ``nested monospace`` content``" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "nested monospace"}, }, @@ -739,15 +637,11 @@ var _ = Describe("quoted texts", func() { actualContent := "`some ``nested monospace`` content`" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "nested monospace"}, }, @@ -764,15 +658,11 @@ var _ = Describe("quoted texts", func() { actualContent := "`some ``nested monospace`` content`" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "some "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "nested monospace"}, }, @@ -794,9 +684,7 @@ var _ = Describe("quoted texts", func() { actualContent := "**some bold content*" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "*some bold content"}, }, @@ -809,9 +697,7 @@ var _ = Describe("quoted texts", func() { actualContent := "*some bold content**" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "some bold content"}, }, @@ -828,9 +714,7 @@ var _ = Describe("quoted texts", func() { actualContent := "__some italic content_" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "_some italic content"}, }, @@ -843,9 +727,7 @@ var _ = Describe("quoted texts", func() { actualContent := "_some italic content__" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "some italic content"}, }, @@ -862,9 +744,7 @@ var _ = Describe("quoted texts", func() { actualContent := "``some monospace content`" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "`some monospace content"}, }, @@ -877,9 +757,7 @@ var _ = Describe("quoted texts", func() { actualContent := "`some monospace content``" expectedResult := types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "some monospace content"}, }, @@ -1000,9 +878,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "*"}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "italic content"}, }, @@ -1022,9 +898,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "**"}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "italic content"}, }, @@ -1044,9 +918,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "*bold "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{Content: "and italic"}, }, @@ -1154,9 +1026,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "_"}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Monospace, - }, + Kind: types.Monospace, Elements: types.InlineElements{ types.StringElement{Content: "monospace content"}, }, @@ -1176,9 +1046,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "__"}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold content"}, }, @@ -1198,9 +1066,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "_italic "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "and bold"}, }, @@ -1307,9 +1173,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "`"}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold content"}, }, @@ -1329,9 +1193,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "``"}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold content"}, }, @@ -1351,9 +1213,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "`monospace "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "and bold"}, }, @@ -1460,9 +1320,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "~"}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold content"}, }, @@ -1482,9 +1340,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "~~"}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold content"}, }, @@ -1504,9 +1360,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "~subscript "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "and bold"}, }, @@ -1613,9 +1467,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "^"}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold content"}, }, @@ -1635,9 +1487,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "^^"}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "bold content"}, }, @@ -1657,9 +1507,7 @@ var _ = Describe("quoted texts", func() { { types.StringElement{Content: "^superscript "}, types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "and bold"}, }, diff --git a/pkg/parser/section_test.go b/pkg/parser/section_test.go index e45ace41..553e09fd 100644 --- a/pkg/parser/section_test.go +++ b/pkg/parser/section_test.go @@ -123,9 +123,7 @@ and a paragraph` }, Elements: types.InlineElements{ types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{Content: "2 spaces and bold content"}, }, diff --git a/pkg/parser/table_test.go b/pkg/parser/table_test.go index be59e5a8..e5f640aa 100644 --- a/pkg/parser/table_test.go +++ b/pkg/parser/table_test.go @@ -20,9 +20,7 @@ var _ = Describe("tables", func() { Cells: []types.InlineElements{ { types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{ Content: "foo", @@ -35,9 +33,7 @@ var _ = Describe("tables", func() { }, { types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{ Content: "bar", @@ -66,9 +62,7 @@ var _ = Describe("tables", func() { Cells: []types.InlineElements{ { types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Bold, - }, + Kind: types.Bold, Elements: types.InlineElements{ types.StringElement{ Content: "foo", @@ -81,9 +75,7 @@ var _ = Describe("tables", func() { }, { types.QuotedText{ - Attributes: types.ElementAttributes{ - types.AttrKind: types.Italic, - }, + Kind: types.Italic, Elements: types.InlineElements{ types.StringElement{ Content: "bar", diff --git a/pkg/renderer/html5/quoted_text.go b/pkg/renderer/html5/quoted_text.go index 9c235aa4..a5733a1c 100644 --- a/pkg/renderer/html5/quoted_text.go +++ b/pkg/renderer/html5/quoted_text.go @@ -40,8 +40,7 @@ func renderQuotedText(ctx *renderer.Context, t types.QuotedText) ([]byte, error) } result := bytes.NewBuffer(nil) var tmpl texttemplate.Template - kind := t.Attributes[types.AttrKind] - switch kind { + switch t.Kind { case types.Bold: tmpl = boldTextTmpl case types.Italic: @@ -53,7 +52,7 @@ func renderQuotedText(ctx *renderer.Context, t types.QuotedText) ([]byte, error) case types.Superscript: tmpl = superscriptTextTmpl default: - return nil, errors.Errorf("unsupported quoted text kind: '%v'", kind) + return nil, errors.Errorf("unsupported quoted text kind: '%v'", t.Kind) } err := tmpl.Execute(result, template.HTML(elementsBuffer.String())) if err != nil { diff --git a/pkg/types/grammar_types.go b/pkg/types/grammar_types.go index 64423583..1ed89cd7 100644 --- a/pkg/types/grammar_types.go +++ b/pkg/types/grammar_types.go @@ -1983,8 +1983,8 @@ func NewLineBreak() (LineBreak, error) { // QuotedText the structure for quoted text type QuotedText struct { - Attributes ElementAttributes - Elements InlineElements + Kind QuotedTextKind + Elements InlineElements } // QuotedTextKind the type for @@ -2010,8 +2010,8 @@ func NewQuotedText(kind QuotedTextKind, content []interface{}) (QuotedText, erro log.Debugf("initialized a new QuotedText with %d elements: %v", len(elements), spew.Sdump(elements)) } return QuotedText{ - Attributes: map[string]interface{}{AttrKind: kind}, - Elements: elements, + Kind: kind, + Elements: elements, }, nil } diff --git a/pkg/types/grammar_types_utils_test.go b/pkg/types/grammar_types_utils_test.go index 1ac67363..6b78d84c 100644 --- a/pkg/types/grammar_types_utils_test.go +++ b/pkg/types/grammar_types_utils_test.go @@ -80,9 +80,7 @@ var _ = Describe("normalizing string", func() { source := InlineElements{ StringElement{Content: "a section title, with"}, QuotedText{ - Attributes: ElementAttributes{ - AttrKind: Bold, - }, + Kind: Bold, Elements: []interface{}{ StringElement{Content: "bold content"}, },