Class: Klondikemarlen::JiraApi::MarkdownToAdf

Inherits:
Object
  • Object
show all
Defined in:
lib/klondikemarlen/jira_api/markdown_to_adf.rb

Constant Summary collapse

IMAGE_TAG_PATTERN =
/<img\b(?<attributes>[^>]+)>/i

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(markdown, image_resolver: nil) ⇒ MarkdownToAdf

Returns a new instance of MarkdownToAdf.



38
39
40
41
# File 'lib/klondikemarlen/jira_api/markdown_to_adf.rb', line 38

def initialize(markdown, image_resolver: nil)
  @markdown = markdown.to_s
  @image_resolver = image_resolver
end

Class Method Details

.call(markdown, &image_resolver) ⇒ Object



10
11
12
# File 'lib/klondikemarlen/jira_api/markdown_to_adf.rb', line 10

def self.call(markdown, &image_resolver)
  new(markdown, image_resolver: image_resolver).to_document
end

.media_single(id:, alt:, width:, height:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/klondikemarlen/jira_api/markdown_to_adf.rb', line 14

def self.media_single(id:, alt:, width:, height:)
  {
    "type" => "mediaSingle",
    "attrs" => { "layout" => "center" },
    "content" => [
      {
        "type" => "media",
        "attrs" => {
          "id" => id,
          "type" => "file",
          "collection" => "jira-issue-attachments",
          "alt" => alt,
          "width" => width,
          "height" => height,
        },
      },
    ],
  }
end

.paragraph(text) ⇒ Object



34
35
36
# File 'lib/klondikemarlen/jira_api/markdown_to_adf.rb', line 34

def self.paragraph(text)
  new("").send(:paragraph_from_text, text)
end

Instance Method Details

#to_documentObject



43
44
45
46
47
48
49
# File 'lib/klondikemarlen/jira_api/markdown_to_adf.rb', line 43

def to_document
  {
    "type" => "doc",
    "version" => 1,
    "content" => document_content,
  }
end