Class: Kramdown::Converter::Latex
- Inherits:
-
Base
- Object
- Base
- Kramdown::Converter::Latex
- Defined in:
- lib/polytexnic/preprocessors/polytex.rb
Instance Method Summary collapse
-
#convert_a(el, opts) ⇒ Object
Overrides default convert_a.
-
#convert_codespan(el, opts) ⇒ Object
Converts ‘inline codespan`.
-
#convert_standalone_image(el, opts, img) ⇒ Object
Uses figures for images only when label is present.
-
#has_label?(text) ⇒ Boolean
Detects if text has a label.
- #original_convert_standalone_image ⇒ Object
Instance Method Details
#convert_a(el, opts) ⇒ Object
Overrides default convert_a. Unfortunately, kramdown is too aggressive in escaping characters in hrefs, converting
[foo bar](http://example.com/foo%20bar)
into
\href{http://example.com/foo\%20bar}{foo bar}
The ‘%20’ in the href then won’t work properly.
26 27 28 29 30 31 32 33 |
# File 'lib/polytexnic/preprocessors/polytex.rb', line 26 def convert_a(el, opts) url = el.attr['href'] if url =~ /^#/ "\\hyperlink{#{escape(url[1..-1])}}{#{inner(el, opts)}}" else "\\href{#{url}}{#{inner(el, opts)}}" end end |
#convert_codespan(el, opts) ⇒ Object
Converts ‘inline codespan`. This overrides kramdown’s default to use ‘kode` instead of `tt`.
15 16 17 |
# File 'lib/polytexnic/preprocessors/polytex.rb', line 15 def convert_codespan(el, opts) "\\kode{#{latex_link_target(el)}#{escape(el.value)}}" end |
#convert_standalone_image(el, opts, img) ⇒ Object
Uses figures for images only when label is present. This allows users to put raw (centered) images in their documents. The default behavior of kramdown is to wrap such images in a figure environment, which causes LaTeX to (a) treat them as floats and (b) include a caption. This may not be what the user wants, and it’s also nonstandard Markdown. On the other hand, it is really nice to be able to include captions using the default image syntax, so as a compromise we use Markdown behavior by default and kramdown behavior if the alt text contains a ‘label’ element.
46 47 48 49 50 51 52 53 |
# File 'lib/polytexnic/preprocessors/polytex.rb', line 46 def convert_standalone_image(el, opts, img) alt_text = el.children.first.attr['alt'] if has_label?(alt_text) original_convert_standalone_image(el, opts, img) else img.gsub('\includegraphics', '\image') + "\n" end end |
#has_label?(text) ⇒ Boolean
Detects if text has a label.
56 57 58 |
# File 'lib/polytexnic/preprocessors/polytex.rb', line 56 def has_label?(text) text.include?($label_salt) end |
#original_convert_standalone_image ⇒ Object
35 |
# File 'lib/polytexnic/preprocessors/polytex.rb', line 35 alias_method :original_convert_standalone_image, :convert_standalone_image |