Skip to content

Instantly share code, notes, and snippets.

@insteps
Created July 30, 2015 10:16
Show Gist options
  • Save insteps/70315bcaeb4b28734138 to your computer and use it in GitHub Desktop.
Save insteps/70315bcaeb4b28734138 to your computer and use it in GitHub Desktop.
turbo-paste, add get option format
From 50e35277923004a7c13d513ae110953475dd9e54 Mon Sep 17 00:00:00 2001
From: "V.Krishn" <vkrishn4@gmail.com>
Date: Wed, 29 Jul 2015 17:29:00 +0000
Subject: [PATCH] add format=<filename>
---
tpl/highlight2.tpl | 23 +++++++++++++++++++++++
turbo-paste.lua | 13 ++++++++++---
2 files changed, 33 insertions(+), 3 deletions(-)
create mode 100644 tpl/highlight2.tpl
diff --git a/tpl/highlight2.tpl b/tpl/highlight2.tpl
new file mode 100644
index 0000000..18544d9
--- /dev/null
+++ b/tpl/highlight2.tpl
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Turbo paste</title>
+ <style>
+ body { margin:0;padding:0;background:#000; }
+ pre { margin:0; }
+ </style>
+ <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/sunburst.min.css">
+ <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/highlight.min.js"></script>
+ </head>
+ <body id='body'>
+ <pre>
+<code>{{{paste}}}</code>
+ </pre>
+ <script>
+ var body = document.getElementById('body');
+ codes = body.getElementsByTagName('code');
+ for (c in codes) { codes[c].className='{{{format}}}'; hljs.highlightBlock(codes[c]); }
+ </script>
+ </body>
+</html>
diff --git a/turbo-paste.lua b/turbo-paste.lua
index d6da451..88cdb45 100755
--- a/turbo-paste.lua
+++ b/turbo-paste.lua
@@ -8,7 +8,7 @@
-- kwargs: arguments passed on to HTTPServer
local conf = {
salt = "CHANGE ME!",
- url = "http://172.16.3.80:8888/",
+ url = "http://localhost:8888/",
port = 8888,
address = "0.0.0.0",
kwargs = {
@@ -60,13 +60,20 @@ end
local GetPasteHandler = class("GetPasteHandler", turbo.web.RequestHandler)
function GetPasteHandler:get(hash)
+ local t = {}
local paste = yield(redis:get(hash, paste))
if not paste then
error(turbo.web.HTTPError(404, "404 Not found."))
end
local hl = self:get_argument("hl", false)
- if hl == "true" then
- self:write(tpl:render("highlight.tpl", {paste = paste}))
+ local format = self:get_argument("format", false)
+ t['paste'] = paste
+ t['format'] = format
+ -- need to sanitize 'format'
+ if hl == "true" and not format then
+ self:write(tpl:render("highlight.tpl", t))
+ elseif format then
+ self:write(tpl:render("highlight2.tpl", t))
else
self:add_header("Content-Type", "text/plain; charset=UTF-8")
self:write(paste)
--
2.4.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment