Class: SlackTransformer::Slack::Preformatted

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_transformer/slack/preformatted.rb

Constant Summary collapse

PATTERN =
/
  (?<=^|\W|_)

  # preceded by start of line, non-word character, or _

  (?<!~)

  # but not ~

  ([*_~]?)

  # optionally preceded by *, _, or ~

  ```(.+)```

  # one or more of anything surrounded by ```

  \1

  # followed by *, _, or ~ if preceded by it

  (?!~)

  # not followed by ~

  (?=\W|_|$)

  # followed by non-word character, _, or end of line
/x

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Preformatted

Returns a new instance of Preformatted.



36
37
38
# File 'lib/slack_transformer/slack/preformatted.rb', line 36

def initialize(input)
  @input = input
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



4
5
6
# File 'lib/slack_transformer/slack/preformatted.rb', line 4

def input
  @input
end

Instance Method Details

#to_htmlObject



40
41
42
# File 'lib/slack_transformer/slack/preformatted.rb', line 40

def to_html
  input.gsub(PATTERN, '\1<pre>\2</pre>\1')
end