Permalink
Browse files

introduced prism.js syntax highlighter

  - fenced code blocks in markdown like in Github
  - will update while typing (triggered re-highlight in wiki.js)
  • Loading branch information...
Simon Wilper
Simon Wilper committed Apr 25, 2017
1 parent 2587ffa commit dc23ef8cddccba719790bac6007d867aa225323f
Showing with 163 additions and 0 deletions.
  1. +13 −0 lib/MojoMojo/Formatter/Markdown.pm
  2. +2 −0 root/base/header.tt
  3. +139 −0 root/static/css/prism.css
  4. +8 −0 root/static/js/prism.js
  5. +1 −0 root/static/js/wiki.js
@@ -2,6 +2,18 @@ package MojoMojo::Formatter::Markdown;
use parent qw/MojoMojo::Formatter/;
my %replace_map = (
'&' => '&',
'<' => '&lt;',
'>' => '&gt;'
);
sub esc {
my $source = shift;
$source =~ s/([&<>])/$replace_map{$1}/eg;
return $source;
}
my $markdown;
eval "use Text::MultiMarkdown";
unless ($@) {
@@ -54,6 +66,7 @@ sub main_format_content {
my ( $class, $content ) = @_;
return unless $markdown;
$$content =~ s/```(.+?)\n(.+?)```/"<pre><code class=\"language-$1\">\n".esc($2)."<\/code><\/pre>";/seg;
$$content = $markdown->markdown($$content);
}
View
@@ -11,6 +11,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="powered by" content="MojoMojo [%c.VERSION%]" />
<link href="[% c.uri_for_static('css/jquery.autocomplete.css')%]" type="text/css" rel="stylesheet" />
<link href="[% c.uri_for_static('css/prism.css')%]" type="text/css" rel="stylesheet" />
<link rel="alternate" type="application/atom+xml" title="Atom" href="[%c.uri_for('atom')%]" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0 Headlines" href="[%c.uri_for('rss')%]" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0 Full" href="[%c.uri_for('rss_full')%]" />
@@ -31,6 +32,7 @@
<script type="text/javascript" src="[%c.uri_for_static('js/jquery.editinplace.js')%]"></script>
<script type="text/javascript" src="[%c.uri_for_static('js/jquery.autocomplete.js')%]"></script>
<script type="text/javascript" src="[%c.uri_for_static('js/jquery.cookies.2.0.1.min.js')%]"></script>
<script type="text/javascript" src="[%c.uri_for_static('js/prism.js')%]"></script>
<script type="text/javascript" src="[%c.uri_for_static('js/wiki.js')%]"></script>
<script type="text/javascript" src="[%c.uri_for_static('js/swfupload.js')%]"></script>
<script type="text/javascript" src="[%c.uri_for_static('js/swfupload.queue.js')%]"></script>
View
@@ -0,0 +1,139 @@
/* http://prismjs.com/download.html?themes=prism&languages=clike+javascript+c+cpp+nginx+perl */
/**
* prism.js default theme for JavaScript, CSS and HTML
* Based on dabblet (http://dabblet.com)
* @author Lea Verou
*/
code[class*="language-"],
pre[class*="language-"] {
color: black;
background: none;
text-shadow: 0 1px white;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: #b3d4fc;
}
pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none;
background: #b3d4fc;
}
@media print {
code[class*="language-"],
pre[class*="language-"] {
text-shadow: none;
}
}
/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
}
:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #f5f2f0;
}
/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
white-space: normal;
}
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}
.token.punctuation {
color: #999;
}
.namespace {
opacity: .7;
}
.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
color: #905;
}
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #690;
}
.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
color: #a67f59;
background: hsla(0, 0%, 100%, .5);
}
.token.atrule,
.token.attr-value,
.token.keyword {
color: #07a;
}
.token.function {
color: #DD4A68;
}
.token.regex,
.token.important,
.token.variable {
color: #e90;
}
.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}
.token.entity {
cursor: help;
}
Oops, something went wrong.

0 comments on commit dc23ef8

Please sign in to comment.