2020-06-25 20:31:58 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
|
2020-07-04 17:17:08 +00:00
|
|
|
"github.com/bouncepaw/mycorrhiza/plugin"
|
2020-06-30 18:13:46 +00:00
|
|
|
"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>?
|
|
|
|
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 {
|
2020-07-04 17:17:08 +00:00
|
|
|
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.
|
2020-07-04 17:17:08 +00:00
|
|
|
parser := plugin.ParserForMime(rev.TextMime)
|
|
|
|
ret += parser(contents)
|
2020-06-25 20:31:58 +00:00
|
|
|
|
|
|
|
ret += `
|
|
|
|
</article>`
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|