Class: Gitlab::GithubImport::MarkdownText

Inherits:
Object
  • Object
show all
Includes:
EncodingHelper, Import::UsernameMentionRewriter
Defined in:
lib/gitlab/github_import/markdown_text.rb

Constant Summary collapse

GITHUB_MEDIA_CDN =

On github.com we have base url for docs and CDN url for media. On github EE as far as we can know there is no CDN urls and media is placed on base url.

'https://user-images.githubusercontent.com/'
ISSUE_REF_MATCHER =
'%{github_url}/%{import_source}/issues'
PULL_REF_MATCHER =
'%{github_url}/%{import_source}/pull'

Constants included from Import::UsernameMentionRewriter

Import::UsernameMentionRewriter::MENTION_REGEX

Constants included from EncodingHelper

EncodingHelper::BOM_UTF8, EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD, EncodingHelper::ESCAPED_CHARS, EncodingHelper::UNICODE_REPLACEMENT_CHARACTER

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Import::UsernameMentionRewriter

#update_username_mentions, #wrap_mentions_in_backticks

Methods included from EncodingHelper

#binary_io, #detect_binary?, #detect_encoding, #detect_libgit2_binary?, #encode!, #encode_binary, #encode_utf8, #encode_utf8_no_detect, #encode_utf8_with_escaping!, #encode_utf8_with_replacement_character, #force_encode_utf8, #strip_bom, #unquote_path

Constructor Details

#initialize(text, author = nil, exists = false, project: nil, client: nil) ⇒ MarkdownText

text - The Markdown text as a String. author - An instance of Gitlab::GithubImport::Representation::User exists - Boolean that indicates the user exists in the GitLab database. project - An instance of Project.



47
48
49
50
51
52
53
# File 'lib/gitlab/github_import/markdown_text.rb', line 47

def initialize(text, author = nil, exists = false, project: nil, client: nil)
  @text = text
  @author = author
  @exists = exists
  @project = project
  @web_endpoint = client&.web_endpoint || ::Octokit::Default.web_endpoint
end

Class Method Details

.fetch_attachments(text, web_endpoint) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/github_import/markdown_text.rb', line 23

def fetch_attachments(text, web_endpoint)
  attachments = []
  return attachments if text.nil?

  doc = CommonMarker.render_doc(text)

  doc.walk do |node|
    attachment = extract_attachment(node, web_endpoint)
    attachments << attachment if attachment
  end
  attachments
end

.formatObject



19
20
21
# File 'lib/gitlab/github_import/markdown_text.rb', line 19

def format(...)
  new(...).perform
end

Instance Method Details

#performObject



55
56
57
58
59
60
61
62
# File 'lib/gitlab/github_import/markdown_text.rb', line 55

def perform
  return if text.blank?

  # Gitlab::EncodingHelper#clean remove `null` chars from the string
  text = clean(formatted_text)
  text = convert_ref_links(text, project, web_endpoint) if project.present?
  wrap_mentions_in_backticks(text)
end