2020-10-05 02:23:57 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package print
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/charmbracelet/glamour"
|
|
|
|
)
|
|
|
|
|
2020-12-08 10:28:54 +00:00
|
|
|
// outputMarkdown prints markdown to stdout, formatted for terminals.
|
2020-10-05 02:23:57 +00:00
|
|
|
// If the input could not be parsed, it is printed unformatted, the error
|
|
|
|
// is returned anyway.
|
2020-12-08 10:28:54 +00:00
|
|
|
func outputMarkdown(markdown string) error {
|
2020-10-05 02:23:57 +00:00
|
|
|
out, err := glamour.Render(markdown, "auto")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf(markdown)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Print(out)
|
|
|
|
return nil
|
|
|
|
}
|