Skip to content

Added settings to Inliner. #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions inliner/inliner.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ type Inliner struct {

// current element marker value
eltMarker int

// Do not remove original rules after inlining the styles
KeepStyle bool

// Append rules after parsing the HTML document to the body instead of head
AppendToBody bool
}

// NewInliner instanciates a new Inliner
Expand Down Expand Up @@ -130,6 +136,9 @@ func (inliner *Inliner) collectElementsAndRules() {
if rule.Kind == css.QualifiedRule {
// Let's go!
inliner.handleQualifiedRule(rule)
if inliner.KeepStyle {
inliner.rawRules = append(inliner.rawRules, rule)
}
} else {
// Keep it 'as is'
inliner.rawRules = append(inliner.rawRules, rule)
Expand Down Expand Up @@ -211,14 +220,19 @@ func (inliner *Inliner) insertRawStylesheet() {

styleNode.AppendChild(cssNode)

// append to <head> element
headNode := inliner.doc.Find("head")
if headNode == nil {
// @todo Create head node !
panic("NOT IMPLEMENTED: create missing <head> node")
var elementNode string
if inliner.AppendToBody {
elementNode = "body"
} else {
elementNode = "head"
}

headNode.AppendNodes(styleNode)
node := inliner.doc.Find(elementNode)
if node == nil {
// @todo create head/body node !
panic(fmt.Sprintf("NOT IMPLEMENTED: create missing <%s> node", elementNode))
}
node.AppendNodes(styleNode)
}
}

Expand Down