Class: HatenablogPublisher::Generator::Body
- Inherits:
-
Object
- Object
- HatenablogPublisher::Generator::Body
- Defined in:
- lib/hatenablog_publisher/generator/body.rb
Constant Summary collapse
- IMAGE_PATTERN =
/[^`]!\[.*\]\((.*)\)/.freeze
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(context, options) ⇒ Body
constructor
A new instance of Body.
- #remove_textlint_comment(markdown) ⇒ Object
- #replace_image(markdown) ⇒ Object
Constructor Details
#initialize(context, options) ⇒ Body
Returns a new instance of Body.
8 9 10 11 |
# File 'lib/hatenablog_publisher/generator/body.rb', line 8 def initialize(context, ) @context = context @options = end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/hatenablog_publisher/generator/body.rb', line 4 def context @context end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/hatenablog_publisher/generator/body.rb', line 4 def @options end |
Instance Method Details
#generate ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/hatenablog_publisher/generator/body.rb', line 13 def generate markdown = @context.text.dup replaced_markdown = remove_textlint_comment(replace_image(markdown)) CGI.escapeHTML(replaced_markdown) end |
#remove_textlint_comment(markdown) ⇒ Object
21 22 23 |
# File 'lib/hatenablog_publisher/generator/body.rb', line 21 def remove_textlint_comment(markdown) markdown.gsub(/^<!--\s+textlint-(enable|disable).*-->\n/, '') end |
#replace_image(markdown) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hatenablog_publisher/generator/body.rb', line 25 def replace_image(markdown) markdown.gsub(IMAGE_PATTERN) do |s| image_name = Regexp.last_match(1) if image_name.match('^http') s else "\n\n" + @context.image_syntax(image_name) end end end |