Try syntax highlighting
This commit is contained in:
parent
2d8aa75257
commit
3d22aa63fd
|
@ -0,0 +1,54 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
||||
<title>%s</title>
|
||||
|
||||
<!-- Material Design fonts -->
|
||||
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Roboto:300,400,500,700">
|
||||
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/icon?family=Material+Icons">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
|
||||
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/bootstrap.material-design/0.5.10/css/bootstrap-material-design.min.css" integrity="sha256-j3CLSRG31GkOu6kaeLh7XsRgL2YNvRl9aOtXoAYt320=" crossorigin="anonymous">
|
||||
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/bootstrap.material-design/0.5.10/css/ripples.min.css" integrity="sha256-+Og2qJI9qzvKYwhGo/LYXg0FzE1BhEQfDsUSjKXQ3Bg=" crossorigin="anonymous">
|
||||
|
||||
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h1>%s</h1>
|
||||
</div>
|
||||
|
||||
<div class="well" style="padding-top: 10px;">
|
||||
%s
|
||||
</div>
|
||||
|
||||
<div class="pull-right">
|
||||
<a href="%s" class="btn btn-raised btn-primary">Raw</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
||||
<!-- Include all compiled plugins (below), or include individual files as needed -->
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/bootstrap.material-design/0.5.10/js/material.min.js" integrity="sha256-uZbIqasulk7Y9yEwknbeQ0FpF3aUhtPwuggbpvQaI8Y=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/bootstrap.material-design/0.5.10/js/ripples.min.js" integrity="sha256-TY/EO/++Ug/P+fSBjaqlmtuphCBKwlP7TOnS+SGnN8g=" crossorigin="anonymous"></script>
|
||||
<script>
|
||||
$.material.init();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
16
main.go
16
main.go
|
@ -10,6 +10,7 @@ import (
|
|||
"html"
|
||||
"html/template"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
|
@ -212,7 +213,14 @@ func getPaste(paste string, lang string) string {
|
|||
if err == sql.ErrNoRows {
|
||||
return "Error invalid paste"
|
||||
} else {
|
||||
if lang == "" {
|
||||
return html.UnescapeString(s)
|
||||
} else {
|
||||
high, err := highlight(s, lang)
|
||||
check(err)
|
||||
return high
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -223,6 +231,7 @@ func pasteHandler(w http.ResponseWriter, r *http.Request) {
|
|||
lang := vars["lang"]
|
||||
s := getPaste(paste, lang)
|
||||
link := ADDRESS + "/raw/" + paste
|
||||
if lang == "" {
|
||||
p := &Page{
|
||||
Title: paste,
|
||||
Body: []byte(s),
|
||||
|
@ -233,6 +242,13 @@ func pasteHandler(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
t.Execute(w, p)
|
||||
|
||||
} else {
|
||||
dat, err := ioutil.ReadFile("assets/syntax.html")
|
||||
check(err)
|
||||
fmt.Fprintf(w, string(dat), paste, paste, highlight, link)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func rawHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
Loading…
Reference in New Issue