From 64a7c969a8cc1f8515512836cb7a36dde55b62ab Mon Sep 17 00:00:00 2001 From: Xusen Yin Date: Sat, 24 Oct 2015 16:35:02 -0700 Subject: [PATCH 1/2] add new code tags --- docs/_plugins/include_example.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/_plugins/include_example.rb b/docs/_plugins/include_example.rb index 0f4184c7462be..59d3bfc928995 100644 --- a/docs/_plugins/include_example.rb +++ b/docs/_plugins/include_example.rb @@ -38,7 +38,9 @@ def render(context) code = File.open(@file).read.encode("UTF-8") code = select_lines(code) - Pygments.highlight(code, :lexer => @lang) + rendered_code = Pygments.highlight(code, :lexer => @lang) + trimed = rendered_code.sub("
", "").sub("
", "") + add_code_tag(trimed) end # Trim the code block so as to have the same indention, regardless of their positions in the @@ -53,6 +55,16 @@ def trim_codeblock(lines) lines.map { |l| l[min_start_spaces .. -1] } end + # Add new code tags outside the Pygments generated code example, to keep the same look and feel + # with previous documents. + def add_code_tag(code) + code_attributes = [ + "class=\"language-#{@lang.to_s.gsub('+', '-')}\"", + "data-lang=\"#{@lang.to_s}\"" + ].join(" ") + "
#{code.chomp}
" + end + # Select lines according to labels in code. Currently we use "$example on$" and "$example off$" # as labels. Note that code blocks identified by the labels should not overlap. def select_lines(code) From 7352bc406282038802d5560a6aafad79b36301c1 Mon Sep 17 00:00:00 2001 From: Xusen Yin Date: Mon, 26 Oct 2015 22:09:23 -0700 Subject: [PATCH 2/2] modify css file --- docs/_plugins/include_example.rb | 14 +------------- docs/css/main.css | 4 ++++ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/docs/_plugins/include_example.rb b/docs/_plugins/include_example.rb index 59d3bfc928995..0f4184c7462be 100644 --- a/docs/_plugins/include_example.rb +++ b/docs/_plugins/include_example.rb @@ -38,9 +38,7 @@ def render(context) code = File.open(@file).read.encode("UTF-8") code = select_lines(code) - rendered_code = Pygments.highlight(code, :lexer => @lang) - trimed = rendered_code.sub("
", "").sub("
", "") - add_code_tag(trimed) + Pygments.highlight(code, :lexer => @lang) end # Trim the code block so as to have the same indention, regardless of their positions in the @@ -55,16 +53,6 @@ def trim_codeblock(lines) lines.map { |l| l[min_start_spaces .. -1] } end - # Add new code tags outside the Pygments generated code example, to keep the same look and feel - # with previous documents. - def add_code_tag(code) - code_attributes = [ - "class=\"language-#{@lang.to_s.gsub('+', '-')}\"", - "data-lang=\"#{@lang.to_s}\"" - ].join(" ") - "
#{code.chomp}
" - end - # Select lines according to labels in code. Currently we use "$example on$" and "$example off$" # as labels. Note that code blocks identified by the labels should not overlap. def select_lines(code) diff --git a/docs/css/main.css b/docs/css/main.css index 89305a7d3a358..d770173be1014 100755 --- a/docs/css/main.css +++ b/docs/css/main.css @@ -74,6 +74,10 @@ code { color: #444444; } +div .highlight pre { + font-size: 12px; +} + a code { color: #0088cc; }