lib/polytexnic/preprocessors/polytex.rb in polytexnic-0.7.6 vs lib/polytexnic/preprocessors/polytex.rb in polytexnic-0.7.7
- old
+ new
@@ -24,11 +24,11 @@
# marketing term.</rant>
def to_polytex
require 'kramdown'
cache = {}
math_cache = {}
- cleaned_markdown = cache_code_environments
+ cleaned_markdown = cache_code_environments(@source)
puts cleaned_markdown if debug?
cleaned_markdown.tap do |markdown|
convert_code_inclusion(markdown, cache)
cache_latex_literal(markdown, cache)
cache_raw_latex(markdown, cache)
@@ -61,11 +61,13 @@
end
end
# Caches literal LaTeX environments.
def cache_latex_literal(markdown, cache)
- Polytexnic::Literal.literal_types.each do |literal|
+ # Add tabular and tabularx support.
+ literal_types = Polytexnic::Literal.literal_types + %w[tabular tabularx]
+ literal_types.each do |literal|
regex = /(\\begin\{#{Regexp.escape(literal)}\}
.*?
\\end\{#{Regexp.escape(literal)}\})
/xm
markdown.gsub!(regex) do
@@ -133,12 +135,12 @@
end
# Caches Markdown code environments.
# Included are indented environments, Leanpub-style indented environments,
# and GitHub-style code fencing.
- def cache_code_environments
+ def cache_code_environments(source)
output = []
- lines = @source.split("\n")
+ lines = source.split("\n")
indentation = ' ' * 4
while (line = lines.shift)
if line =~ /\{lang="(.*?)"\}/
language = $1
code = []