| Class | Texy::Modules::Block |
| In: |
lib/texy/modules/block.rb
|
| Parent: | Base |
Block module class
| code_handler | [RW] | proc(element) |
| div_handler | [RW] | proc(element, non_parsed_content) |
| html_handler | [RW] | proc(element, is_html) |
# File lib/texy/modules/block.rb, line 44 def initialize(texy) super self.allowed = { :pre => true, :text => true, # if false, /--html blocks are parsed as /--text block :html => true, :div => true, :source => true, :comment => true } end
Module initialization.
# File lib/texy/modules/block.rb, line 58 def init # (rane) FIXME: in original code, there was . instead of [a-zA-Z0-9_-] in the second caturing block, # but it caused the pattern to swallow the modifier ( ".[blabla]" ). I have to figure out why it # works in original code but not here. texy.register_block_pattern( method(:process_block), /^\/--+\ *(?:(code|samp|text|html|div|notexy|source|comment)(\ [a-zA-Z0-9_-]*?)?|)\ *#{PATTERN_MODIFIER_H}?\n(.*?\n)?(?:\\--+\ *\1?|\z)()$/mi ) end
Callback function (for blocks)
/-----code html .(title)[class]{style}
....
....
\----
# File lib/texy/modules/block.rb, line 76 def process_block(parser, matches) m_type, m_second, m_content = matches.values_at(1, 2, 7) m_second = m_second.to_s.downcase.strip m_content.gsub!(/\A\n+|\n+\Z/, '') #trim($mContent, "\n"); m_type ||= 'pre' # default type m_type = m_type.downcase.strip m_type = 'html' if m_type == 'notexy' # backward compatibility m_type = 'text' if m_type == 'html' && !allowed[:html] if m_type == 'code' || m_type == 'samp' m_type = allowed[:pre] ? m_type : 'none' elsif !allowed[m_type.to_sym] m_type = 'none' # transparent block end case m_type when 'none', 'div' el = BlockElement.new(texy) el.tag = 'div' el.modifier.set_properties(*matches[3..6]) outdent(m_content) if div_handler return unless div_handler.call(el, m_content) end el.parse(m_content) parser.element.append_child(el) when 'source' el = SourceBlockElement.new(texy) el.modifier.set_properties(*matches[3..6]) outdent(m_content) el.parse(m_content) parser.element.append_child(el) when 'comment' when 'html' el = HtmlBlockElement.new(texy) el.parse(m_content) if html_handler return unless html_handler.call(el, true) end parser.element.append_child(el) when 'text' el = TextualElement.new(texy) el.set_content(Texy::Html::html_chars(m_content).gsub("\n", '<br />'), true) if html_handler return unless html_handler.call(el, false) end parser.element.append_child(el) else # pre | code | samp el = CodeBlockElement.new(texy) el.modifier.set_properties(*matches[3..6]) el.type = m_type el.lang = m_second outdent(m_content) el.set_content(m_content, false) # not html-safe content if code_handler return unless code_handler.call(el) end parser.element.append_child(el) end end