From e1814f16834ffba246ad912d1d757f705d98dcdc Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 22 Oct 2018 14:36:31 +0100 Subject: [PATCH] nopaste: Make code prettifying work again Signed-off-by: Michael Tremer --- Makefile.am | 13 ++++++++++++- src/templates/nopaste/modules/code.html | 1 + src/templates/nopaste/view.html | 7 +------ src/web/__init__.py | 3 +++ src/web/nopaste.py | 18 ++++++++++++++++++ 5 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 src/templates/nopaste/modules/code.html diff --git a/Makefile.am b/Makefile.am index 4c6faf20..7a3ef587 100644 --- a/Makefile.am +++ b/Makefile.am @@ -156,6 +156,11 @@ templates_nopaste_DATA = \ templates_nopastedir = $(templatesdir)/nopaste +templates_nopaste_modules_DATA = \ + src/templates/nopaste/modules/code.html + +templates_nopaste_modulesdir = $(templates_nopastedir)/modules + templates_people_DATA = \ src/templates/people/base.html \ src/templates/people/conferences.html \ @@ -226,6 +231,11 @@ EXTRA_DIST += \ staticdir = $(datadir)/static +static_css_DATA = \ + src/static/css/prettify.css + +static_cssdir = $(staticdir)/css + static_fonts_DATA = \ src/fonts/ofl/mukta/Mukta-Bold.ttf \ src/fonts/ofl/mukta/Mukta-ExtraBold.ttf \ @@ -294,7 +304,8 @@ static_js_DATA = \ src/bootstrap/dist/js/bootstrap.min.js.map \ \ src/static/js/jquery-3.3.1.min.js \ - src/static/js/popper.min.js + src/static/js/popper.min.js \ + src/static/js/prettify.js static_jsdir = $(staticdir)/js diff --git a/src/templates/nopaste/modules/code.html b/src/templates/nopaste/modules/code.html new file mode 100644 index 00000000..9feae42d --- /dev/null +++ b/src/templates/nopaste/modules/code.html @@ -0,0 +1 @@ +
{{ content }}
diff --git a/src/templates/nopaste/view.html b/src/templates/nopaste/view.html index dc7d1253..6a2e6a88 100644 --- a/src/templates/nopaste/view.html +++ b/src/templates/nopaste/view.html @@ -40,12 +40,7 @@
{% if content %} -
{{ content }}
- - - - - + {% module Code(content) %} {% elif entry.mimetype.startswith("image/") %} {% else %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 09a3826f..84d0e501 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -67,6 +67,9 @@ class Application(tornado.web.Application): "Registrations" : people.RegistrationsModule, "SIPStatus" : people.SIPStatusModule, + # Nopaste + "Code" : nopaste.CodeModule, + # Old modules "LanguageName" : ui_modules.LanguageNameModule, diff --git a/src/web/nopaste.py b/src/web/nopaste.py index 34a5d488..13917cfc 100644 --- a/src/web/nopaste.py +++ b/src/web/nopaste.py @@ -3,6 +3,7 @@ import tornado.web from . import handlers_base as base +from . import ui_modules class CreateHandler(base.BaseHandler): MODES = ("paste", "upload") @@ -95,3 +96,20 @@ class ViewHandler(base.BaseHandler): content = None self.render("nopaste/view.html", entry=entry, content=content) + + +class CodeModule(ui_modules.UIModule): + def render(self, content): + return self.render_string("nopaste/modules/code.html", content=content) + + def javascript_files(self): + return "js/prettify.js" + + def css_files(self): + return "css/prettify.css" + + def embedded_javascript(self): + return """ + // Run pretty print + prettyPrint(); + """ -- 2.47.3