Skip to content

Commit

Permalink
#8 try fix font inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-gaitzsch committed Dec 1, 2023
1 parent 889472d commit 958497f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
3 changes: 0 additions & 3 deletions services/renderer/html-to-pdf-renderer-chromium.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"regexp"

"github.com/lucas-gaitzsch/pdf-turtle/models"
"github.com/lucas-gaitzsch/pdf-turtle/services/renderer/headlesschromium"
Expand All @@ -19,8 +18,6 @@ import (
const magicHeaderFooterScaleFactor = 0.75
const magicBodyPaddingInInches = 0.004

var urlReferenceRegex = regexp.MustCompile(`(src|href)="(.+)"`)

type HtmlToPdfRendererChromium struct {
ChromiumCtx context.Context
chromiumCancelFunc context.CancelFunc
Expand Down
8 changes: 4 additions & 4 deletions utils/html-css.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func MergeCss(css ...*string) *string {
return &mergedCss
}

var urlReferenceRegex = regexp.MustCompile(`( src="| href="|src: *url\(")([^"]+)("\)|")`)
var urlReferenceRegex = regexp.MustCompile(`(\ssrc="|\shref="|src:\s*(local\(.*\),)?\s*url\(["'])([^"']+)(["']\)|")`)

type HttpClientExecuter interface {
Do(req *http.Request) (*http.Response, error)
Expand All @@ -64,10 +64,10 @@ func RequestAndInlineAllHtmlResources(ctx context.Context, htmlPtr *string, base

func requestAndReturnBase64IfPossible(ctx context.Context, htmlAttribute string, baseUrl string, logger *zerolog.Logger) string {

groups := urlReferenceRegex.FindAllStringSubmatch(htmlAttribute, 2)
groups := urlReferenceRegex.FindAllStringSubmatch(htmlAttribute, 4)
prefix := groups[0][1]
src := groups[0][2]
suffix := groups[0][3]
src := groups[0][3]
suffix := groups[0][4]

if baseUrl != "" && !strings.HasPrefix(src, "http") {
src = baseUrl + src
Expand Down

0 comments on commit 958497f

Please sign in to comment.