lib/rabbit/parser/rd/ext/block-verbatim.rb in rabbit-0.9.3 vs lib/rabbit/parser/rd/ext/block-verbatim.rb in rabbit-1.0.0

- old
+ new

@@ -6,25 +6,23 @@ require 'rabbit/parser/rd/rt/rt2rabbit-lib' rescue LoadError end require 'rabbit/parser/rd/ext/base' require 'rabbit/parser/rd/ext/image' -require 'rabbit/parser/rd/ext/enscript' -require 'rabbit/parser/rd/ext/tex' -require 'rabbit/parser/rd/ext/aafigure' -require 'rabbit/parser/rd/ext/anthy' +require 'rabbit/parser/ext/enscript' +require 'rabbit/parser/ext/tex' +require 'rabbit/parser/ext/aafigure' +require 'rabbit/parser/ext/blockdiag' +require 'rabbit/parser/ext/coderay' +require 'rabbit/parser/ext/emacs' module Rabbit module Parser class RD module Ext class BlockVerbatim < Base include Image - include Enscript - include TeX - include AAFigure - include Anthy include GetText def default_ext_block_verbatim(label, source, content, visitor) content = visitor.apply_to_String(content.rstrip) text = Text.new(content) @@ -63,30 +61,69 @@ end def ext_block_verb_enscript(label, source, content, visitor) return nil unless /^enscript (\w+)$/i =~ label lang = $1.downcase.untaint - enscript_block(label, lang, source, content, visitor) - end - def ext_block_verb_anthy(label, source, content, visitor) - return nil unless /^anthy$/i =~ label - anthy_hiragana_to_kanji(label, source, content, visitor) + src, prop = parse_source(source) + logger = visitor.logger + + result = nil + if Parser::Ext::Enscript.check_availability(lang, logger) + result = Parser::Ext::Enscript.highlight(lang, src, logger) + end + result || default_ext_block_verbatim(label, src, src, visitor) end def ext_block_verb_LaTeX(label, source, content, visitor) return nil unless /^LaTeX$/i =~ label - make_image_by_LaTeX(source, visitor) + make_image_from_file(source, visitor) do |src_file_path, prop| + Parser::Ext::TeX.make_image_by_LaTeX(src_file_path, prop, visitor) + end end def ext_block_verb_mimeTeX(label, source, content, visitor) return nil unless /^mimeTeX$/i =~ label - make_image_by_mimeTeX(source, visitor) + make_image_from_file(source, visitor) do |src_file_path, prop| + Parser::Ext::TeX.make_image_by_mimeTeX(src_file_path, prop, + visitor) + end end def ext_block_verb_aafigure(label, source, content, visitor) return nil unless /^aafigure$/i =~ label - make_image_by_aafigure(source, visitor) + make_image_from_file(source, visitor) do |src_file_path, prop| + Parser::Ext::AAFigure.make_image(src_file_path, prop, visitor) + end + end + + def ext_block_verb_blockdiag(label, source, content, visitor) + return nil unless /^blockdiag$/i =~ label + make_image_from_file(source, visitor) do |src_file_path, prop| + Parser::Ext::BlockDiag.make_image(src_file_path, prop, visitor) + end + end + + def ext_block_verb_coderay(label, source, content, visitor) + return nil unless /^coderay (\w+)$/i =~ label + lang = $1.downcase.untaint + + src, prop = parse_source(source) + logger = visitor.logger + + result = Parser::Ext::CodeRay.highlight(lang, src, logger) + result || default_ext_block_verbatim(label, src, src, visitor) + end + + def ext_block_verb_emacs(label, source, content, visitor) + return nil unless /^emacs(?:\s+(.+))?$/i =~ label + mode_line = $1.untaint + + src, prop = parse_source(source) + logger = visitor.logger + + result = Parser::Ext::Emacs.highlight(src, logger, mode_line) + result || default_ext_block_verbatim(label, src, src, visitor) end def ext_block_verb_rt(label, source, content, visitor) return nil unless /^rt$/i =~ label unless defined?(RT2RabbitVisitor)