lib/polytexnic/literal.rb in polytexnic-0.5.0 vs lib/polytexnic/literal.rb in polytexnic-0.6.0
- old
+ new
@@ -1,7 +1,8 @@
module Polytexnic
module Literal
+ extend self
# Matches the line for syntax highlighting.
# %= lang:<language>
LANG_REGEX = /^\s*%=\s+lang:\s*(\w+)/
@@ -19,10 +20,26 @@
lines = polytex.split("\n")
cache_literal_environments(lines, output, format)
output.join("\n")
end
+ # Returns supported math environments.
+ # Note that the custom AMS-TeX environments are supported
+ # in addition to the LaTeX defaults.
+ def math_environments
+ %w[align align*
+ eqnarray eqnarray* equation equation*
+ gather gather* gathered
+ multline multline*
+ ]
+ end
+
+ # Returns a list of all literal types.
+ def literal_types
+ %w[verbatim Vertatim code metadcode] + math_environments
+ end
+
# Handles environments that should be passed through the pipeline intact.
# The includes verbatim environments ('verbatim', 'Verbatim') and all the
# equation environments handled by MathJax ('equation', 'align', etc.).
# We take care to keep count of the number of begins we see so that the
# code handles nested environments correctly. I.e.,
@@ -38,11 +55,11 @@
# The control flow here is really nasty, but attempts to refactor it
# into a multi-pass solution have only resulted in even more complexity,
# and even then I've failed to get it to work. Thus, it shall for now
# follow the "ball of mud" pattern. (The only saving grace is that it's
# very thoroughly tested.)
- def cache_literal_environments(lines, output, format)
+ def cache_literal_environments(lines, output, format, cache = nil)
latex = (format == :latex)
language = nil
in_verbatim = false
in_codelisting = false
while (line = lines.shift)
@@ -239,22 +256,13 @@
end
end
end
end
-# Returns supported math environments.
-# Note that the custom AMS-TeX environments are supported
-# in addition to the LaTeX defaults.
-def math_environments
- %w[align align*
- eqnarray eqnarray* equation equation*
- gather gather* gathered
- multline multline*
- ]
-end
class String
+ include Polytexnic::Literal
# Returns true if self matches \begin{...} where ... is a literal environment.
# Note: Support for the 'metacode' environment exists solely to allow
# meta-discussion of the 'code' environment.
def begin_literal?(literal_type = nil)
@@ -292,8 +300,10 @@
private
# Returns a regex matching valid math environments.
def math_environment_regex
- math_environments.map { |s| Regexp.escape(s) }.join('|')
+ Polytexnic::Literal.math_environments.map do |s|
+ Regexp.escape(s)
+ end.join('|')
end
end
\ No newline at end of file