Skip to content

Commit

Permalink
fix: handle empty image title in pdf conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
dikkadev committed Apr 11, 2023
1 parent 385312d commit 90eb312
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion globals/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package globals

const Version = "2.7.3"
const Version = "2.7.4"
4 changes: 0 additions & 4 deletions pdf/conversions/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ func Image(image *ast.Image, node ast.Node) (retO *spec.XObject, retA *spec.Adda
titlePara := String(string(image.Title))
titleSegs := (*titlePara).(*elements.Paragraph).Segments
para.Add(titleSegs...)
//para.Add(&spec.Segment{
// Content: string(image.Title),
// Font: spec.SerifRegular,
//})
var a spec.Addable = &para
retP = &a
return
Expand Down
21 changes: 19 additions & 2 deletions pdf/conversions/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"github.com/sett17/mdpaper/v2/globals"
goldmark_cite "github.com/sett17/mdpaper/v2/goldmark-cite"
goldmark_figref "github.com/sett17/mdpaper/v2/goldmark-figref"
"github.com/sett17/mdpaper/v2/pdf/elements"
"github.com/sett17/mdpaper/v2/pdf/spec"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/text"
"strings"
)

func String(s string) *spec.Addable {
func String(s string) (ret *spec.Addable) {
p := goldmark.New(
goldmark.WithExtensions(
&goldmark_cite.CitationExtension{},
Expand All @@ -23,7 +24,23 @@ func String(s string) *spec.Addable {
prevFile := globals.File
globals.File = buf
parsed := p.Parse(text.NewReader(buf))
ret := Paragraph(parsed.FirstChild().(*ast.Paragraph), false)
if para, ok := parsed.FirstChild().(*ast.Paragraph); ok {
ret = Paragraph(para, false)
} else {
para := elements.Paragraph{
Text: spec.Text{
FontSize: globals.Cfg.Text.FontSize,
LineHeight: globals.Cfg.Text.LineHeight,
},
}
emptySeg := spec.Segment{
Content: "",
Font: spec.SerifRegular,
}
para.Add(&emptySeg)
var a spec.Addable = &para
ret = &a
}
globals.File = prevFile

return ret
Expand Down

0 comments on commit 90eb312

Please sign in to comment.