Changeset 273

Show
Ignore:
Timestamp:
02/03/08 01:32:04 (10 months ago)
Author:
ingy
Message:
Support for hr and wikilinks.

Needed to add support for attribute stuffs. Might be better way later.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/ingy/Document-Tools/lib/Document/Parser.pm

    r255 r273  
    9898    my $container_type = shift; 
    9999    my $types = $self->{grammar}{$container_type}{phrases}; 
    100     while (length $self->{input}) { 
     100    while ($self->{input} and length $self->{input}) { 
    101101        my $match; 
    102102        for my $type (@$types) { 
     
    171171        ? $self->{grammar}{$type}{type} 
    172172        : $type; 
    173     $self->{receiver}->begin_node($node_type) 
    174       if $node_type; 
     173    # The matched text gets passed to &$filter as $_.  In most cases, 
     174    # this will be enough. However, $match is also passed as a parameter 
     175    # to &$filter. This allows us to pass more structured data to the 
     176    # receiver. For example, you might use this when parsing links in 
     177    # WikiText, where the link text is passed as $_ and additional 
     178    # attributes are passed as fields in $match. 
     179 
     180    # TODO: Modify Makefile.PL to indicate change in API 
    175181    my $parser = $self->new( 
    176182        grammar => $self->{grammar}, 
    177183        receiver => $self->{receiver}->new, 
    178184        input => $filter 
    179         ? do { $_ = $match->{text}; &$filter(); $_ } 
     185        ? do { $_ = $match->{text}; &$filter($match); $_ } 
    180186        : $match->{text}, 
    181187    ); 
     188    $self->{receiver}->begin_node($node_type, $match) 
     189      if $node_type; 
    182190    $parser->$func($type); 
    183191    $self->{receiver}->insert($parser->{receiver}); 
  • trunk/src/ingy/Document-Tools/lib/Document/Parser/Creole.pm

    r272 r273  
    11package Document::Parser::Creole; 
    22use base 'Document::Parser'; 
     3use XXX; 
    34 
    45sub create_grammar { 
     
    910 
    1011    my $all_phrases = [ 
    11         'b', 'i', 'tt', 'br', 
     12        'b', 'i', 'tt', 'br', 'wikilink', 
    1213    ]; 
    1314 
     
    9495        }, 
    9596        hr => { 
    96             match => qr/\ *----\ *\n/, 
     97            match => qr/^ *----\s*\n/, 
    9798        }, 
    9899         
     
    111112            match => qr/\\\\/, 
    112113        }, 
     114        wikilink => { 
     115            type => 'a', 
     116            match => qr/\[\[(.*?)\]\]/, 
     117            filter => sub { 
     118                my $match = shift; 
     119                if (s/(.*?)\s*\|\s*(.*)/$2/) { 
     120                    $match->{href} = $1; 
     121                } 
     122            }, 
     123        }, 
     124 
    113125    }; 
    114126} 
  • trunk/src/ingy/Document-Tools/lib/Document/Viewer/HTML.pm

    r268 r273  
    44 
    55use base 'Document::AST'; 
     6use CGI::Util; 
    67 
    78#sub view { 
     
    3031} 
    3132 
     33sub uri_escape { 
     34    $_ = shift; 
     35    s/ /\%20/g; 
     36    return $_; 
     37} 
     38 
    3239sub begin_node { 
    3340    my $self = shift; 
    3441    my $tag = shift; 
    35     $tag =~ s/-.*//; 
    36     $self->{output} .= "<$tag>"; 
     42    my $node = shift; 
     43    if ($tag eq "a") { 
     44        $self->{output} .= 
     45            '<a href="' . 
     46            CGI::Util::escape($node->{href}) . 
     47            '">'; 
     48        return; 
     49    } 
     50# XXX For tables. 
     51#    $tag =~ s/-.*//; 
     52    $self->{output} .= ($tag =~ /^(br|hr)$/) 
     53        ? "<$tag />\n" 
     54        : "<$tag>"; 
    3755} 
    3856 
     
    4159    my $tag = shift; 
    4260    $tag =~ s/-.*//; 
    43     $self->{output} .= "</$tag>"; 
     61    return if ($tag =~ /^(br|hr)$/); 
     62    $self->{output} .= "</$tag>" . 
     63        ($tag =~ /^(p|hr|table|ul|ol|h\d)$/ ? "\n" : ""); 
    4464} 
    4565 
     
    4767    my $self = shift; 
    4868    my $text = shift; 
    49     $text =~ s/\n/\n /g; 
    5069    $self->{output} .= "$text"; 
    5170} 
  • trunk/src/ingy/Document-Tools/t/data/lists

    r270 r273  
    1414-li 
    1515-ul 
    16 --- html chomp 
    17 <ul><li>Item one.<ul><li>Subitem one.</li></ul></li></ul> 
     16--- html 
     17<ul><li>Item one.<ul><li>Subitem one.</li></ul> 
     18</li></ul> 
    1819=== Sublists are well formed XHTML 
    1920--- creole