Skip to content

Commit 35e2a71

Browse files
committed
add flag to export only inner HTML of output file
1 parent 484db50 commit 35e2a71

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

webtex_render/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ type Config struct {
1212
InputURL string
1313
OutputURL string
1414
Template *template.Template
15+
OnlyInnerHTML bool
1516
}

webtex_render/html.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ func parseHtml(config Config) error {
3131
s.SetAttr("src", sha)
3232
})
3333

34-
html, err := doc.Html()
34+
var toExport *goquery.Selection
35+
if config.OnlyInnerHTML {
36+
toExport = doc.Find("body")
37+
} else {
38+
toExport = doc.Selection
39+
}
40+
html, err := toExport.Html()
3541
if err != nil {
3642
log.Println("failed generating output html:", err)
3743
return err

webtex_render/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func main() {
1515
var inputUrl = flag.String("inurl", "eqn://", "input webtex URL prefix")
1616
var outputUrl = flag.String("outurl", "equations", "image src root")
1717
var templateFilename = flag.String("template", "", "TeX template file")
18+
var onlyInner = flag.Bool("innerhtml", false, "export only inner HTML of the result (without <html><body> tags)")
1819
flag.Parse()
1920

2021
var err error
@@ -41,6 +42,7 @@ func main() {
4142
config.EquationDirectory = *equationDirectory
4243
config.InputURL = *inputUrl
4344
config.OutputURL = *outputUrl
45+
config.OnlyInnerHTML = *onlyInner
4446

4547
if *templateFilename == "" {
4648
log.Println("please provide a template file.")

0 commit comments

Comments
 (0)