Class: Polytexnic::Pipeline

Inherits:
Object
  • Object
show all
Includes:
Postprocessor, Preprocessor, Utils
Defined in:
lib/polytexnic.rb

Constant Summary

Constants included from Literal

Literal::LANG_REGEX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#add_font_info, #apple_silicon?, #cache_urls, #debug?, #digest, #escape_backslashes, #expand_input!, #framed, #highlight, #highlight_lines, #highlight_source_code, #highlighted_lines, #horrible_backslash_kludge, #linux?, #os_x?, #os_x_newer?, #os_x_older?, #pipeline_digest, #profiling?, #set_test_mode!, #test?, #tralics, #tralics_commands, #underscore_digest, #xmlelement

Methods included from Postprocessor

#postprocess

Methods included from Polytexnic::Postprocessor::Polytex

#escape_hack, #fix_verbatim_bug, #remove_hypertarget, #write_polytex_code

Methods included from Polytexnic::Postprocessor::Latex

#extra_escape, #replace_hashes

Methods included from Polytexnic::Postprocessor::Html

#xml_to_html

Methods included from Preprocessor

#preprocess

Methods included from Polytexnic::Preprocessor::Polytex

#cache_code_environments, #cache_image_locations, #cache_latex_literal, #cache_math, #cache_raw_latex, #convert_code_inclusion, #convert_includegraphics, #remove_kramdown_comments, #restore_hashed_content, #restore_math, #to_polytex

Methods included from Literal

#cache_display_inline_math, #cache_display_math, #cache_inline_math, #cache_literal, #cache_literal_environments, #cache_unicode, #code_salt, #element, #equation_element, #hyperrefs, #literal_types, #math_environments

Methods included from Polytexnic::Preprocessor::Latex

#clean_latex_document, #convert_gifs, #polish_tables, #process_asides, #to_processed_latex

Methods included from Polytexnic::Preprocessor::Html

#to_xml

Constructor Details

#initialize(source, options = {}) ⇒ Pipeline

Returns a new instance of Pipeline.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/polytexnic.rb', line 44

def initialize(source, options = {})
  @literal_cache = options[:literal_cache] || {}
  @unicode_cache = {}
  @code_cache = {}
  @figure_quote_cache = {}
  @literal_html_cache = {}
  @maketitle_elements = {}
  @article = options[:article]
  @supported_theorem_types = %w[theorem lemma corollary proposition
                                conjecture
                                definition problem example exercise axiom
                                remark claim]
  @language_labels = if (labels = options[:language_labels]).nil?
                        default_language_labels
                      else
                        default_language_labels.merge(labels)
                      end
  tempdir = 'tmp'
  FileUtils.mkdir(tempdir) unless File.directory?(tempdir)
  @highlight_cache_filename = File.join(tempdir, '.highlight_cache')
  if File.exist?(@highlight_cache_filename)
    content = File.read(@highlight_cache_filename)
                  .force_encoding('ASCII-8BIT')
    begin
      @highlight_cache = MessagePack.unpack(content) unless content.empty?
    rescue MessagePack::UnpackError
      FileUtils.rm @highlight_cache_filename
    end
  end
  @highlight_cache ||= {}
  @math_label_cache = {}
  @source_format = options[:source] || :polytex
  @custom_commands = File.read(Polytexnic.core_style_file) rescue ''
  @custom_commands += "\n" + (options[:custom_commands] || '')
  @source = source
  if markdown?
    preprocess(:polytex)
    postprocess(:polytex)
  end
  @polytex = @source
end

Instance Attribute Details

#articleObject

Returns the value of attribute article.



39
40
41
# File 'lib/polytexnic.rb', line 39

def article
  @article
end

#code_cacheObject

Returns the value of attribute code_cache.



39
40
41
# File 'lib/polytexnic.rb', line 39

def code_cache
  @code_cache
end

#custom_commandsObject

Returns the value of attribute custom_commands.



39
40
41
# File 'lib/polytexnic.rb', line 39

def custom_commands
  @custom_commands
end

#figure_quote_cacheObject

Returns the value of attribute figure_quote_cache.



39
40
41
# File 'lib/polytexnic.rb', line 39

def figure_quote_cache
  @figure_quote_cache
end

#highlight_cacheObject

Returns the value of attribute highlight_cache.



39
40
41
# File 'lib/polytexnic.rb', line 39

def highlight_cache
  @highlight_cache
end

#htmlObject

Returns the value of attribute html.



39
40
41
# File 'lib/polytexnic.rb', line 39

def html
  @html
end

#language_labelsObject

Returns the value of attribute language_labels.



39
40
41
# File 'lib/polytexnic.rb', line 39

def language_labels
  @language_labels
end

#literal_cacheObject

Returns the value of attribute literal_cache.



39
40
41
# File 'lib/polytexnic.rb', line 39

def literal_cache
  @literal_cache
end

#literal_html_cacheObject

Returns the value of attribute literal_html_cache.



39
40
41
# File 'lib/polytexnic.rb', line 39

def literal_html_cache
  @literal_html_cache
end

#maketitle_elementsObject

Returns the value of attribute maketitle_elements.



39
40
41
# File 'lib/polytexnic.rb', line 39

def maketitle_elements
  @maketitle_elements
end

#math_label_cacheObject

Returns the value of attribute math_label_cache.



39
40
41
# File 'lib/polytexnic.rb', line 39

def math_label_cache
  @math_label_cache
end

#polytexObject

Returns the value of attribute polytex.



39
40
41
# File 'lib/polytexnic.rb', line 39

def polytex
  @polytex
end

#unicode_cacheObject

Returns the value of attribute unicode_cache.



39
40
41
# File 'lib/polytexnic.rb', line 39

def unicode_cache
  @unicode_cache
end

#xmlObject

Returns the value of attribute xml.



39
40
41
# File 'lib/polytexnic.rb', line 39

def xml
  @xml
end

Instance Method Details

#to_htmlObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/polytexnic.rb', line 86

def to_html
  if profiling?
    require 'ruby-prof'
    RubyProf.start
  end

  puts "before preprocess:\n#{@polytex}" if debug?
  preprocess(:html)
  puts "\nafter preprocess:\n#{@xml}" if debug?
  postprocess(:html)
  puts "\nafter postprocess:\n#{@html}" if debug?

  if profiling?
    result = RubyProf.stop
    printer = RubyProf::GraphPrinter.new(result)
    printer.print(STDOUT, {})
  end
  @html.strip
end

#to_latexObject



106
107
108
109
110
# File 'lib/polytexnic.rb', line 106

def to_latex
  preprocess(:latex)
  postprocess(:latex)
  @latex
end