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



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/telegrama/formatter.rb', line 121

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



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/telegrama/formatter.rb', line 135

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