1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
Description: Make it possible to skip-syntax-highlighting explicitly
From: Waldemar Quevedo <waldemar.quevedo@gmail.com>
Origin: https://github.com/wallyqs/org-ruby/commit/2cba8d21e2de71b7d5cab212cb1016dbbfddbba8.patch
Reviewed-by: Cédric Boutillier <boutil@debian.org>
Last-Update: 2014-04-16
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -1,14 +1,3 @@
-begin
- require 'pygments'
-rescue LoadError
- # Pygments is not supported so we try instead with CodeRay
- begin
- require 'coderay'
- rescue LoadError
- # No code syntax highlighting
- end
-end
-
module Orgmode
class HtmlOutputBuffer < OutputBuffer
@@ -51,6 +40,19 @@
@footnotes = {}
@unclosed_tags = []
@logger.debug "HTML export options: #{@options.inspect}"
+
+ unless @options[:skip_syntax_highlight]
+ begin
+ require 'pygments'
+ rescue LoadError
+ # Pygments is not supported so we try instead with CodeRay
+ begin
+ require 'coderay'
+ rescue LoadError
+ # No code syntax highlighting
+ end
+ end
+ end
end
# Output buffer is entering a new mode. Use this opportunity to
@@ -61,7 +63,7 @@
if HtmlBlockTag[mode]
unless ((mode_is_table?(mode) and skip_tables?) or
- (mode == :src and defined? Pygments))
+ (mode == :src and !@options[:skip_syntax_highlight] and defined? Pygments))
css_class = case
when (mode == :src and @block_lang.empty?)
" class=\"src\""
@@ -92,7 +94,7 @@
m = super(mode)
if HtmlBlockTag[m]
unless ((mode_is_table?(m) and skip_tables?) or
- (m == :src and defined? Pygments))
+ (m == :src and !@options[:skip_syntax_highlight] and defined? Pygments))
add_paragraph if @new_paragraph
@new_paragraph = true
@logger.debug "</#{HtmlBlockTag[m]}>"
@@ -111,6 +113,8 @@
# NOTE: CodeRay and Pygments already escape the html once, so
# no need to escapeHTML
case
+ when (current_mode == :src and @options[:skip_syntax_highlight])
+ @buffer = escapeHTML @buffer
when (current_mode == :src and defined? Pygments)
lang = normalize_lang @block_lang
@output << "\n" unless @new_paragraph == :start
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -306,7 +306,8 @@
:export_todo => export_todo?,
:use_sub_superscripts => use_sub_superscripts?,
:export_footnotes => export_footnotes?,
- :link_abbrevs => @link_abbrevs
+ :link_abbrevs => @link_abbrevs,
+ :skip_syntax_highlight => @parser_options[:skip_syntax_highlight]
}
export_options[:skip_tables] = true if not export_tables?
output = ""
--- a/spec/parser_spec.rb
+++ b/spec/parser_spec.rb
@@ -195,19 +195,18 @@
describe "Export to HTML test cases with code syntax highlight" do
code_syntax_examples_directory = File.join(File.dirname(__FILE__), "html_code_syntax_highlight_examples")
+ files = []
# Include the code syntax highlight support tests
if defined? CodeRay
# Use CodeRay for syntax highlight (pure Ruby solution)
org_files = File.expand_path(File.join(code_syntax_examples_directory, "*-coderay.org"))
+ files = Dir.glob(org_files)
elsif defined? Pygments
# Use pygments (so that it works with Jekyll, Gollum and possibly Github)
org_files = File.expand_path(File.join(code_syntax_examples_directory, "*-pygments.org"))
- else
- # Do not use syntax coloring for source code blocks
- org_files = File.expand_path(File.join(code_syntax_examples_directory, "*-no-color.org"))
+ files = Dir.glob(org_files)
end
- files = Dir.glob(org_files)
files.each do |file|
basename = File.basename(file, ".org")
@@ -227,6 +226,41 @@
ENV['ORG_RUBY_ENABLE_INCLUDE_FILES'] = 'true'
expected = IO.read(org_filename)
template = Tilt.new(file).render
+ template.should == expected
+ ENV['ORG_RUBY_ENABLE_INCLUDE_FILES'] = ''
+ end
+ end
+ end
+
+ describe "Export to HTML test cases with code syntax highlight disabled" do
+ code_syntax_examples_directory = File.join(File.dirname(__FILE__), "html_code_syntax_highlight_examples")
+
+ # Do not use syntax coloring for source code blocks
+ org_files = File.expand_path(File.join(code_syntax_examples_directory, "*-no-color.org"))
+ files = Dir.glob(org_files)
+
+ files.each do |file|
+ basename = File.basename(file, ".org")
+ org_filename = File.join(code_syntax_examples_directory, basename + ".html")
+ org_filename = File.expand_path(org_filename)
+
+ it "should convert #{basename}.org to HTML" do
+ expected = IO.read(org_filename)
+ expected.should be_kind_of(String)
+ parser = Orgmode::Parser.new(IO.read(file), {
+ :allow_include_files => true,
+ :skip_syntax_highlight => true
+ })
+ actual = parser.to_html
+ actual.should be_kind_of(String)
+ actual.should == expected
+ end
+
+ it "should render #{basename}.org to HTML using Tilt templates",
+ :if => (defined? Coderay or defined? Pygments) do
+ ENV['ORG_RUBY_ENABLE_INCLUDE_FILES'] = 'true'
+ expected = IO.read(org_filename)
+ template = Tilt.new(file).render
template.should == expected
ENV['ORG_RUBY_ENABLE_INCLUDE_FILES'] = ''
end
|