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

Commit db62628

Browse files
author
Matthew Williams
committed
Fix link styling
1 parent 3d93242 commit db62628

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
@@ -815,27 +815,22 @@ func button(ds *docState) types.Node {
815815
func link(ds *docState) types.Node {
816816
href := nodeAttr(ds.cur, "href")
817817

818-
text := stringifyNode(ds.cur, false)
819-
if strings.TrimSpace(text) == "" {
820-
return nil
821-
}
818+
ds.push(nil)
819+
parsedChildNodes := parseSubtree(ds)
820+
ds.pop()
822821

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

838-
n := types.NewURLNode(href, t)
833+
n := types.NewURLNode(href, parsedChildNodes...)
839834
n.Name = nodeAttr(ds.cur, "name")
840835
if v := nodeAttr(ds.cur, "target"); v != "" {
841836
n.Target = v

0 commit comments

Comments
 (0)