class Growi::ImageConverter::Body
markdown bodyを扱うクラス
Constants
- FILE_PATH_PREFIX
- REGEX_SPACE
- REGEX_SPACE_GE_1_OR_RETURN
- REGEX_SPACE_OR_RETURN
- REGEX_TITLE
- REGEX_URL_PREFIX_ESA
Attributes
body[RW]
markdown_images[RW]
Public Class Methods
new(body)
click to toggle source
# File lib/growi/image_converter/body.rb, line 15 def initialize(body) @body = body @markdown_images = [] end
Public Instance Methods
group_by_url()
click to toggle source
# File lib/growi/image_converter/body.rb, line 48 def group_by_url group_by_url = {} markdown_images.each do |markdown_image| (group_by_url[markdown_image.url] ||= []).push(markdown_image) end group_by_url end
replace_markdown_image(attached_file)
click to toggle source
# File lib/growi/image_converter/body.rb, line 56 def replace_markdown_image(attached_file) attached_file_path = FILE_PATH_PREFIX + attached_file.data[:attachment]._id attached_file.markdown_images.each do |markdown_image| body.sub! markdown_image.syntax, markdown_image.replace_url(attached_file_path) end end
scan_markdown_image_esa()
click to toggle source
# File lib/growi/image_converter/body.rb, line 21 def scan_markdown_image_esa matches = [] # Image syntax inline matches.concat(body.scan( / !\[#{REGEX_SPACE_OR_RETURN}.*?#{REGEX_SPACE_OR_RETURN}\] \(#{REGEX_SPACE_OR_RETURN} #{REGEX_URL_PREFIX_ESA}.*?#{REGEX_TITLE} #{REGEX_SPACE_OR_RETURN}\) /x )) # Image syntax reference-style matches.concat(body.scan( / \[#{REGEX_SPACE_OR_RETURN}.*?#{REGEX_SPACE_OR_RETURN}\]: #{REGEX_SPACE_OR_RETURN}#{REGEX_URL_PREFIX_ESA}.* /x )) # Image syntax img tag matches.concat(body.scan(/<img#{REGEX_SPACE_GE_1_OR_RETURN}.*?#{REGEX_URL_PREFIX_ESA}.*?>/m)) @markdown_images = matches.map { |match| Growi::ImageConverter::MarkdownImage.new match } end