Class: WikiWah::Flow
- Inherits:
-
Object
- Object
- WikiWah::Flow
- Defined in:
- lib/wikiwah/flow.rb
Overview
Flow deals with block-level formatting in WikiWah. Input text is split into paragraphs, separated by blank lines. A list-item bullet also implies a new paragraph.
Flow keeps track of the current level of indentation, and emits block-start and block-end tags (e.g. “<li>”, “</li>”) as required.
Flow recognises the following types of blocks:
-
A line prefixed by “=” is a heading. The heading-level is implied by the number of “=” characters.
-
A line beginning with “*” or “-” is an unordered list item.
-
A line beginning with “1.”, “(1)” or “#” is an ordered list item.
-
A paragraph prefixed by “|” is preformatted text (e.g. code)
-
A paragraph prefixed by “>” is a blockquote (ie. a citation)
-
Anything else is plain old body text.
Defined Under Namespace
Classes: Context
Constant Summary collapse
- BlankRegexp =
Patterns that start a new block
/\A *$/
- BulletRegexp =
Regexp.new('\A *([\*\-\#]|\d+\.|\(\d+\)) ')
Class Method Summary collapse
-
.convert(input, &filter) ⇒ Object
Convert
input
text to HTML.
Instance Method Summary collapse
-
#initialize(out, text_filter = null) ⇒ Flow
constructor
A new instance of Flow.
-
#process(input) ⇒ Object
Process a multi-line input string.
Constructor Details
#initialize(out, text_filter = null) ⇒ Flow
Returns a new instance of Flow.
46 47 48 49 50 51 |
# File 'lib/wikiwah/flow.rb', line 46 def initialize(out, text_filter=null) @out = out @text_filter = text_filter @context_stack = [TopContext] @block_buffer = nil end |
Class Method Details
.convert(input, &filter) ⇒ Object
Convert input
text to HTML.
An optional filter
block may be provided, in which case it’s applied to the body of each block.
35 36 37 38 39 40 |
# File 'lib/wikiwah/flow.rb', line 35 def Flow.convert(input, &filter) buff = '' parser = Flow.new(buff,filter) parser.process(input) buff end |
Instance Method Details
#process(input) ⇒ Object
Process a multi-line input string
54 55 56 57 |
# File 'lib/wikiwah/flow.rb', line 54 def process(input) add_input(input) flush_context_stack end |