Class: Telegrama::Formatter::MarkdownTokenizer

Inherits:
Object
  • Object
show all
Defined in:
lib/telegrama/formatter.rb

Overview

A tokenizer that processes text and applies Markdown formatting rules

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ MarkdownTokenizer

Initialize the tokenizer with text to process

Parameters:

  • text (String)

    The text to tokenize and format



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/telegrama/formatter.rb', line 130

def initialize(text)
  @text = text
  @result = ""
  @position = 0
  @chars = text.chars
  @length = text.length

  # State tracking
  @state = :normal
  @state_stack = []
end

Instance Method Details

#processString

Process the text, applying formatting rules

Returns:

  • (String)

    The processed text



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/telegrama/formatter.rb', line 144

def process
  while @position < @length
    case @state
    when :normal
      process_normal_state
    when :code_block
      process_code_block_state
    when :triple_code_block
      process_triple_code_block_state
    when :bold
      process_bold_state
    when :italic
      process_italic_state
    when :link_text
      process_link_text_state
    when :link_url
      process_link_url_state
    end
  end

  # Handle any unclosed formatting
  finalize_result

  @result
end