From b8953ce4af51d59432dee2e2239c866181ea5ea7 Mon Sep 17 00:00:00 2001 From: Brian Strauch Date: Tue, 22 Aug 2023 12:39:50 -0700 Subject: [PATCH] fix: render urls in table (#248) --- ansi/elements.go | 9 +++++++-- styles/examples/table.md | 8 ++++---- testdata/table.test | 8 ++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ansi/elements.go b/ansi/elements.go index 5e8adb52..ac98399a 100644 --- a/ansi/elements.go +++ b/ansi/elements.go @@ -306,8 +306,13 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element { s := "" n := node.FirstChild() for n != nil { - s += string(n.Text(source)) - // s += string(n.LinkData.Destination) + switch t := n.(type) { + case *ast.AutoLink: + s += string(t.Label(source)) + default: + s += string(n.Text(source)) + } + n = n.NextSibling() } diff --git a/styles/examples/table.md b/styles/examples/table.md index a752b0cd..c6029c42 100644 --- a/styles/examples/table.md +++ b/styles/examples/table.md @@ -1,4 +1,4 @@ -| Label | Value | -| ------ | ----- | -| First | foo | -| Second | bar | +| Label | Value | URL | +| ------ | ----- | ---------------- | +| First | foo | https://charm.sh | +| Second | bar | https://charm.sh | diff --git a/testdata/table.test b/testdata/table.test index c608b86d..0da2654e 100644 --- a/testdata/table.test +++ b/testdata/table.test @@ -1,5 +1,5 @@ - LABEL | VALUE - ---------+-------- - First | foo - Second | bar + LABEL | VALUE | URL + ---------+-------+------------------- + First | foo | https://charm.sh + Second | bar | https://charm.sh