Skip to content

Commit

Permalink
シンタックスハイライトにrougeを使用
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki384 committed Jun 11, 2020
1 parent db9b429 commit 0520724
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,6 @@ end
gem "ibm_db" if ENV["IBM_DB"]
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem "wdm", ">= 0.1.0", platforms: [:mingw, :mswin, :x64_mingw, :mswin64]

# SyntaxHighlight
gem "rouge"
210 changes: 210 additions & 0 deletions guides/assets/stylesheets/rouge_highlight_github.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
/* https://github.com/rouge-ruby/rouge/blob/master/lib/rouge/themes/github.rb */
.highlight table td { padding: 5px; }
.highlight table pre { margin: 0; }
.highlight .cm {
color: #999988;
font-style: italic;
}
.highlight .cp {
color: #999999;
font-weight: bold;
}
.highlight .c1 {
color: #999988;
font-style: italic;
}
.highlight .cs {
color: #999999;
font-weight: bold;
font-style: italic;
}
.highlight .c, .highlight .cd {
color: #999988;
font-style: italic;
}
.highlight .err {
color: #a61717;
background-color: #e3d2d2;
}
.highlight .gd {
color: #000000;
background-color: #ffdddd;
}
.highlight .ge {
color: #000000;
font-style: italic;
}
.highlight .gr {
color: #aa0000;
}
.highlight .gh {
color: #999999;
}
.highlight .gi {
color: #000000;
background-color: #ddffdd;
}
.highlight .go {
color: #888888;
}
.highlight .gp {
color: #555555;
}
.highlight .gs {
font-weight: bold;
}
.highlight .gu {
color: #aaaaaa;
}
.highlight .gt {
color: #aa0000;
}
.highlight .kc {
color: #000000;
font-weight: bold;
}
.highlight .kd {
color: #000000;
font-weight: bold;
}
.highlight .kn {
color: #000000;
font-weight: bold;
}
.highlight .kp {
color: #000000;
font-weight: bold;
}
.highlight .kr {
color: #000000;
font-weight: bold;
}
.highlight .kt {
color: #445588;
font-weight: bold;
}
.highlight .k, .highlight .kv {
color: #000000;
font-weight: bold;
}
.highlight .mf {
color: #009999;
}
.highlight .mh {
color: #009999;
}
.highlight .il {
color: #009999;
}
.highlight .mi {
color: #009999;
}
.highlight .mo {
color: #009999;
}
.highlight .m, .highlight .mb, .highlight .mx {
color: #009999;
}
.highlight .sb {
color: #d14;
}
.highlight .sc {
color: #d14;
}
.highlight .sd {
color: #d14;
}
.highlight .s2 {
color: #d14;
}
.highlight .se {
color: #d14;
}
.highlight .sh {
color: #d14;
}
.highlight .si {
color: #d14;
}
.highlight .sx {
color: #d14;
}
.highlight .sr {
color: #009926;
}
.highlight .s1 {
color: #d14;
}
.highlight .ss {
color: #990073;
}
.highlight .s {
color: #d14;
}
.highlight .na {
color: #008080;
}
.highlight .bp {
color: #999999;
}
.highlight .nb {
color: #0086B3;
}
.highlight .nc {
color: #445588;
font-weight: bold;
}
.highlight .no {
color: #008080;
}
.highlight .nd {
color: #3c5d5d;
font-weight: bold;
}
.highlight .ni {
color: #800080;
}
.highlight .ne {
color: #990000;
font-weight: bold;
}
.highlight .nf {
color: #990000;
font-weight: bold;
}
.highlight .nl {
color: #990000;
font-weight: bold;
}
.highlight .nn {
color: #555555;
}
.highlight .nt {
color: #000080;
}
.highlight .vc {
color: #008080;
}
.highlight .vg {
color: #008080;
}
.highlight .vi {
color: #008080;
}
.highlight .nv {
color: #008080;
}
.highlight .ow {
color: #000000;
font-weight: bold;
}
.highlight .o {
color: #000000;
font-weight: bold;
}
.highlight .w {
color: #bbbbbb;
}
.highlight {
font-family: "Anonymous Pro", "Inconsolata", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
}
19 changes: 12 additions & 7 deletions guides/rails_guides/markdown/renderer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true
require 'rouge'

module RailsGuides
class Markdown
Expand All @@ -8,8 +9,8 @@ class Renderer < Redcarpet::Render::HTML
def block_code(code, language)
<<-HTML
<div class="code_container">
<pre class="brush: #{brush_for(language)}; gutter: false; toolbar: false">
#{ERB::Util.h(code)}
<pre class="highlight">
#{Rouge::Formatters::HTML.new.format(Rouge::Lexers.const_get(brush_for(language)).new.lex(code)).chop}
</pre>
</div>
HTML
Expand Down Expand Up @@ -58,14 +59,18 @@ def convert_footnotes(text)

def brush_for(code_type)
case code_type
when "ruby", "sql", "plain"
code_type
when "ruby"
"Ruby"
when "sql"
"SQL"
when "erb", "html+erb"
"ruby; html-script: true"
"ERB"
when "html"
"xml" # HTML is understood, but there are .xml rules in the CSS
"XML" # HTML is understood, but there are .xml rules in the CSS
when "bash"
"ConsoleLexer"
else
"plain"
"PlainText"
end
end

Expand Down
2 changes: 2 additions & 0 deletions guides/source/ja/layout.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
<link rel="stylesheet" type="text/css" href="stylesheets/rouge_highlight_github.css" />


<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />

Expand Down

0 comments on commit 0520724

Please sign in to comment.