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]
link_type[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
md_link_regex()
click to toggle source
# File lib/jekyll-wikilinks/parser.rb, line 180 def md_link_regex regex_embed = embedded? ? REGEX_LINK_EMBED : %r{} regex_link_type = typed? ? %r{#{@link_type}#{REGEX_LINK_TYPE}} : %r{} filename = described?(FILENAME) ? @filename : "" if described?(HEADER_TXT) header = %r{#{REGEX_LINK_HEADER}#{@header_txt}} block = %r{} elsif described?(BLOCK_ID) header = %r{} block = %r{#{REGEX_LINK_BLOCK}#{@block_id}} elsif !described?(FILENAME) Jekyll.logger.error "Invalid link level in regex. See WikiLink's 'md_link_regex' for details" end label_ = labelled? ? %r{#{REGEX_LINK_LABEL}#{clean_label_txt}} : %r{} return %r{#{regex_embed}#{regex_link_type}\[\[#{filename}#{header}#{block}#{label_}\]\]} end
md_link_str()
click to toggle source
# File lib/jekyll-wikilinks/parser.rb, line 163 def md_link_str embed = embedded? ? "!" : "" link_type = typed? ? "#{@link_type}::" : "" filename = described?(FILENAME) ? @filename : "" if described?(HEADER_TXT) header = "\##{@header_txt}" block = "" elsif described?(BLOCK_ID) header = "" block = "\#\^#{@block_id}" elsif !described?(FILENAME) Jekyll.logger.error "Invalid link level in 'md_link_str'. See WikiLink's 'md_link_str' for details" end label_ = labelled? ? "\|#{@label_txt}" : "" return "#{embed}#{link_type}\[\[#{filename}#{header}#{block}#{label_}\]\]" end
typed?()
click to toggle source
# File lib/jekyll-wikilinks/parser.rb, line 210 def typed? return !@link_type.nil? && !@link_type.empty? end