1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-14 22:20:25 +00:00
mycorrhiza/fs/html.go

39 lines
857 B
Go
Raw Normal View History

2020-06-25 20:31:58 +00:00
package fs
import (
"fmt"
"io/ioutil"
"log"
"github.com/bouncepaw/mycorrhiza/plugin"
"github.com/bouncepaw/mycorrhiza/util"
2020-06-25 20:31:58 +00:00
)
func (h *Hypha) asHtml() (string, error) {
rev := h.actual
ret := `<article class="page">
<h1 class="page__title">` + rev.FullName + `</h1>
`
// What about using <figure>?
2020-07-17 15:18:03 +00:00
// TODO: support other things
2020-06-25 20:31:58 +00:00
if h.hasBinaryData() {
2020-07-03 19:20:56 +00:00
ret += fmt.Sprintf(`<img src="/:%s?action=binary&rev=%d" class="page__amnt"/>`, util.DisplayToCanonical(rev.FullName), rev.Id)
2020-06-25 20:31:58 +00:00
}
contents, err := ioutil.ReadFile(rev.TextPath)
if err != nil {
log.Println("Failed to read contents of", rev.FullName, ":", err)
2020-06-25 20:31:58 +00:00
return "", err
}
// TODO: support more markups.
// TODO: support mycorrhiza extensions like transclusion.
parser := plugin.ParserForMime(rev.TextMime)
ret += parser(contents)
2020-06-25 20:31:58 +00:00
ret += `
</article>`
return ret, nil
}