Merge branch 'atomaka/feature/syntax-highlighting' into 'master'

Syntax Highlighting

Implement syntax highlighting using highlight.js.  This is the simplest method for implementing syntax highlighting.  Consider moving the line numbering into Ruby code instead of handling it through JavaScript.
This commit is contained in:
Andrew Tomaka 2014-03-09 15:29:18 -04:00
commit 9870038644
7 changed files with 190 additions and 4 deletions

View file

@ -14,4 +14,5 @@
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require highlight.min
//= require_tree .

View file

@ -1,3 +1,13 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
$(document).on 'ready page:load', ->
$(".code pre code").each (i, e) ->
hljs.highlightBlock e
numberLines e
numberLines = (e) ->
$('.line-numbers').html([1..lineCount(e)].join("<br/>"))
lineCount = (e) ->
$(e).html().split("\n").length - 1

View file

@ -0,0 +1,150 @@
/*
Original style from softwaremaniacs.org (c) Ivan Sagalaev <Maniac@SoftwareManiacs.Org>
*/
.hljs {
display: block;
background: #f0f0f0;
}
.hljs,
.hljs-subst,
.hljs-tag .hljs-title,
.lisp .hljs-title,
.clojure .hljs-built_in,
.nginx .hljs-title {
color: black;
}
.hljs-string,
.hljs-title,
.hljs-constant,
.hljs-parent,
.hljs-tag .hljs-value,
.hljs-rules .hljs-value,
.hljs-preprocessor,
.hljs-pragma,
.haml .hljs-symbol,
.ruby .hljs-symbol,
.ruby .hljs-symbol .hljs-string,
.hljs-template_tag,
.django .hljs-variable,
.smalltalk .hljs-class,
.hljs-addition,
.hljs-flow,
.hljs-stream,
.bash .hljs-variable,
.apache .hljs-tag,
.apache .hljs-cbracket,
.tex .hljs-command,
.tex .hljs-special,
.erlang_repl .hljs-function_or_atom,
.asciidoc .hljs-header,
.markdown .hljs-header,
.coffeescript .hljs-attribute {
color: #800;
}
.smartquote,
.hljs-comment,
.hljs-annotation,
.hljs-template_comment,
.diff .hljs-header,
.hljs-chunk,
.asciidoc .hljs-blockquote,
.markdown .hljs-blockquote {
color: #888;
}
.hljs-number,
.hljs-date,
.hljs-regexp,
.hljs-literal,
.hljs-hexcolor,
.smalltalk .hljs-symbol,
.smalltalk .hljs-char,
.go .hljs-constant,
.hljs-change,
.lasso .hljs-variable,
.makefile .hljs-variable,
.asciidoc .hljs-bullet,
.markdown .hljs-bullet,
.asciidoc .hljs-link_url,
.markdown .hljs-link_url {
color: #080;
}
.hljs-label,
.hljs-javadoc,
.ruby .hljs-string,
.hljs-decorator,
.hljs-filter .hljs-argument,
.hljs-localvars,
.hljs-array,
.hljs-attr_selector,
.hljs-important,
.hljs-pseudo,
.hljs-pi,
.haml .hljs-bullet,
.hljs-doctype,
.hljs-deletion,
.hljs-envvar,
.hljs-shebang,
.apache .hljs-sqbracket,
.nginx .hljs-built_in,
.tex .hljs-formula,
.erlang_repl .hljs-reserved,
.hljs-prompt,
.asciidoc .hljs-link_label,
.markdown .hljs-link_label,
.vhdl .hljs-attribute,
.clojure .hljs-attribute,
.asciidoc .hljs-attribute,
.lasso .hljs-attribute,
.coffeescript .hljs-property,
.hljs-phony {
color: #88f;
}
.hljs-keyword,
.hljs-id,
.hljs-title,
.hljs-built_in,
.css .hljs-tag,
.hljs-javadoctag,
.hljs-phpdoc,
.hljs-yardoctag,
.smalltalk .hljs-class,
.hljs-winutils,
.bash .hljs-variable,
.apache .hljs-tag,
.go .hljs-typename,
.tex .hljs-command,
.asciidoc .hljs-strong,
.markdown .hljs-strong,
.hljs-request,
.hljs-status {
font-weight: bold;
}
.asciidoc .hljs-emphasis,
.markdown .hljs-emphasis {
font-style: italic;
}
.nginx .hljs-built_in {
font-weight: normal;
}
.coffeescript .javascript,
.javascript .xml,
.lasso .markup,
.tex .hljs-formula,
.xml .javascript,
.xml .vbscript,
.xml .css,
.xml .hljs-cdata {
opacity: 0.5;
}

View file

@ -1,3 +1,26 @@
// Place all the styles related to the pastes controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
.paste {
.line-numbers {
float: left;
padding: 10px;
margin: 1px 10px 0 0;
border-right: 1px solid;
line-height: 1.5;
font-size: 12px;
font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
text-align: right;
}
pre {
margin: 0;
padding: 10px;
.code {
margin: 0;
font-size: 12px;
}
}
}

View file

@ -1,7 +1,7 @@
<%= form_for @paste do |f| %>
<div class="form-group">
<%= f.label :content %>
<%= f.text_area :content, class: 'form-control' %>
<%= f.text_area :content, class: 'form-control', rows: 15 %>
</div>
<%= f.submit 'Paste it!', class: 'btn btn-primary' %>
<% end %>

View file

@ -1,3 +1,4 @@
<pre class="prettyprint linenums">
<%= @paste.content %>
</pre>
<div class="paste">
<div class="line-numbers"></div>
<div class="code"><pre><code><%= @paste.content %></code></pre></div>
</div>

File diff suppressed because one or more lines are too long