Skip to content

Commit 269911a

Browse files
committed
allow Markdown with Source property (not from file)
1 parent db565a9 commit 269911a

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

irc/irc.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,24 @@ func main() {
2020
return mes.Command == "PRIVMSG" && strings.HasPrefix(mes.Content, "quiki")
2121
},
2222
Action: func(irc *hbot.Bot, mes *hbot.Message) bool {
23-
lines := strings.TrimLeft(strings.TrimPrefix(mes.Content, "quiki"), " ,:")
24-
page := wikifier.NewPageSource(strings.Replace(lines, "_NL_", "\n", -1))
23+
line := strings.TrimLeft(strings.TrimPrefix(mes.Content, "quiki"), " ,:")
2524

25+
// markdown if starts with "md: "
26+
md := false
27+
withoutMd := strings.TrimPrefix(line, "md: ")
28+
if withoutMd != line {
29+
line = withoutMd
30+
md = true
31+
}
32+
33+
// create page
34+
page := wikifier.NewPageSource(strings.Replace(line, "_NL_", "\n", -1))
35+
if md {
36+
page.Markdown = true
37+
}
2638
var reply string
2739

28-
// html
40+
// parse/generate html
2941
if err := page.Parse(); err != nil {
3042
reply = err.Error()
3143
} else {
@@ -49,6 +61,9 @@ func main() {
4961

5062
// reply
5163
for _, line := range strings.Split(reply, "\n") {
64+
if line == "" {
65+
line = " "
66+
}
5267
irc.Send("PRIVMSG " + mes.To + " :" + line)
5368
}
5469

wikifier/page.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type Page struct {
3535
name string
3636
headingIDs map[string]int
3737
Wiki interface{} // only available during Parse() and HTML()
38-
markdown bool // true if FilePath points to a markdown source
38+
Markdown bool // true if this is a markdown source
3939
model bool // true if this is a model being generated
4040
Warnings []Warning // parser warnings
4141
Error *Warning // parser error, as an encodable Warning
@@ -83,7 +83,7 @@ func NewPage(filePath string) *Page {
8383
Models: make(map[string]ModelInfo),
8484
PageLinks: make(map[string][]int),
8585
headingIDs: make(map[string]int),
86-
markdown: strings.HasSuffix(filePath, ".md"),
86+
Markdown: strings.HasSuffix(filePath, ".md"),
8787
}
8888
}
8989

@@ -137,9 +137,12 @@ func (p *Page) _parse() error {
137137

138138
// create reader from file path or source code provided
139139
var reader io.Reader
140-
if p.Source != "" {
140+
if p.Markdown && p.Source != "" {
141+
d := markdown.Run([]byte(p.Source))
142+
reader = bytes.NewReader(d)
143+
} else if p.Source != "" {
141144
reader = strings.NewReader(p.Source)
142-
} else if p.markdown && p.FilePath != "" {
145+
} else if p.Markdown && p.FilePath != "" {
143146
md, err := ioutil.ReadFile(p.FilePath)
144147
if err != nil {
145148
return err

0 commit comments

Comments
 (0)