class Jekyll::SideNoteGenerator

Constants

ALD_ANY_CHARS
ALD_ID_CHARS

from extensions.rb

ALD_ID_NAME
BLANK_LINE

from kramdown: github.com/gettalong/kramdown from blank_line.rb

CODEBLOCK_MATCH

from markdown.rb CODEBLOCK_MATCH = /(?:#{BLANK_LINE}?(?:#{INDENT}[ t]S.n)+)*/ because `.gsub(INDENT, '')` in footnote.rb CODEBLOCK_MATCH = /(?:#{BLANK_LINE}?(?:s[ t]S.n)+)*/ from codeblock.rb

COMBININGCHAR
EOB_MARKER

from eob.rb

EXTENDER
HTML_SPAN_ELEMENTS

from html.rb Some HTML elements like script belong to both categories (i.e. are valid in block and span HTML) and don't appear therefore! script, textarea

IAL_BLOCK
IAL_BLOCK_START
INDENT

Regexp for matching indentation (one tab or four spaces)

LAZY_END_HTML_SPAN_ELEMENTS

from paragraph.rb

LAZY_END_HTML_START
LAZY_END_HTML_STOP
LEFT_SIDENOTE_DEFINITION_START

left

LEFT_SIDENOTE_MARKER_START
LETTER

from baseparser: github.com/ruby/rexml/blob/master/lib/rexml/parsers/baseparser.rb#L36

NCNAME_STR
OPT_SPACE

from kramdown.rb

RIGHT_SIDENOTE_DEFINITION_START

footnotes (for reference) FOOTNOTE_DEFINITION_START = /^#{OPT_SPACE}[^(#{ALD_ID_NAME})]:s*?(.*?n#{CODEBLOCK_MATCH})/ FOOTNOTE_MARKER_START = /[^(#{ALD_ID_NAME})]/

constants for local use

right

RIGHT_SIDENOTE_MARKER_START
UNAME_STR

Attributes

md_docs[RW]

Public Instance Methods

generate(site) click to toggle source
# File _plugins/sidenote.rb, line 67
def generate(site)

  # setup markdown docs
                    docs = site.pages + site.docs_to_write
                    @md_docs = docs.filter {|doc| site.find_converter_instance(Jekyll::Converters::Markdown).matches(doc.extname) }
  
  link_extension = !!site.config["use_html_extension"] ? '.html' : ''
   
  @md_docs.each do |cur_doc|
    # check for newlines @ eof.
    #   (kramdown can handle footnotes with no newline, but the regex i'm getting requires a newline after the last footnote to find it.)
    if cur_doc.content[-1] != "\n"
      Jekyll.logger.warn "Missing newline at end of file -- this could break sidenotes: ", cur_note.data['title']
    end    
    parse_sidenote(cur_doc, "left")
    parse_sidenote(cur_doc, "right")
  end
end
parse_sidenote(doc, side) click to toggle source

mark -> [<left-sidenote], [>right-sidenote] def -> [<left-sidenote]:, [>right-sidenote]: `side` should be 'right' or 'left'

# File _plugins/sidenote.rb, line 92
def parse_sidenote(doc, side)
  # left v right setup
  if side == "right"
    sidenote_def_regex = RIGHT_SIDENOTE_DEFINITION_START
    # sidenote_mark_regex = RIGHT_SIDENOTE_MARKER_START
    css_class = "rsn"
    sn_regex = /\>/
  elsif side == "left"
    sidenote_def_regex = LEFT_SIDENOTE_DEFINITION_START
    # sidenote_mark_regex = LEFT_SIDENOTE_MARKER_START
    css_class = "lsn"
    sn_regex = /\</
  else
      Jekyll.logger.error "Can't process sidenote that is not either 'right' or 'left'."
      return
  end
  # process sidenotes
  sidenotes = doc.content.scan(sidenote_def_regex)
  doc.content.gsub!(sidenote_def_regex, '') # rm sidenote defs from original note.
  i = 0
  sidenotes.each do |sidenote|
    i += 1
    mark = sidenote[0]
    definition = sidenote[1]
    doc.content = doc.content.gsub(
      /\[#{sn_regex}(#{mark})\]/i,
      "<label for=\"#{css_class}-#{i}\" class=\"sidenote-toggle sidenote-number\"></label><input type=\"checkbox\" id=\"#{css_class}-#{i}\" class=\"sidenote-toggle\"><span class=\"#{css_class}\">#{definition}</span>"
    )
  end
end