From d2b38fd27b1ed67bbb9ad5e0b3e39cafda7fda7f Mon Sep 17 00:00:00 2001 From: Arya Hassanli Date: Tue, 17 Mar 2026 21:51:27 +0000 Subject: [PATCH 1/2] Support complex revision tables in overlay --- asciidoc/overlay/overlay.go | 37 ++++++++++++++++++++++++++++++------- asciidoc/overlay/state.go | 5 +++-- matter/spec/table_info.go | 3 --- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/asciidoc/overlay/overlay.go b/asciidoc/overlay/overlay.go index a7265b92..5d12319a 100644 --- a/asciidoc/overlay/overlay.go +++ b/asciidoc/overlay/overlay.go @@ -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(pps, el, 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(pps, el, 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) @@ -144,7 +144,7 @@ func preparseFile(cxt OverlayContext, pps *overlayFileState, d *asciidoc.Documen suppress = !include } remove = true - addToCell = el.Inline + addToCell = el.Inline || isContentIfDef(pps, el, parent, index) case *asciidoc.IfDefBlock, *asciidoc.IfNDefBlock, *asciidoc.IfEvalBlock: err = fmt.Errorf("unexpected type in preparse: %T", el) should = parse.SearchShouldStop @@ -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) { @@ -365,3 +365,26 @@ func parseLevelOffset(el asciidoc.Parent, elements asciidoc.Elements) (leveloffs leveloffset, relative, err = text.ParseRelativeNumber(val) return } + +func isContentIfDef(pps *overlayFileState, el asciidoc.Element, 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 +} diff --git a/asciidoc/overlay/state.go b/asciidoc/overlay/state.go index ae5f5fad..e3a6bde5 100644 --- a/asciidoc/overlay/state.go +++ b/asciidoc/overlay/state.go @@ -7,8 +7,9 @@ import ( ) type conditionalBlock struct { - open asciidoc.Element - suppress bool + open asciidoc.Element + suppress bool + addToCell bool } type overlayState struct { diff --git a/matter/spec/table_info.go b/matter/spec/table_info.go index a7c1853b..8b6a5e7b 100644 --- a/matter/spec/table_info.go +++ b/matter/spec/table_info.go @@ -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 { From 50e9acef3facfed4bcd6c0d5bab9c38fedd41e22 Mon Sep 17 00:00:00 2001 From: Arya Hassanli Date: Tue, 17 Mar 2026 21:56:48 +0000 Subject: [PATCH 2/2] Remove unused parameters --- asciidoc/overlay/overlay.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/asciidoc/overlay/overlay.go b/asciidoc/overlay/overlay.go index 5d12319a..63b85fa2 100644 --- a/asciidoc/overlay/overlay.go +++ b/asciidoc/overlay/overlay.go @@ -126,12 +126,12 @@ func preparseFile(cxt OverlayContext, pps *overlayFileState, d *asciidoc.Documen suppressStack.Push(&conditionalBlock{suppress: suppress, open: el, addToCell: addToCell}) suppress = suppress || !el.Eval(pps) remove = true - addToCell = el.Inline || isContentIfDef(pps, el, parent, index) + addToCell = el.Inline || isContentIfDef(parent, index) case *asciidoc.IfNDef: suppressStack.Push(&conditionalBlock{suppress: suppress, open: el, addToCell: addToCell}) suppress = suppress || !el.Eval(pps) remove = true - addToCell = el.Inline || isContentIfDef(pps, el, parent, index) + addToCell = el.Inline || isContentIfDef(parent, index) case *asciidoc.IfEval: suppressStack.Push(&conditionalBlock{suppress: suppress, open: el, addToCell: addToCell}) if !suppress { @@ -144,7 +144,7 @@ func preparseFile(cxt OverlayContext, pps *overlayFileState, d *asciidoc.Documen suppress = !include } remove = true - addToCell = el.Inline || isContentIfDef(pps, el, parent, index) + 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 @@ -366,7 +366,7 @@ func parseLevelOffset(el asciidoc.Parent, elements asciidoc.Elements) (leveloffs return } -func isContentIfDef(pps *overlayFileState, el asciidoc.Element, parent asciidoc.ParentElement, index int) bool { +func isContentIfDef(parent asciidoc.ParentElement, index int) bool { if _, ok := parent.(*asciidoc.Table); !ok { return false }