class JekyllWikiLinks::WikiLink

the wikilink class knows everything about the original markdown syntax and its semantic meaning

Constants

BLOCK_ID
FILENAME
HEADER_TXT

Attributes

block_id[RW]
embed[RW]
filename[RW]
header_txt[RW]
label_txt[RW]

Public Class Methods

new(embed, link_type, filename, header_txt, block_id, label_txt) click to toggle source

parameters ordered by appearance in regex

# File lib/jekyll-wikilinks/parser.rb, line 148
def initialize(embed, link_type, filename, header_txt, block_id, label_txt)
  # super(embed, link_type, filename, header_txt, block_id, label_txt)
  @embed ||= embed
  @link_type ||= link_type
  @filename ||= filename
  @header_txt ||= header_txt
  @block_id ||= block_id
  @label_txt ||= label_txt
end

Public Instance Methods

clean_label_txt() click to toggle source

labeles are really flexible, so we need to handle them with a bit more care

# File lib/jekyll-wikilinks/parser.rb, line 159
def clean_label_txt
  return @label_txt.sub("[", "\\[").sub("]", "\\]")
end
describe() click to toggle source
# File lib/jekyll-wikilinks/parser.rb, line 197
def describe
  return {
    'level' => level,
    'labelled' => labelled?,
    'embedded' => embedded?,
    'typed_link' => typed?,
  }
end
described?(chunk) click to toggle source
# File lib/jekyll-wikilinks/parser.rb, line 223
def described?(chunk)
  return (!@filename.nil? && !@filename.empty?) if chunk == FILENAME
  return (!@header_txt.nil? && !@header_txt.empty?) if chunk == HEADER_TXT
  return (!@block_id.nil? && !@block_id.empty?) if chunk == BLOCK_ID
  Jekyll.logger.error "There is no link level '#{chunk}' in WikiLink Struct"
end
embedded?() click to toggle source
# File lib/jekyll-wikilinks/parser.rb, line 214
def embedded?
  return !@embed.nil? && @embed == "!"
end
is_img?() click to toggle source
# File lib/jekyll-wikilinks/parser.rb, line 218
def is_img?
  # github supported image formats: https://docs.github.com/en/github/managing-files-in-a-repository/working-with-non-code-files/rendering-and-diffing-images
  return SUPPORTED_IMG_FORMATS.any?{ |ext| ext == File.extname(@filename).downcase }
end
labelled?() click to toggle source
# File lib/jekyll-wikilinks/parser.rb, line 206
def labelled?
  return !@label_txt.nil? && !@label_txt.empty?
end
level() click to toggle source
# File lib/jekyll-wikilinks/parser.rb, line 230
def level
  return "file" if described?(FILENAME) && !described?(HEADER_TXT) && !described?(BLOCK_ID)
  return "header" if described?(FILENAME) && described?(HEADER_TXT) && !described?(BLOCK_ID)    
  return "block" if described?(FILENAME) && !described?(HEADER_TXT) && described?(BLOCK_ID)
  return "invalid"
end
typed?() click to toggle source
# File lib/jekyll-wikilinks/parser.rb, line 210
def typed?
  return !@link_type.nil? && !@link_type.empty?
end