Class Texy::Dom
In: lib/texy/dom.rb
Parent: BlockElement

Texy! DOM

Methods

build_lists   parse   to_html  

Included Modules

DomEasyAccess

Attributes

elements  [R] 
elements_by_class  [R] 
elements_by_id  [R] 

Public Instance methods

Build list for easy access to DOM structure

[Source]

# File lib/texy/dom.rb, line 390
        def build_lists
            @elements = []
            @elements_by_id = {}
            @elements_by_class = {}

            broadcast
        end

Convert Texy! document into DOM structure

Before converting it normalize text and call all pre-processing modules

[Source]

# File lib/texy/dom.rb, line 325
        def parse(text)
            # Remove special chars, normalize lines.
            text = Texy.wash(text)

            # Standardize line endings to unix-like (dos, mac).
            text.gsub! "\r\n", "\n" # DOS
            text.gsub! "\r", "\n" # Mac

            # Replace tabs with spaces.
            tab_width = texy.tab_width

            while text.include?("\t")
                text.gsub! /^(.*)\t/ do
                    $1 + ' ' * ((tab_width - $1.length) % tab_width)
                end
            end

            # Remmove Texy! comments.
            comment_chars = "\xC2\xA7"

            text.gsub! /#{comment_chars}{2,}(?!#{comment_chars}).*(#{comment_chars}{2,}|$)(?!#{comment_chars})/m, ''

            # Right trim.
            text.gsub /[\t ]+$/m, ''


            # Pre-processing.
            texy.modules.each do |mod|
                text = mod.pre_process(text)
            end

            # Process.
            super
        end

Convert DOM structure to (X)HTML code and call all post-processing modules

[Source]

# File lib/texy/dom.rb, line 364
        def to_html
            html = super

            html = Html::WellForm.new.process(html)

            # Post-process.
            texy.modules.each do |mod|
                html = mod.post_process(html)
            end

            # Unfreeze spaces.
            html = Texy.unfreeze_spaces(html)
            html = Html.check_entities(html)

            # (rane) i've removed the notice "generated by texy!".

            html
        end

[Validate]