Skip to content

Commit

Permalink
🎨 Protyle Improve image width setting siyuan-note/siyuan#12516
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 28, 2024
1 parent f772b0e commit 47c361d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 34 deletions.
4 changes: 2 additions & 2 deletions javascript/lute.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion javascript/lute.min.js.map

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions parse/inline_html.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,24 @@ func SetSpanIAL(node *ast.Node, n *html.Node) {
}
}

if nil != n.Parent && atom.Img == n.DataAtom {
if style := util.DomAttrValue(n.Parent, "style"); "" != style {
if insertedIAL {
m := Tokens2IAL(node.Next.Tokens)
m = append(m, []string{"style", style})
node.Next.Tokens = IAL2Tokens(m)
node.SetIALAttr("style", style)
node.KramdownIAL = m
} else {
node.SetIALAttr("style", style)
ialTokens := IAL2Tokens(node.KramdownIAL)
ial := &ast.Node{Type: ast.NodeKramdownSpanIAL, Tokens: ialTokens}
node.InsertAfter(ial)
}
insertedIAL = true
}
}

if nil != n.Parent && nil != n.Parent.Parent && atom.Img == n.DataAtom {
if parentStyle := util.DomAttrValue(n.Parent.Parent, "style"); "" != parentStyle {
if insertedIAL {
Expand Down
12 changes: 7 additions & 5 deletions render/protyle_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,11 @@ func (r *ProtyleRenderer) renderImage(node *ast.Node, entering bool) ast.WalkSta
r.Tag("span", nil, false)
r.WriteString(" ")
r.Tag("/span", nil, false)
r.Tag("span", nil, false)
attrs = [][]string{}
if style := node.IALAttr("style"); "" != style {
attrs = append(attrs, []string{"style", style})
}
r.Tag("span", attrs, false)
r.Tag("span", [][]string{{"class", "protyle-action protyle-icons"}}, false)
r.WriteString("<span class=\"protyle-icon protyle-icon--only\"><svg class=\"svg\"><use xlink:href=\"#iconMore\"></use></svg></span>")
r.Tag("/span", nil, false)
Expand All @@ -1287,10 +1291,6 @@ func (r *ProtyleRenderer) renderImage(node *ast.Node, entering bool) ast.WalkSta
titleTokens = title.Tokens
attrs = append(attrs, []string{"title", r.escapeRefText(string(titleTokens))})
}

if style := node.IALAttr("style"); "" != style {
attrs = append(attrs, []string{"style", style})
}
r.Tag("img", attrs, true)

buf := r.Writer.Bytes()
Expand All @@ -1312,9 +1312,11 @@ func (r *ProtyleRenderer) renderImage(node *ast.Node, entering bool) ast.WalkSta

attrs = [][]string{{"class", "protyle-action__title"}}
r.Tag("span", attrs, false)
r.Tag("span", nil, false)
r.Writer.Write(html.EscapeHTML(titleTokens))
r.Tag("/span", nil, false)
r.Tag("/span", nil, false)
r.Tag("/span", nil, false)
r.Tag("span", nil, false)
r.WriteString(" ")
r.Tag("/span", nil, false)
Expand Down
Loading

0 comments on commit 47c361d

Please sign in to comment.