Skip to content

Commit

Permalink
change how codes are highlighteg
Browse files Browse the repository at this point in the history
  • Loading branch information
TIOJ authored and TIOJ committed Jan 13, 2015
1 parent 556342d commit ea9c201
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 921 deletions.
13 changes: 13 additions & 0 deletions app/helpers/submissions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,17 @@ def censored(s)
end
return false
end

def language_class(lang)
case lang
when "c++11", "c++"
return "language-cpp"
when "c"
return "language-c"
when "haskell"
return "language-haskell"
else
return "language-clike"
end
end
end
9 changes: 5 additions & 4 deletions app/views/submissions/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<%= javascript_include_tag "/stylesheets/prism.js" %>
<%= stylesheet_link_tag "/stylesheets/prism.css" %>

<% if censored(@submission) %>
<h4 class="page-header">Results of submission #<code>censored</code></h4>
<code>censored</code>
Expand Down Expand Up @@ -124,9 +121,13 @@
</div>

<% if user_signed_in? and ( current_user.admin? or current_user.id == @submission.user_id ) %>
<pre class="line-numbers"><code class="<%= @submission.compiler == "c" ? "language-c" : "language-cpp" %>"><%= @submission.code %></code></pre>
<pre class="line-numbers"><code class="<%= language_class(@submission.compiler) %>"><%= @submission.code %></code></pre>
<% end %>

<%= link_to 'Back to Top', '#', :class => 'btn btn-default btn-xs' %>

<% end %>

<%= javascript_include_tag "/codehighlighter/prism.js" %>
<%= stylesheet_link_tag "/codehighlighter/prism.css" %>

160 changes: 160 additions & 0 deletions public/codehighlighter/prism.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/* http://prismjs.com/download.html?themes=prism-okaidia&languages=clike+c+cpp+haskell&plugins=line-numbers */
/**
* okaidia theme for JavaScript, CSS and HTML
* Loosely based on Monokai textmate theme by http://www.monokai.nl/
* @author ocodia
*/

code[class*="language-"],
pre[class*="language-"] {
color: #f8f8f2;
text-shadow: 0 1px rgba(0, 0, 0, 0.3);
font-family: Consolas, Monaco, 'Andale Mono', monospace;
direction: ltr;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: 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;
}

/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
border-radius: 0.3em;
}

:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #272822;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}

.token.punctuation {
color: #f8f8f2;
}

.namespace {
opacity: .7;
}

.token.property,
.token.tag,
.token.constant,
.token.symbol,
.token.deleted {
color: #f92672;
}

.token.boolean,
.token.number {
color: #ae81ff;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #a6e22e;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string,
.token.variable {
color: #f8f8f2;
}

.token.atrule,
.token.attr-value {
color: #e6db74;
}

.token.keyword {
color: #66d9ef;
}

.token.regex,
.token.important {
color: #fd971f;
}

.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}

.token.entity {
cursor: help;
}

pre.line-numbers {
position: relative;
padding-left: 3.8em;
counter-reset: linenumber;
}

pre.line-numbers > code {
position: relative;
}

.line-numbers .line-numbers-rows {
position: absolute;
pointer-events: none;
top: 0;
font-size: 100%;
left: -3.8em;
width: 3em; /* works for line-numbers below 1000 lines */
letter-spacing: -1px;
border-right: 1px solid #999;

-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;

}

.line-numbers-rows > span {
pointer-events: none;
display: block;
counter-increment: linenumber;
}

.line-numbers-rows > span:before {
content: counter(linenumber);
color: #999;
display: block;
padding-right: 0.8em;
text-align: right;
}
7 changes: 7 additions & 0 deletions public/codehighlighter/prism.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ea9c201

Please sign in to comment.