Class: SlackTransformer::Slack::Italics

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

Constant Summary collapse

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

  # preceded by start of line or non-word character

  (?<![*~`])

  # but not *, ~, or `, which are mrkdwn delimiters
  # Note: _ is also a mrkdwn delimiter, but it's included in \W because
  # it's a word character.

  ([*~]?)

  # optionally preceded by * or ~

  _((?:[^_]|(?<=[a-zA-Z0-9\s])_+(?=[a-zA-Z0-9]))+)_

  # one or more of either not _, or one or more _ preceded by letter,
  # number, or space and followed by letter or number, 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) ⇒ Italics

Returns a new instance of Italics.



39
40
41
# File 'lib/slack_transformer/slack/italics.rb', line 39

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/italics.rb', line 4

def input
  @input
end

Instance Method Details

#to_htmlObject



43
44
45
# File 'lib/slack_transformer/slack/italics.rb', line 43

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