[DRE-commits] [ruby-org] 179/303: Normalize language used in block for Pygments and CodeRay. This makes emacs-lisp, common-lisp and lisp use the scheme lexer in Pygments.
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:33:53 UTC 2013
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository ruby-org.
commit 180d995bd7ae3b8dab99bcf0bcafd9455bfc33fc
Author: Waldemar Quevedo <waldemar.quevedo at gmail.com>
Date: Sat Aug 4 11:26:31 2012 +0900
Normalize language used in block for Pygments and CodeRay.
This makes emacs-lisp, common-lisp and lisp use the scheme lexer in Pygments.
---
lib/org-ruby/html_output_buffer.rb | 22 +++++++++++++++++---
lib/org-ruby/line.rb | 2 +-
.../advanced-code-coderay.html | 2 +-
.../advanced-code-coderay.org | 2 +-
.../advanced-code-pygments.org | 2 +-
5 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 2754ae9..b565b1f 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -110,18 +110,25 @@ module Orgmode
# Only try to colorize #+BEGIN_SRC blocks with a specified language,
# but we still have to catch the cases when a lexer for the language was not available
if not @block_lang.empty? and (defined? Pygments or defined? CodeRay)
+ lang = normalize_lang(@block_lang)
+
# NOTE: CodeRay and Pygments already escape the html once, so no need to escape_buffer!
if defined? Pygments
begin
- @buffer = Pygments.highlight(@buffer, :lexer => @block_lang)
+ @buffer = Pygments.highlight(@buffer, :lexer => lang)
rescue ::RubyPython::PythonError
# Not supported lexer from Pygments, we fallback on using the text lexer
@buffer = Pygments.highlight(@buffer, :lexer => 'text')
end
elsif defined? CodeRay
- # CodeRay might throw a warning when unsupported lang is set
+ # CodeRay might throw a warning when unsupported lang is set,
+ # then fallback to using the text lexer
silence_warnings do
- @buffer = CodeRay.scan(@buffer, @block_lang).html(:wrap => nil, :css => :style)
+ begin
+ @buffer = CodeRay.scan(@buffer, lang).html(:wrap => nil, :css => :style)
+ rescue ArgumentError
+ @buffer = CodeRay.scan(@buffer, 'text').html(:wrap => nil, :css => :style)
+ end
end
end
else
@@ -336,6 +343,15 @@ module Orgmode
end
end
+ def normalize_lang(lang)
+ case lang
+ when 'emacs-lisp', 'common-lisp', 'lisp'
+ 'scheme'
+ else
+ lang
+ end
+ end
+
# Helper method taken from Rails
# https://github.com/rails/rails/blob/c2c8ef57d6f00d1c22743dc43746f95704d67a95/activesupport/lib/active_support/core_ext/kernel/reporting.rb#L10
def silence_warnings
diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb
index fc3d9a9..d771568 100644
--- a/lib/org-ruby/line.rb
+++ b/lib/org-ruby/line.rb
@@ -146,7 +146,7 @@ module Orgmode
table_row? or table_separator? or table_header?
end
- BlockRegexp = /^\s*#\+(BEGIN|END)_(\w*)\s*(\w*)?/i
+ BlockRegexp = /^\s*#\+(BEGIN|END)_(\w*)\s*([0-9A-Za-z_\-]*)?/i
def begin_block?
@line =~ BlockRegexp && $1 =~ /BEGIN/i
diff --git a/spec/html_code_syntax_highlight_examples/advanced-code-coderay.html b/spec/html_code_syntax_highlight_examples/advanced-code-coderay.html
index 909dfea..83d3bf4 100644
--- a/spec/html_code_syntax_highlight_examples/advanced-code-coderay.html
+++ b/spec/html_code_syntax_highlight_examples/advanced-code-coderay.html
@@ -134,7 +134,7 @@ Posts.<span style="color:#06B;font-weight:bold">index</span> = <span style="colo
<span style="color:#369;font-weight:bold">var_dump</span>(some_var);
</pre>
<h2><span class="heading-number heading-number-2">4.9 </span>Elisp example</h2>
-<pre class="src src-scheme">
+<pre class="src src-emacs-lisp">
(defun hello()
(interactive)
(message "hello"))
diff --git a/spec/html_code_syntax_highlight_examples/advanced-code-coderay.org b/spec/html_code_syntax_highlight_examples/advanced-code-coderay.org
index 199021b..0a3c029 100644
--- a/spec/html_code_syntax_highlight_examples/advanced-code-coderay.org
+++ b/spec/html_code_syntax_highlight_examples/advanced-code-coderay.org
@@ -190,7 +190,7 @@ var_dump(some_var);
** Elisp example
-#+BEGIN_SRC scheme
+#+BEGIN_SRC emacs-lisp
(defun hello()
(interactive)
(message "hello"))
diff --git a/spec/html_code_syntax_highlight_examples/advanced-code-pygments.org b/spec/html_code_syntax_highlight_examples/advanced-code-pygments.org
index ea2d8b4..206f7a5 100644
--- a/spec/html_code_syntax_highlight_examples/advanced-code-pygments.org
+++ b/spec/html_code_syntax_highlight_examples/advanced-code-pygments.org
@@ -189,7 +189,7 @@ var_dump(some_var);
** Elisp example
-#+BEGIN_SRC scheme
+#+BEGIN_SRC emacs-lisp
(defun hello()
(interactive)
(message "hello"))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-org.git
More information about the Pkg-ruby-extras-commits
mailing list