Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 4397814

Browse files
authored
Merge pull request #430 from M4FFS/fixunderline
Fix link styling
2 parents a46b43c + cd97950 commit 4397814

1 file changed

Lines changed: 13 additions & 18 deletions

File tree

claat/parser/md/parse.go

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -821,27 +821,22 @@ func button(ds *docState) types.Node {
821821
func link(ds *docState) types.Node {
822822
href := nodeAttr(ds.cur, "href")
823823

824-
text := stringifyNode(ds.cur, false)
825-
if strings.TrimSpace(text) == "" {
826-
return nil
827-
}
824+
ds.push(nil)
825+
parsedChildNodes := parseSubtree(ds)
826+
ds.pop()
828827

829-
t := types.NewTextNode(text)
830-
if isBold(ds.cur.Parent) {
831-
t.Bold = true
832-
}
833-
if isItalic(ds.cur.Parent) {
834-
t.Italic = true
835-
}
836-
if isCode(ds.cur.Parent) {
837-
t.Code = true
838-
}
839-
if href == "" || href[0] == '#' {
840-
t.MutateBlock(findBlockParent(ds.cur))
841-
return t
828+
// Check outside styles
829+
outsideBold := isBold(ds.cur.Parent)
830+
outsideItalic := isItalic(ds.cur.Parent)
831+
// Apply outside styles to inside parsed (text) nodes
832+
for _, node := range parsedChildNodes {
833+
if textNode, ok := node.(*types.TextNode); ok {
834+
textNode.Bold = textNode.Bold || outsideBold
835+
textNode.Italic = textNode.Italic || outsideItalic
836+
}
842837
}
843838

844-
n := types.NewURLNode(href, t)
839+
n := types.NewURLNode(href, parsedChildNodes...)
845840
n.Name = nodeAttr(ds.cur, "name")
846841
if v := nodeAttr(ds.cur, "target"); v != "" {
847842
n.Target = v

0 commit comments

Comments
 (0)