Class: Gitt::Sanitizers::Paragraphs

Inherits:
Object
  • Object
show all
Defined in:
lib/gitt/sanitizers/paragraphs.rb

Overview

Detects and parses paragraphs (including code blocks).

Constant Summary collapse

PATTERN =
/
  (            # Condition start.
  (?:          # Opens non-capture group.
  \.           # Dot character.
  (?!\s)       # Negative look ahead for whitespace character.
  [^\n]*?      # Non-greedy match for non-whitespace characters.
  \n           # New line character.
  )            # End of non-capture group.
  ?            # Makes above capture group optional.
  (?:          # Opens non-capture group.
  \[           # Open bracket character.
  .*           # Greedy matches any character zero or more times.
  \]           # Close bracket character.
  \n           # New line character.
  )            # Closes non-capture group.
  ?            # Makes above capture group optional.
  [-_=+.*]{4}  # ASCII Doc block start.
  [\s\S]*?     # Lazy block content with any character.
  [-_=+.*]{4}  # ASCII Doc block end.
  |            # Or.
  ```          # Markdown start.
  [\s\S]*?     # Lazy block content with any character.
  ```          # Markdown end.
  )            # Condition end.
/mx

Instance Method Summary collapse

Constructor Details

#initialize(pattern: PATTERN, client: StringScanner) ⇒ Paragraphs

Returns a new instance of Paragraphs.



36
37
38
39
# File 'lib/gitt/sanitizers/paragraphs.rb', line 36

def initialize pattern: PATTERN, client: StringScanner
  @pattern = pattern
  @client = client
end

Instance Method Details

#call(text) ⇒ Object



41
# File 'lib/gitt/sanitizers/paragraphs.rb', line 41

def call(text) = scan client.new(text.to_s)