lib/polytexnic/preprocessors/polytex.rb
def cache_code_environments(source)
        output = []
        lines = source.split("\n")
        indentation = ' ' * 4
        while (line = lines.shift)
          if line =~ /\{lang="(.*?)"\}/
            language = $1
            code = []
            while (line = lines.shift) && line.match(/^#{indentation}(.*)$/) do
              code << $1
            end
            code = code.join("\n")
            key = digest(code)
            code_cache[key] = [code, language]
            output << key
            output << line
          elsif line =~ /^```([\w+]*)(,\s*options:.*)?$/  # highlighted fences
            count = 1
            language = $1.empty? ? 'text' : $1
            options  = $2
            code = []
            while (line = lines.shift) do
              count += 1 if line =~ /^```.+$/
              count -= 1 if line.match(/^```\s*$/)
              break if count.zero?
              code << line
            end
            code = code.join("\n")
            data = [code, language, false, options]
            key = digest(data.join("--"))
            code_cache[key] = data
            output << key
          else
            output << line
          end
        end
        output.join("\n")
      end
# Caches Markdown code environments.
# Included are indented environments, Leanpub-style indented environments,
# and GitHub-style code fencing.
Caches Markdown code environments.
Included are indented environments, Leanpub-style indented environments,
and GitHub-style code fencing.
Caches Markdown code environments . Included are indented environments Leanpub - style indented environments and GitHub - style code fencing .
def cache_code_environments(source)
        output = []
        lines = source.split("\n")
        indentation = ' ' * 4
        while (line = lines.shift)
          if line =~ /\{lang="(.*?)"\}/
            language = $1
            code = []
            while (line = lines.shift) && line.match(/^#{indentation}(.*)$/) do
              code << $1
            end
            code = code.join("\n")
            key = digest(code)
            code_cache[key] = [code, language]
            output << key
            output << line
          elsif line =~ /^```([\w+]*)(,\s*options:.*)?$/  
            count = 1
            language = $1.empty? ? 'text' : $1
            options  = $2
            code = []
            while (line = lines.shift) do
              count += 1 if line =~ /^```.+$/
              count -= 1 if line.match(/^```\s*$/)
              break if count.zero?
              code << line
            end
            code = code.join("\n")
            data = [code, language, false, options]
            key = digest(data.join("--"))
            code_cache[key] = data
            output << key
          else
            output << line
          end
        end
        output.join("\n")
      end
def cache_code_environments ( source ) output = [ ] lines = source . split ( "\n" ) indentation = ' ' * 4 while ( line = lines . shift ) if line =~ / \{ lang="(.*?)" \} / language = $1 code = [ ] while ( line = lines . shift ) && line . match ( / ^ #{ indentation } (.*)$ / ) do code << $1 end code = code . join ( "\n" ) key = digest ( code ) code_cache [ key ] = [ code , language ] output << key output << line elsif line =~ / ^```([ \w +]*)(, \s *options:.*)?$ / count = 1 language = $1 . empty? ? 'text' : $1 options = $2 code = [ ] while ( line = lines . shift ) do count += 1 if line =~ / ^```.+$ / count -= 1 if line . match ( / ^``` \s *$ / ) break if count . zero? code << line end code = code . join ( "\n" ) data = [ code , language , false , options ] key = digest ( data . join ( "--" ) ) code_cache [ key ] = data output << key else output << line end end output . join ( "\n" ) end
Caches Markdown code environments.
Caches Markdown code environments .
# highlighted fences
source