Class: JayAddLink

Inherits:
HTML::Pipeline::TextFilter
  • Object
show all
Defined in:
lib/jay_flavored_markdown/markdown_converter.rb

Instance Method Summary collapse

Instance Method Details

#callObject



896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 896

def call
  lines = @text.split("\n")

  # Replace GitHub issue notation into solid markdown link.
  # Example:
  #   nomlab/jay/#10
  # becomes:
  #   [nomlab/jay/#10](https://github.com/nomlab/jay/issues/10){:.github-issue}
  #
  # NOTE: {:.foo} is a kramdown dialect to add class="foo" to HTML.
  @text = lines.map do |line|
    line.gsub(%r{(?:([\w.-]+)/)??(?:([\w.-]+)/)?#(\d+)}i) do |match|
      url = "https://github.com/#{$1 || context[:organization]}/#{$2}/issues/#{$3}"
      "[#{match}](#{url}){:.github-issue}"
    end
  end

  # Replace action-item notation into solid markdown link.
  # Example:
  #   -->(name !:0001) becomes [-->(name !:0001)](){:data-action-item="0001"}
  #
  # NOTE: {:attr=val} is a kramdown dialect to add attribute to DOM element.
  @text = @text.map do |line|
    line.gsub(/-->\((.+?)!:([0-9]{4})\)/) do |macth|
      assignee, action = $1.strip, $2.strip
      "[-->(#{assignee} !:#{action})](){:.action-item}{:data-action-item=\"#{action}\"}"
    end
  end.join("\n")
end