lib/polytexnic/literal.rb in polytexnic-0.6.8 vs lib/polytexnic/literal.rb in polytexnic-0.6.9

- old
+ new

@@ -1,18 +1,19 @@ module Polytexnic module Literal extend self # Matches the line for syntax highlighting. - # %= lang:<language> - LANG_REGEX = /^\s*%=\s+lang:\s*(\w+)/ + # %= lang: <language>[, options: ...] + LANG_REGEX = /^\s*%=\s+lang:\s*(\w+)(?:,\s*options:(.*))?/ # Matches the line for code inclusion. # %= <</path/to/code.ext CODE_INCLUSION_REGEX = /^\s*%=\s+<<\s*\( # opening - \s*([\w\/-]+\.?(\w*)) # path + \s*([\w\/-]+\.?(\w*)) # path (?:,\s*lang:\s*(\w+))? # optional lang + (,\s*options:\s*.*)? # optional options \s*\) # closing paren /x # Makes the caches for literal environments. def cache_literal(polytex, format = :html) @@ -63,10 +64,11 @@ in_verbatim = false in_codelisting = false while (line = lines.shift) if line =~ LANG_REGEX && !in_verbatim language = $1 + highlight_options = $2 elsif line =~ /\s*\\begin\{codelisting\}/ && !in_verbatim in_codelisting = true output << line elsif line =~ /\s*\\end\{codelisting\}/ && !in_verbatim in_codelisting = false @@ -82,11 +84,13 @@ # \end{code} # and then prepend the code to the current `lines` array. filename = $1 if File.exist?(filename) language = $3 || $2 || 'text' + highlight_options = $4 code = ["%= lang:#{language}"] + code << highlight_options unless highlight_options.nil? code << '\begin{code}' code.concat(File.read($1).split("\n")) code << '\end{code}' lines.unshift(*code) else @@ -129,12 +133,12 @@ key = digest(content) literal_cache[key] = content tag = 'literal' else format = latex ? 'latex' : 'html' - id = "#{content}--#{language}--#{format}--#{in_codelisting}" + id = "#{content}--#{language}--#{format}--#{in_codelisting}--#{highlight_options}" key = digest(id, salt: code_salt) - code_cache[key] = [content, language, in_codelisting] + code_cache[key] = [content, language, in_codelisting, highlight_options] tag = 'code' end if latex || tag == 'code' || math key else \ No newline at end of file