lib/polytexnic/preprocessors/polytex.rb in polytexnic-0.6.8 vs lib/polytexnic/preprocessors/polytex.rb in polytexnic-0.6.9

- old
+ new

@@ -39,10 +39,11 @@ # Override the header ordering, which starts with 'section' by default. lh = 'chapter,section,subsection,subsubsection,paragraph,subparagraph' kramdown = Kramdown::Document.new(cleaned_markdown, latex_headers: lh) @source = kramdown.to_latex.tap do |polytex| remove_comments(polytex) + convert_includegraphics(polytex) convert_tt(polytex) restore_math(polytex, math_cache) restore_hashed_content(polytex, cache) end end @@ -132,33 +133,35 @@ elsif line =~ /^```\s*$/ # basic code fences while (line = lines.shift) && !line.match(/^```\s*$/) output << indentation + line end output << "\n" - elsif line =~ /^```(\w+)\s*$/ # syntax-highlighted code fences + elsif line =~ /^```(\w+)(,\s*options:.*)?$/ # highlighted fences language = $1 + options = $2 code = [] while (line = lines.shift) && !line.match(/^```\s*$/) do code << line end code = code.join("\n") - key = digest(code) - code_cache[key] = [code, language] + data = [code, language, false, options] + key = digest(data.join("--")) + code_cache[key] = data output << key else output << line end end output.join("\n") end - # # Removes comments. - # # The main reason for doing this is so that commented-out cached objects, - # # such as '% <hash of a code sample>', get removed. - # # Code like '%= lang:ruby' gets preserved. - # def strip_comments(text) - # text.gsub!(/^%.*$/, '') - # end + # Converts \includegraphics to \image. + # The reason is that raw \includegraphics is almost always too wide + # in the PDF. Instead, we use the custom-defined \image command, which + # is specifically designed to fix this issue. + def convert_includegraphics(text) + text.gsub!('\includegraphics', '\image') + end # Converts {tt ...} to \kode{...} # This effectively converts `inline code`, which kramdown sets as # {\tt inline code}, to PolyTeX's native \kode command, which in # turns allows inline code to be separately styled. \ No newline at end of file