Skip to content

Commit

Permalink
feat(parser/renderer): support index terms
Browse files Browse the repository at this point in the history
index terms have a single term which can be a quoted text
or simple text (for now). This index term is rendered
as its term itself.

Fixes bytesparadise#497

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Mar 9, 2020
1 parent 4d3ef23 commit 55b772d
Show file tree
Hide file tree
Showing 11 changed files with 2,655 additions and 2,221 deletions.
121 changes: 0 additions & 121 deletions pkg/parser/concealed_index_terms_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/parser/document_processing_filter_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ var commentBlockMatcher filterMatcher = func(element interface{}) bool {

// concealedIndexTermMatcher filters the element if it is a ConcealedIndexTerm
var concealedIndexTermMatcher filterMatcher = func(element interface{}) bool {
_, ok := element.(types.ConceleadIndexTerm)
_, ok := element.(types.ConcealedIndexTerm)
return ok
}
262 changes: 262 additions & 0 deletions pkg/parser/index_terms_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
package parser_test

import (
"github.com/bytesparadise/libasciidoc/pkg/types"
. "github.com/bytesparadise/libasciidoc/testsupport"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("index terms", func() {

Context("draft document", func() {

It("index term in existing paragraph line", func() {
source := `a paragraph with an ((index term)).`
expected := types.DraftDocument{
Blocks: []interface{}{
types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: [][]interface{}{
{
types.StringElement{
Content: "a paragraph with an ",
},
types.IndexTerm{
Term: []interface{}{
types.StringElement{
Content: "index term",
},
},
},
types.StringElement{
Content: ".",
},
},
},
},
},
}
Expect(ParseDraftDocument(source)).To(Equal(expected))
})

It("index term in single paragraph line", func() {
source := `((_italic term_))
a paragraph with an index term.`
expected := types.DraftDocument{
Blocks: []interface{}{
types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: [][]interface{}{
{
types.IndexTerm{
Term: []interface{}{
types.QuotedText{
Kind: types.Italic,
Elements: []interface{}{
types.StringElement{
Content: "italic term",
},
},
},
},
},
},
{
types.StringElement{
Content: "a paragraph with an index term.",
},
},
},
},
},
}
Expect(ParseDraftDocument(source)).To(Equal(expected))
})
})

Context("final document", func() {

It("index term in existing paragraph line", func() {
source := `a paragraph with an ((index)) term.`
expected := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: [][]interface{}{
{
types.StringElement{
Content: "a paragraph with an ",
},
types.IndexTerm{
Term: []interface{}{types.StringElement{
Content: "index",
},
},
},
types.StringElement{
Content: " term.",
},
},
},
},
},
}
Expect(ParseDocument(source)).To(Equal(expected))
})

It("index term in single paragraph line", func() {
source := `((_italic_))
a paragraph with an index term.`
expected := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: [][]interface{}{
{
types.IndexTerm{
Term: []interface{}{
types.QuotedText{
Kind: types.Italic,
Elements: []interface{}{
types.StringElement{
Content: "italic",
},
},
},
},
},
},
{
types.StringElement{
Content: "a paragraph with an index term.",
},
},
},
},
},
}
Expect(ParseDocument(source)).To(Equal(expected))
})
})
})
var _ = Describe("concealed index terms", func() {

Context("draft document", func() {

It("concealed index term in existing paragraph line", func() {
source := `a paragraph with an index term (((index, term, here))).`
expected := types.DraftDocument{
Blocks: []interface{}{
types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: [][]interface{}{
{
types.StringElement{
Content: "a paragraph with an index term ",
},
types.ConcealedIndexTerm{
Term1: "index",
Term2: "term",
Term3: "here",
},
types.StringElement{
Content: ".",
},
},
},
},
},
}
Expect(ParseDraftDocument(source)).To(Equal(expected))
})

It("concealed index term in single paragraph line", func() {
source := `(((index, term)))
a paragraph with an index term.`
expected := types.DraftDocument{
Blocks: []interface{}{
types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: [][]interface{}{
{
types.ConcealedIndexTerm{
Term1: "index",
Term2: "term",
},
},
{
types.StringElement{
Content: "a paragraph with an index term.",
},
},
},
},
},
}
Expect(ParseDraftDocument(source)).To(Equal(expected))
})
})

Context("final document", func() {

It("concealed index term in existing paragraph line", func() {
source := `a paragraph with an index term (((index, term, here))).`
expected := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: [][]interface{}{
{
types.StringElement{
Content: "a paragraph with an index term ",
},
types.StringElement{
Content: ".",
},
},
},
},
},
}
Expect(ParseDocument(source)).To(Equal(expected))
})

It("concealed index term in single paragraph line", func() {
source := `(((index, term)))
a paragraph with an index term.`
expected := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: [][]interface{}{
{
types.StringElement{
Content: "a paragraph with an index term.",
},
},
},
},
},
}
Expect(ParseDocument(source)).To(Equal(expected))
})
})
})
Loading

0 comments on commit 55b772d

Please sign in to comment.