Skip to content

Commit

Permalink
Add new option: -plaintext
Browse files Browse the repository at this point in the history
  • Loading branch information
hymkor committed May 7, 2023
1 parent eaeabd4 commit 34c07af
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import (
)

var (
flagIndex = flag.String("index", "index.html,README.md,INDEX.md", "the default page when URL is directory")
flagPerl = flag.Bool("perl", false, "Enable Perl as handler for *.pl")
flagPort = flag.Uint64("p", 8000, "Port number")
flagWd = flag.String("C", "", "Working directory")
flagHtml = flag.Bool("html", false, "Enable raw htmls in *.md")
flagWrap = flag.Bool("hardwrap", false, "Enable hard wrap in *.md")
flagIndex = flag.String("index", "index.html,README.md,INDEX.md", "the default page when URL is directory")
flagPerl = flag.Bool("perl", false, "Enable Perl as handler for *.pl")
flagPort = flag.Uint64("p", 8000, "Port number")
flagWd = flag.String("C", "", "Working directory")
flagHtml = flag.Bool("html", false, "Enable raw htmls in *.md")
flagWrap = flag.Bool("hardwrap", false, "Enable hard wrap in *.md")
flagPlainText = flag.String("plaintext", "", "output as plaintext(e.g. `-plaintext .cpp.h`)")
)

type Config struct {
Expand Down Expand Up @@ -55,6 +56,7 @@ var fileServeSuffix = map[string]string{
".jpg": "image/jpg",
".png": "image/jpg",
".html": "text/html",
".txt": "text/plain",
}

func findPathInsteadOfDirectory(dir string) string {
Expand Down Expand Up @@ -164,6 +166,18 @@ func mains(args []string) error {
if *flagWrap {
handler.Config.Markdown.HardWrap = true
}
if t := *flagPlainText; t != "" {
for {
first, next, found := strings.Cut(t, ".")
if first != "" {
fileServeSuffix["."+first] = "text/plain"
}
if !found {
break
}
t = next
}
}

setMarkdownOptions(handler.Config.Markdown.Html, handler.Config.Markdown.HardWrap)
handler.notFound = http.NotFoundHandler()
Expand Down

0 comments on commit 34c07af

Please sign in to comment.