Method: Zena::Parser::ZazenRules#extract_code

Defined in:
lib/zena/parser/zazen_rules.rb

#extract_code(fulltext) ⇒ Object



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/zena/parser/zazen_rules.rb', line 334

def extract_code(fulltext)
  @escaped_code = []
  @block_counter = -1
  fulltext.gsub!( /<(code|notextile|html)([^>]*)>(.*?)<\/\1>/m ) do
    if @translate_ids
      raw_content([nil, $&])
    elsif $1 == 'notextile' || $1 == 'html'
      # FIXME: SECURITY. How to avoid the use of notextile in comments and such ?
      if @context[:notextile] == 'true'
        raw_content($3)
      else
        ''
      end
    else
      params, text = $2, $3
      pre_params = []
      if params =~ /\A(.*)lang\s*=\s*("|')([^"']+)\2(.*)\Z/m
        pre, lang, post = $1.strip, $3, $4.strip
        pre_params << pre if pre && pre != ""
        pre_params << post if post && post != ""
      else
        pre_params << params.strip if params != ''
        lang = ''
      end
      #pre_params << "class='code'" unless params =~ /class\s*=/
      pre_params = pre_params.blank? ? nil : pre_params.join(' ')
      raw_content([lang, text, pre_params])
    end
  end

  @escaped_at = []
  block_counter = -1
  fulltext.gsub!( /(\A|[^\w])@(.*?)@(\Z|[^\w])/m ) do
    @escaped_at << $2
    block_counter += 1
    "#{$1}\\ZAZENBLOCKAT#{block_counter}ZAZENBLOCKAT\\#{$3}"
  end
end