Skip to content

Commit

Permalink
fix(parser/renderer): support non-alphanum characters in index terms
Browse files Browse the repository at this point in the history
Modify IndexTermContent rule to match non-alphanums which
may not be used as quoted text delimters

Also, fix index term renderer (use the `renderInlineElements`
func to avoid having `\n` between each term element

Fixes bytesparadise#503

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Mar 16, 2020
1 parent c394f70 commit 6e33cca
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 271 deletions.
13 changes: 8 additions & 5 deletions pkg/parser/index_terms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var _ = Describe("index terms", func() {
Context("draft document", func() {

It("index term in existing paragraph line", func() {
source := `a paragraph with an ((index term)).`
source := `a paragraph with an ((index_term_here)).`
expected := types.DraftDocument{
Blocks: []interface{}{
types.Paragraph{
Expand All @@ -26,7 +26,7 @@ var _ = Describe("index terms", func() {
types.IndexTerm{
Term: []interface{}{
types.StringElement{
Content: "index term",
Content: "index_term_here",
},
},
},
Expand All @@ -41,7 +41,7 @@ var _ = Describe("index terms", func() {
Expect(ParseDraftDocument(source)).To(Equal(expected))
})

It("index term in single paragraph line", func() {
It("index term in separate paragraph line", func() {
source := `((_italic term_))
a paragraph with an index term.`
expected := types.DraftDocument{
Expand Down Expand Up @@ -111,7 +111,7 @@ a paragraph with an index term.`
})

It("index term in single paragraph line", func() {
source := `((_italic_))
source := `((foo_bar_baz _italic_))
a paragraph with an index term.`
expected := types.Document{
Attributes: types.DocumentAttributes{},
Expand All @@ -125,6 +125,9 @@ a paragraph with an index term.`
{
types.IndexTerm{
Term: []interface{}{
types.StringElement{
Content: "foo_bar_baz ",
},
types.QuotedText{
Kind: types.Italic,
Elements: []interface{}{
Expand Down Expand Up @@ -180,7 +183,7 @@ var _ = Describe("concealed index terms", func() {
Expect(ParseDraftDocument(source)).To(Equal(expected))
})

It("concealed index term in single paragraph line", func() {
It("concealed index term in separate paragraph line", func() {
source := `(((index, term)))
a paragraph with an index term.`
expected := types.DraftDocument{
Expand Down
Loading

0 comments on commit 6e33cca

Please sign in to comment.