class Nesta::ContentFocus::HTMLRenderer

Public Instance Methods

block_code(code, language) click to toggle source
# File lib/nesta-contentfocus-extensions/renderer.rb, line 10
def block_code(code, language)
  @code_count ||= 0
  @code_count += 1
  code_block_id = "code-example-#{@code_count}"
  syntax_highlight(code, language, code_block_id)
end
escape_example_codeblock(code) click to toggle source
# File lib/nesta-contentfocus-extensions/renderer.rb, line 29
def escape_example_codeblock(code)
  code.gsub(/^\\```/m, '```')
end
escape_example_footnote(code) click to toggle source
# File lib/nesta-contentfocus-extensions/renderer.rb, line 33
def escape_example_footnote(code)
  code.gsub(/^\\\[([a-z]+)/im, '[\1')
end
preprocess(document) click to toggle source
# File lib/nesta-contentfocus-extensions/renderer.rb, line 6
def preprocess(document)
  @document = document
end
syntax_highlight(code, language, id) click to toggle source
# File lib/nesta-contentfocus-extensions/renderer.rb, line 37
def syntax_highlight(code, language, id)
  options = syntax_highlight_options(language, id)
  code = escape_example_codeblock(code)
  code = escape_example_footnote(code)
  Pygments.highlight(code, options)
end
syntax_highlight_options(language, id) click to toggle source
# File lib/nesta-contentfocus-extensions/renderer.rb, line 17
def syntax_highlight_options(language, id)
  options = { options: {
    linenos: true,
    cssclass: 'hll',
    lineanchors: id,
    linespans: id,
    anchorlinenos: true
  } }
  #options.merge!(lexer: language) if LANGUAGES.include? language
  options
end