Skip to content

Commit 453cc52

Browse files
authored
Merge pull request #50 from AryaHassanli/support-complex-tables-in-overlay
Support complex revision tables in overlay
2 parents ebe5b46 + 50e9ace commit 453cc52

3 files changed

Lines changed: 33 additions & 12 deletions

File tree

asciidoc/overlay/overlay.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ func preparseFile(cxt OverlayContext, pps *overlayFileState, d *asciidoc.Documen
123123
}
124124
remove = true
125125
case *asciidoc.IfDef:
126-
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el})
126+
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el, addToCell: addToCell})
127127
suppress = suppress || !el.Eval(pps)
128128
remove = true
129-
addToCell = el.Inline
129+
addToCell = el.Inline || isContentIfDef(parent, index)
130130
case *asciidoc.IfNDef:
131-
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el})
131+
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el, addToCell: addToCell})
132132
suppress = suppress || !el.Eval(pps)
133133
remove = true
134-
addToCell = el.Inline
134+
addToCell = el.Inline || isContentIfDef(parent, index)
135135
case *asciidoc.IfEval:
136-
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el})
136+
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el, addToCell: addToCell})
137137
if !suppress {
138138
var include bool
139139
include, err = el.Eval(pps)
@@ -144,7 +144,7 @@ func preparseFile(cxt OverlayContext, pps *overlayFileState, d *asciidoc.Documen
144144
suppress = !include
145145
}
146146
remove = true
147-
addToCell = el.Inline
147+
addToCell = el.Inline || isContentIfDef(parent, index)
148148
case *asciidoc.IfDefBlock, *asciidoc.IfNDefBlock, *asciidoc.IfEvalBlock:
149149
err = fmt.Errorf("unexpected type in preparse: %T", el)
150150
should = parse.SearchShouldStop
@@ -163,7 +163,7 @@ func preparseFile(cxt OverlayContext, pps *overlayFileState, d *asciidoc.Documen
163163
}
164164
suppress = cb.suppress
165165
remove = true
166-
addToCell = false
166+
addToCell = cb.addToCell
167167
case *asciidoc.InlineIfDef:
168168
if !suppress {
169169
if el.Eval(pps) {
@@ -365,3 +365,26 @@ func parseLevelOffset(el asciidoc.Parent, elements asciidoc.Elements) (leveloffs
365365
leveloffset, relative, err = text.ParseRelativeNumber(val)
366366
return
367367
}
368+
369+
func isContentIfDef(parent asciidoc.ParentElement, index int) bool {
370+
if _, ok := parent.(*asciidoc.Table); !ok {
371+
return false
372+
}
373+
children := parent.Children()
374+
depth := 0
375+
for i := index + 1; i < len(children); i++ {
376+
child := children[i]
377+
switch child.(type) {
378+
case *asciidoc.IfDef, *asciidoc.IfNDef, *asciidoc.IfEval:
379+
depth++
380+
case *asciidoc.EndIf:
381+
if depth == 0 {
382+
return true
383+
}
384+
depth--
385+
case *asciidoc.TableRow:
386+
return false
387+
}
388+
}
389+
return false
390+
}

asciidoc/overlay/state.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
)
88

99
type conditionalBlock struct {
10-
open asciidoc.Element
11-
suppress bool
10+
open asciidoc.Element
11+
suppress bool
12+
addToCell bool
1213
}
1314

1415
type overlayState struct {

matter/spec/table_info.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,6 @@ func (ti *TableInfo) ReadValue(reader asciidoc.Reader, row *asciidoc.TableRow, c
178178
func (ti *TableInfo) ReadValueByIndex(reader asciidoc.Reader, row *asciidoc.TableRow, offset int) (string, error) {
179179
cell := row.Cell(offset)
180180
cellElements := reader.Children(cell)
181-
if len(cellElements) == 0 {
182-
return "", nil
183-
}
184181
var value strings.Builder
185182
err := readRowCellValueElements(reader, row, cell, cellElements, &value)
186183
if err != nil {

0 commit comments

Comments
 (0)