forked from JohannesKaufmann/html-to-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frontmatter.go
63 lines (52 loc) · 1.02 KB
/
frontmatter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package plugin
import (
"fmt"
"github.com/nehbit/html-to-markdown"
yaml "gopkg.in/yaml.v2"
)
// type frontMatterCallback func(selec *goquery.Selection) map[string]interface{}
// TODO: automatically convert to formats (look at hugo)
func EXPERIMENTAL_FrontMatter(format string) md.Plugin {
return func(c *md.Converter) []md.Rule {
data := make(map[string]interface{})
d, err := yaml.Marshal(data)
if err != nil {
panic(err)
}
fmt.Println(string(d))
/*
add rule for `head`
- get title
- return AdvancedResult{ Header: formated_yaml }, skip
-> added to head
-> others rules can apply
*/
title := "" // c.Find("head title").Text()
var text string
switch format {
case "toml": // +++
text = fmt.Sprintf(`
+++
title = "%s"
+++
`, title)
case "yaml": // ---
text = fmt.Sprintf(`
---
title: %s
---
`, title)
case "json": // { }
text = fmt.Sprintf(`
{
"title": "%s"
}
`, title)
default:
panic("unknown format")
}
_ = text
// c.AddLeading(text)
return nil
}
}