+%# -*-html-*-
+%#
+%# Pastebin display webservice for Odin
+%#
+%# (c) 2015 Mark Wooding
+%#
+%#----- Licensing notice ----------------------------------------------------
+%#
+%# This file is part of the `odin.gg' service, `odin-cgi'.
+%#
+%# `odin-cgi' is free software; you can redistribute it and/or modify
+%# it under the terms of the GNU Affero General Public License as
+%# published by the Free Software Foundation; either version 3 of the
+%# License, or (at your option) any later version.
+%#
+%# `odin-cgi' is distributed in the hope that it will be useful,
+%# but WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+%# GNU Affero General Public License for more details.
+%#
+%# You should have received a copy of the GNU Affero General Public
+%# License along with `odin-cgi'; if not, see
+%# <http://www.gnu.org/licenses/>.
+%#
<&| SELF:wrapper,
title => Odin::escapify($m, $title) . " (odin.gg Paste Bin)" &>
<h1><tt>odin.gg</tt> Paste Bin: <% $title %></h1>
<div class="menu">
- <span class="item"><a href="<% "$Odin::PASTEBIN/$tag?op=raw" %>">Raw</a></span>
+ <span class="item"><a href="<% "$Odin::PASTEBIN/$tag?op=raw" |h %>">Raw</a></span>
% if (defined $edit) {
- <span class="item"><a href="<% "$Odin::PASTEBIN/$tag?edit=$edit" %>">Edit</a></span>
+ <span class="item"><a href="<% "$Odin::PASTEBIN/$tag?edit=$edit" |h %>">Edit</a></span>
% }
+ <span class="item"><a href="<% "$Odin::PASTEBIN/" |h %>">New</a></span>
</div>
-<pre class="paste">
+% if (defined $honc) {
+<div class="note">
+<p>Your browser doesn't appear to be accepting my cookies.
+<p>Don't share the link to this page with other people. <b>If you do,
+ they'll be able to edit this paste just as you can</b>, using the
+ <b>Edit</b> link at the top of the page.
+<p>Instead, share this link:
+ <a href="<% "$Odin::PASTEBIN/$tag" |h %>"><%
+ "$Odin::PASTEBIN/$tag" |h %></a>
+</div>
+% }
% if ($lang eq 'txt') {
+<pre class="paste">
<% $content |h %>\
+</pre>
+% } elsif ($lang =~ /^hl:(.*)$/) {
+<pre class="paste">
+% filter "highlight", $m, $content,
+% "highlight", "-Ohtml", "-f", "-t8", "-S$1";
+</pre>
+% } elsif ($lang eq "md") {
+% filter "markdown", $m, $content,
+% "markdown", "-fnohtml,autolink,safelink,footnote";
% } else {
-<%perl>
- my $kid = open my $fh, "-|" // die "fork: $!";
- if ($kid == 0) {
- open my $hl, "|-", "highlight", "-Ohtml", "-f", "-t8", "-S$lang"
- or die "open highlight: $!";
- syswrite $hl, $content // die "highlight write: $!";
- close $hl or die "highlight kid: $!, $?";
- exit 0;
- } else {
- while (sysread $fh, my $buf, 8192) { $m->print($buf); }
- close $fh and waitpid $kid, 0
- or die "highlight parent: $!, $?";
- }
-</%perl>
-% }
+<div class="note">
+<p>I don't know how to display content with language
+ ‘<% $lang |h %>’. This is a bug in the Pastebin program.
+ Here's the raw text, in case that's useful.
+</div>
+<pre class="paste">
+<% $content |h %>\
</pre>
+% }
</&>
%#
<%args>
$title
$lang
$tag
+ $honc
$edit
</%args>
%#
%#
<%once>
use utf8;
+ use POSIX qw(_exit);
+
+ sub filter ($$$@) {
+ my ($what, $m, $content, @cmd) = @_;
+ my $kid = open my $fh, "-|" // die "fork: $!";
+ if ($kid == 0) {
+ open my $hl, "|-", @cmd or die "open $what: $!";
+ syswrite $hl, $content // die "$what write: $!";
+ close $hl or die "$what kid: $!, $?";
+ _exit 0;
+ } else {
+ while (sysread $fh, my $buf, 8192) { $m->print($buf); }
+ close $fh and waitpid $kid, 0
+ or die "$what parent: $!, $?";
+ }
+ }
</%once>