Explorar el Código

Format non-markdown files as plain text

Even works with binaries, albeit very slow...  :)
Lu Stadler %!s(int64=7) %!d(string=hace) años
padre
commit
996b648c6d
Se han modificado 1 ficheros con 10 adiciones y 1 borrados
  1. 10 1
      go/tmpview/tmpview.go

+ 10 - 1
go/tmpview/tmpview.go

3
import (
3
import (
4
	"context"
4
	"context"
5
	"fmt"
5
	"fmt"
6
	"html/template"
6
	"io/ioutil"
7
	"io/ioutil"
7
	"log"
8
	"log"
8
	"net"
9
	"net"
9
	"net/http"
10
	"net/http"
10
	"os"
11
	"os"
11
	"os/exec"
12
	"os/exec"
13
	"strings"
12
	"time"
14
	"time"
13
15
14
	"github.com/russross/blackfriday"
16
	"github.com/russross/blackfriday"
39
41
40
			style := `body { max-width: 50em; margin: 0 auto; }`
42
			style := `body { max-width: 50em; margin: 0 auto; }`
41
			fmt.Fprintf(w, "<!doctype html><html><head><meta charset=\"utf-8\" /><title>%s</title><style>%s</style></head><body>\n\n\n", fileName, style)
43
			fmt.Fprintf(w, "<!doctype html><html><head><meta charset=\"utf-8\" /><title>%s</title><style>%s</style></head><body>\n\n\n", fileName, style)
42
			w.Write(blackfriday.MarkdownCommon(data))
44
			switch {
45
			case strings.HasSuffix(strings.ToLower(fileName), ".md"):
46
				w.Write(blackfriday.MarkdownCommon(data))
47
			default:
48
				fmt.Fprint(w, "<pre>\n")
49
				template.HTMLEscape(w, data)
50
				fmt.Fprint(w, "\n</pre>")
51
			}
43
			fmt.Fprintf(w, "\n\n\n</body></html>")
52
			fmt.Fprintf(w, "\n\n\n</body></html>")
44
		})
53
		})
45
54