siboom.rb
def convertSiboom(input,o)
    notes = []
    inparagraph = false
    inlist = false
    inpara = false
    output = o.header
    input = File.open(input).to_a if input.is_a?(String)
    i = 0

    # We perform processing on a line by line basis
    while input[i] do
        line = input[i]

        # Handle termination of lists/paragraphs.
        # To handle this here is much simpler.
        if inlist and line[0..2] != " * "
            output += o.end_list
            inlist = false
        end
        if (inpara and line[0..4] != "!note") and (line[0..2] == " * " or line[0..0] == "!" or line[0..0] == "=" or line.strip == "")
            output += o.end_para
            inpara = false
        end

        # Handle bang forms
        if line[0..0] == "!"
            ba = parseBangForm(input,i)
            case ba[0]
                when "book"
                    output += o.frontpage(ba[1].strip,ba[2].strip)
                when "image"
                    output += o.image(ba[1].strip,ba[2].strip)
                when "code"
                    output += o.code(ba[1..-1])
                when "cit"
                    output += o.cit(ba[1].strip,ba[2].strip)
                when "note"
                    notes << ba[1]
                    output += o.noteref(notes.length)
                when "shownotes"
                    if notes.length
                        output += o.title(ba[1].strip)
                        output += o.start_notes
                        notes.each_with_index{|n,notenum|
                            output += o.notes_item(notenum+1,convertInlineMarkup(n.strip,o))
                        }
                        output += o.end_notes
                    end
                else
                    raise "Unrecognized bang form: #{ba[0]} (line #{i})"
            end
            i += ba.length+1
            next
        end

        # Handle special forms like titles, subtitles, lists, ...
        if line[0..1] == "%%"
            # This is just a comment, skip it
            i += 1
            next
        elsif line[0..1] == "=="
            output += o.subtitle(line[2..-1].strip)
            i += 1
            next
        elsif line[0..0] == "="
            output += o.title(line[1..-1].strip)
            i += 1
            next
        elsif line[0..2] == " * "
            if !inlist
                inlist = true
                output += o.start_list
            end
            i += 1
            output += o.list_item(convertInlineMarkup(line[3..-1].strip,o))
            next
        end

        # Handle normal lines of text, with inline markup like bold and italic
        output += o.start_para if !inpara
        inpara = true
        output += convertInlineMarkup(line.strip,o)
        i += 1
    end

    # Done! Handle again the list termination thing
    output += o.end_list if inlist
    output += o.end_para if inpara
    output += o.footer
end
# Convert input into the target format using the 'o' output filter.
Convert input into the target format using the 'o' output filter.
Convert input into the target format using the ' o ' output filter .
def convertSiboom(input,o)
    notes = []
    inparagraph = false
    inlist = false
    inpara = false
    output = o.header
    input = File.open(input).to_a if input.is_a?(String)
    i = 0
    while input[i] do
        line = input[i]
        if inlist and line[0..2] != " * "
            output += o.end_list
            inlist = false
        end
        if (inpara and line[0..4] != "!note") and (line[0..2] == " * " or line[0..0] == "!" or line[0..0] == "=" or line.strip == "")
            output += o.end_para
            inpara = false
        end
        if line[0..0] == "!"
            ba = parseBangForm(input,i)
            case ba[0]
                when "book"
                    output += o.frontpage(ba[1].strip,ba[2].strip)
                when "image"
                    output += o.image(ba[1].strip,ba[2].strip)
                when "code"
                    output += o.code(ba[1..-1])
                when "cit"
                    output += o.cit(ba[1].strip,ba[2].strip)
                when "note"
                    notes << ba[1]
                    output += o.noteref(notes.length)
                when "shownotes"
                    if notes.length
                        output += o.title(ba[1].strip)
                        output += o.start_notes
                        notes.each_with_index{|n,notenum|
                            output += o.notes_item(notenum+1,convertInlineMarkup(n.strip,o))
                        }
                        output += o.end_notes
                    end
                else
                    raise "Unrecognized bang form: #{ba[0]} (line #{i})"
            end
            i += ba.length+1
            next
        end
        if line[0..1] == "%%"
            i += 1
            next
        elsif line[0..1] == "=="
            output += o.subtitle(line[2..-1].strip)
            i += 1
            next
        elsif line[0..0] == "="
            output += o.title(line[1..-1].strip)
            i += 1
            next
        elsif line[0..2] == " * "
            if !inlist
                inlist = true
                output += o.start_list
            end
            i += 1
            output += o.list_item(convertInlineMarkup(line[3..-1].strip,o))
            next
        end
        output += o.start_para if !inpara
        inpara = true
        output += convertInlineMarkup(line.strip,o)
        i += 1
    end
    output += o.end_list if inlist
    output += o.end_para if inpara
    output += o.footer
end
def convertSiboom ( input , o ) notes = [ ] inparagraph = false inlist = false inpara = false output = o . header input = File . open ( input ) . to_a if input . is_a? ( String ) i = 0 while input [ i ] do line = input [ i ] if inlist and line [ 0 .. 2 ] != " * " output += o . end_list inlist = false end if ( inpara and line [ 0 .. 4 ] != "!note" ) and ( line [ 0 .. 2 ] == " * " or line [ 0 .. 0 ] == "!" or line [ 0 .. 0 ] == "=" or line . strip == "" ) output += o . end_para inpara = false end if line [ 0 .. 0 ] == "!" ba = parseBangForm ( input , i ) case ba [ 0 ] when "book" output += o . frontpage ( ba [ 1 ] . strip , ba [ 2 ] . strip ) when "image" output += o . image ( ba [ 1 ] . strip , ba [ 2 ] . strip ) when "code" output += o . code ( ba [ 1 .. - 1 ] ) when "cit" output += o . cit ( ba [ 1 ] . strip , ba [ 2 ] . strip ) when "note" notes << ba [ 1 ] output += o . noteref ( notes . length ) when "shownotes" if notes . length output += o . title ( ba [ 1 ] . strip ) output += o . start_notes notes . each_with_index { | n , notenum | output += o . notes_item ( notenum + 1 , convertInlineMarkup ( n . strip , o ) ) } output += o . end_notes end else raise "Unrecognized bang form: #{ba[0]} (line #{i})" end i += ba . length + 1 next end if line [ 0 .. 1 ] == "%%" i += 1 next elsif line [ 0 .. 1 ] == "==" output += o . subtitle ( line [ 2 .. - 1 ] . strip ) i += 1 next elsif line [ 0 .. 0 ] == "=" output += o . title ( line [ 1 .. - 1 ] . strip ) i += 1 next elsif line [ 0 .. 2 ] == " * " if ! inlist inlist = true output += o . start_list end i += 1 output += o . list_item ( convertInlineMarkup ( line [ 3 .. - 1 ] . strip , o ) ) next end output += o . start_para if ! inpara inpara = true output += convertInlineMarkup ( line . strip , o ) i += 1 end output += o . end_list if inlist output += o . end_para if inpara output += o . footer end
Convert input into the target format using the 'o' output filter.
Convert input into the target format using the ' o ' output filter .
# We perform processing on a line by line basis # Handle termination of lists/paragraphs. # To handle this here is much simpler. # Handle bang forms # Handle special forms like titles, subtitles, lists, ... # This is just a comment, skip it # Handle normal lines of text, with inline markup like bold and italic # Done! Handle again the list termination thing
input
o