Add more languages for code syntax highlighting

This commit is contained in:
Seednode 2023-09-14 21:02:48 -05:00
parent 8923a4c14d
commit 28bc560098
4 changed files with 104 additions and 20 deletions

View File

@ -11,7 +11,7 @@ import (
)
const (
ReleaseVersion string = "0.84.1"
ReleaseVersion string = "0.84.2"
)
var (
@ -21,6 +21,7 @@ var (
Cache bool
CacheFile string
Code bool
Debug bool
Filtering bool
Flash bool
Handlers bool
@ -70,6 +71,7 @@ func init() {
rootCmd.Flags().BoolVarP(&Cache, "cache", "c", false, "generate directory cache at startup")
rootCmd.Flags().StringVar(&CacheFile, "cache-file", "", "path to optional persistent cache file")
rootCmd.Flags().BoolVar(&Code, "code", false, "enable support for source code files")
rootCmd.Flags().BoolVar(&Debug, "debug", false, "display debug information")
rootCmd.Flags().BoolVarP(&Filtering, "filter", "f", false, "enable filtering")
rootCmd.Flags().BoolVar(&Flash, "flash", false, "enable support for shockwave flash files (via ruffle.rs)")
rootCmd.Flags().BoolVar(&Handlers, "handlers", false, "display registered handlers (for debugging)")

View File

@ -49,6 +49,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle {
if err != nil {
fmt.Println(err)
if Debug {
fmt.Printf("Call to stripQueryParams(%v) failed inside serveStaticFile()\n", path)
}
serverError(w, r, nil)
return
@ -58,6 +61,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle {
if err != nil {
fmt.Println(err)
if Debug {
fmt.Printf("Call to filepath.EvalSymlinks(%v) failed inside serveStaticFile()\n", strings.TrimPrefix(prefixedFilePath, prefix))
}
serverError(w, r, nil)
return
@ -71,8 +77,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle {
exists, err := fileExists(filePath)
if err != nil {
fmt.Println(err)
if Debug {
fmt.Printf("Call to fileExists(%v) failed inside serveStaticFile()\n", filePath)
}
serverError(w, r, nil)
return
@ -88,8 +95,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle {
buf, err := os.ReadFile(filePath)
if err != nil {
fmt.Println(err)
if Debug {
fmt.Printf("Call to os.ReadFile(%v) failed inside serveStaticFile()\n", filePath)
}
serverError(w, r, nil)
return
@ -102,7 +110,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle {
if Russian {
err = os.Remove(filePath)
if err != nil {
fmt.Println(err)
if Debug {
fmt.Printf("Call to os.Remove(%v) failed inside serveStaticFile()\n", filePath)
}
serverError(w, r, nil)

View File

@ -123,8 +123,90 @@ func (t Format) Body(rootUrl, fileUri, filePath, fileName, prefix, mime string)
func (t Format) Extensions() map[string]string {
return map[string]string{
`.go`: `text/plain`,
`.sh`: `application/x-sh`,
`.4th`: ``,
`.abap`: ``,
`.ada`: ``,
`.ahk`: ``,
`.as`: ``,
`.awk`: ``,
`.bat`: ``,
`.bib`: ``,
`.bibtex`: ``,
`.c`: ``,
`.clj`: ``,
`.cljc`: ``,
`.cljs`: ``,
`.coffee`: ``,
`.conf`: ``,
`.cpp`: ``,
`.cr`: ``,
`.cs`: ``,
`.css`: ``,
`.d`: ``,
`.elm`: ``,
`.erl`: ``,
`.ex`: ``,
`.exs`: ``,
`.f03`: ``,
`.f90`: ``,
`.f95`: ``,
`.fs`: ``,
`.go`: ``,
`.graphql`: ``,
`.groovy`: ``,
`.gsh`: ``,
`.gvy`: ``,
`.gy`: ``,
`.hc`: ``,
`.hcl`: ``,
`.hs`: ``,
`.java`: ``,
`.jinja`: ``,
`.jl`: ``,
`.js`: ``,
`.json`: ``,
`.kt`: ``,
`.lisp`: ``,
`.lsp`: ``,
`.lua`: ``,
`.m`: ``,
`.md`: ``,
`.ml`: ``,
`.nb`: ``,
`.nim`: ``,
`.nix`: ``,
`.php`: ``,
`.pl`: ``,
`.pp`: ``,
`.proto`: ``,
`.ps`: ``,
`.ps1`: ``,
`.psl`: ``,
`.py`: ``,
`.r`: ``,
`.raku`: ``,
`.rb`: ``,
`.rs`: ``,
`.sass`: ``,
`.sc`: ``,
`.scm`: ``,
`.scss`: ``,
`.scpt`: ``,
`.sh`: ``,
`.sql`: ``,
`.swift`: ``,
`.tcl`: ``,
`.tex`: ``,
`.tf`: ``,
`.toml`: ``,
`.ts`: ``,
`.unit`: ``,
`.v`: ``,
`.vb`: ``,
`.xml`: ``,
`.yaml`: ``,
`.yml`: ``,
`.zig`: ``,
}
}

View File

@ -44,18 +44,8 @@ func (t Format) Body(rootUrl, fileUri, filePath, fileName, prefix, mime string)
func (t Format) Extensions() map[string]string {
return map[string]string{
`.css`: `text/css`,
`.csv`: `text/csv`,
`.js`: `text/javascript`,
`.json`: `application/json`,
`.md`: `text/markdown`,
`.ps1`: `text/plain`,
`.sh`: `application./x-sh`,
`.toml`: `application/toml`,
`.txt`: `text/plain`,
`.xml`: `application/xml`,
`.yml`: `application/yaml`,
`.yaml`: `application/yaml`,
`.csv`: `text/csv`,
`.txt`: `text/plain`,
}
}