]> git.ipfire.org Git - ipfire.org.git/commitdiff
nopaste: Make code prettifying work again
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 Oct 2018 13:36:31 +0000 (14:36 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 Oct 2018 13:36:31 +0000 (14:36 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/templates/nopaste/modules/code.html [new file with mode: 0644]
src/templates/nopaste/view.html
src/web/__init__.py
src/web/nopaste.py

index 4c6faf200476532c233783df92f582d337cd5dd6..7a3ef5870e50f24cbfeed9fb7c735e8de10e15eb 100644 (file)
@@ -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 (file)
index 0000000..9feae42
--- /dev/null
@@ -0,0 +1 @@
+<pre class="prettyprint linenums mb-0">{{ content }}</pre>
index dc7d1253df4650debae38f7eee0e2f68608bd2d0..6a2e6a887fb90c87718eb3baf61add2536ef77c6 100644 (file)
                                        <hr>
 
                                        {% if content %}
-                                               <pre class="prettyprint linenums" style="min-height: 25em">{{ content }}</pre>
-
-                                               <link rel="stylesheet" href="{{ static_url("css/prettify.css") }}">
-                                               <script src="{{ static_url("js/prettify.js") }}"></script>
-                                               <script>prettyPrint()</script>
-
+                                               {% module Code(content) %}
                                        {% elif entry.mimetype.startswith("image/") %}
                                                <img class="img-fluid" src="/raw/{{ entry.uuid }}">
                                        {% else %}
index 09a3826fffc9233fa64fff95cf01ccaeb35a3e4e..84d0e501beacca63b096a760d95e35b3a763ae6c 100644 (file)
@@ -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,
 
index 34a5d4887378dc8e080ba060f932ba94a7c23c02..13917cfc275cb40e06f5565f8cb885b002df9f91 100644 (file)
@@ -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();
+               """