Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions asciidoc/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ func preparseFile(cxt OverlayContext, pps *overlayFileState, d *asciidoc.Documen
}
remove = true
case *asciidoc.IfDef:
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el})
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el, addToCell: addToCell})
suppress = suppress || !el.Eval(pps)
remove = true
addToCell = el.Inline
addToCell = el.Inline || isContentIfDef(parent, index)
case *asciidoc.IfNDef:
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el})
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el, addToCell: addToCell})
suppress = suppress || !el.Eval(pps)
remove = true
addToCell = el.Inline
addToCell = el.Inline || isContentIfDef(parent, index)
case *asciidoc.IfEval:
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el})
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el, addToCell: addToCell})
if !suppress {
var include bool
include, err = el.Eval(pps)
Expand All @@ -144,7 +144,7 @@ func preparseFile(cxt OverlayContext, pps *overlayFileState, d *asciidoc.Documen
suppress = !include
}
remove = true
addToCell = el.Inline
addToCell = el.Inline || isContentIfDef(parent, index)
case *asciidoc.IfDefBlock, *asciidoc.IfNDefBlock, *asciidoc.IfEvalBlock:
err = fmt.Errorf("unexpected type in preparse: %T", el)
should = parse.SearchShouldStop
Expand All @@ -163,7 +163,7 @@ func preparseFile(cxt OverlayContext, pps *overlayFileState, d *asciidoc.Documen
}
suppress = cb.suppress
remove = true
addToCell = false
addToCell = cb.addToCell
case *asciidoc.InlineIfDef:
if !suppress {
if el.Eval(pps) {
Expand Down Expand Up @@ -365,3 +365,26 @@ func parseLevelOffset(el asciidoc.Parent, elements asciidoc.Elements) (leveloffs
leveloffset, relative, err = text.ParseRelativeNumber(val)
return
}

func isContentIfDef(parent asciidoc.ParentElement, index int) bool {
if _, ok := parent.(*asciidoc.Table); !ok {
return false
}
children := parent.Children()
depth := 0
for i := index + 1; i < len(children); i++ {
child := children[i]
switch child.(type) {
case *asciidoc.IfDef, *asciidoc.IfNDef, *asciidoc.IfEval:
depth++
case *asciidoc.EndIf:
if depth == 0 {
return true
}
depth--
case *asciidoc.TableRow:
return false
}
}
return false
}
5 changes: 3 additions & 2 deletions asciidoc/overlay/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
)

type conditionalBlock struct {
open asciidoc.Element
suppress bool
open asciidoc.Element
suppress bool
addToCell bool
}

type overlayState struct {
Expand Down
3 changes: 0 additions & 3 deletions matter/spec/table_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ func (ti *TableInfo) ReadValue(reader asciidoc.Reader, row *asciidoc.TableRow, c
func (ti *TableInfo) ReadValueByIndex(reader asciidoc.Reader, row *asciidoc.TableRow, offset int) (string, error) {
cell := row.Cell(offset)
cellElements := reader.Children(cell)
if len(cellElements) == 0 {
return "", nil
}
var value strings.Builder
err := readRowCellValueElements(reader, row, cell, cellElements, &value)
if err != nil {
Expand Down
Loading