From 7afab9487c044c662e10a2c20cc1b85b9c2b38c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Wed, 1 Apr 2026 21:32:39 +0400 Subject: [PATCH] Convert html blocks inside table cells MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Émile Ré --- pkg/prosemirror/markdown.go | 77 +++++++++++++++++++++++++++++++- pkg/prosemirror/markdown_test.go | 49 ++++++++++++++++++++ 2 files changed, 124 insertions(+), 2 deletions(-) diff --git a/pkg/prosemirror/markdown.go b/pkg/prosemirror/markdown.go index d509b727b..f75495bf4 100644 --- a/pkg/prosemirror/markdown.go +++ b/pkg/prosemirror/markdown.go @@ -580,7 +580,7 @@ func (c *converter) convertTableCells(row ast.Node, cellType NodeType) ([]Node, continue } - inlineContent, err := c.convertInlineChildren(child) + content, err := c.convertTableCellContent(child) if err != nil { return nil, err } @@ -598,13 +598,86 @@ func (c *converter) convertTableCells(row ast.Node, cellType NodeType) ([]Node, cells = append(cells, Node{ Type: cellType, Attrs: attrs, - Content: []Node{{Type: NodeParagraph, Content: inlineContent}}, + Content: content, }) } return cells, nil } +func (c *converter) convertTableCellContent(cell ast.Node) ([]Node, error) { + if c.cellHasBlockHTML(cell) { + raw := c.collectCellRawContent(cell) + nodes, err := convertProseMirrorFromHTMLBlock(raw) + if err != nil { + return nil, err + } + if len(nodes) > 0 { + return nodes, nil + } + } + + inlineContent, err := c.convertInlineChildren(cell) + if err != nil { + return nil, err + } + return []Node{{Type: NodeParagraph, Content: inlineContent}}, nil +} + +func (c *converter) cellHasBlockHTML(cell ast.Node) bool { + for ch := cell.FirstChild(); ch != nil; ch = ch.NextSibling() { + if ch.Kind() != ast.KindRawHTML { + continue + } + raw := ch.(*ast.RawHTML) + for i := 0; i < raw.Segments.Len(); i++ { + seg := raw.Segments.At(i) + val := strings.ToLower(string(seg.Value(c.source))) + if containsBlockOpenTag(val) { + return true + } + } + } + return false +} + +func containsBlockOpenTag(s string) bool { + for _, tag := range []string{ + "