forked from JohannesKaufmann/html-to-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontmatter.go
68 lines (58 loc) · 1.31 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
64
65
66
67
68
package plugin
import (
"fmt"
md "github.com/tomkosm/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)
// EXPERIMENTALFrontMatter was an experiment to add certain data
// from a callback function into the beginning of the file as frontmatter.
// It not really working right now.
//
// If someone has a need for it, let me know what your use-case is. Then
// I can create a plugin with a good interface.
func EXPERIMENTALFrontMatter(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
}
}