Module: GitlabKramdown::Parser::Label
- Included in:
- Kramdown::Parser::GitlabKramdown
- Defined in:
- lib/gitlab_kramdown/parser/label.rb
Overview
GitLab Labels
This parser implements non context-specific label references as described in the GitLab Flavored Markdown reference
Constant Summary collapse
- PROJECT_LABEL_PATTERN =
%r{ #{Regexp.escape('~')} (?<label> [A-Za-z0-9_\-?.&]+ | # String-based single-word label title, or ".+?" # String-based multi-word label surrounded in quotes ) }x
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
20 21 22 |
# File 'lib/gitlab_kramdown/parser/label.rb', line 20 def self.included(klass) klass.define_parser(:label, PROJECT_LABEL_PATTERN, '\~') end |
Instance Method Details
#parse_label ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gitlab_kramdown/parser/label.rb', line 24 def parse_label start_line_number = @src.current_line_number @src.pos += @src.matched_size namespace = extract_reference_namespace! # If we can't find a namespace we just add content as regular text and skip unless namespace add_text(@src[0]) return end label_name = @src[:label].delete('"') label_param = label_name.tr(' ', '+') href = "#{@options[:gitlab_url]}/#{namespace}/issues?label_name=#{label_param}" label_attrs = { 'href' => href, 'label' => label_name, 'namespace' => namespace } el = Kramdown::Element.new(:label, nil, label_attrs, location: start_line_number) @tree.children << el end |