Changeset 285
- Timestamp:
- 02/14/08 01:01:47 (5 months ago)
- Files:
-
- trunk/src/ingy/WikiText-Socialtext/Changes (modified) (1 diff)
- trunk/src/ingy/WikiText-Socialtext/lib/WikiText/Socialtext.pm (modified) (1 diff)
- trunk/src/ingy/WikiText-Socialtext/lib/WikiText/Socialtext/Parser.pm (modified) (10 diffs)
- trunk/src/ingy/WikiText-Socialtext/t/parser.t (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/ingy/WikiText-Socialtext/Changes
r284 r285 1 --- 2 version: 0.06 3 date: Tue Feb 12 21:59:21 PST 2008 4 changes: Added more parsing constructs 1 5 --- 2 6 version: 0.05 trunk/src/ingy/WikiText-Socialtext/lib/WikiText/Socialtext.pm
r284 r285 3 3 4 4 use 5.006.001; 5 our $VERSION = '0.0 5';5 our $VERSION = '0.06'; 6 6 7 7 1; trunk/src/ingy/WikiText-Socialtext/lib/WikiText/Socialtext/Parser.pm
r284 r285 4 4 use base 'WikiText::Parser'; 5 5 6 # Reusable regexp generators used by the grammar 7 my $ALPHANUM = '\p{Letter}\p{Number}\pM'; 8 6 9 sub create_grammar { 7 10 my $all_phrases = [ 8 11 # qw(wafl_phrase asis wiki hyper im b_hyper mail b_mail), 9 qw( tt b i del)12 qw(wikilink tt b i del) 10 13 ]; 11 14 my $all_blocks = [ 12 15 # qw(wafl_block hr hx wafl_p ul ol indent table p empty_p) 13 qw( wafl_block hr hx ul oltable p)16 qw(pre wafl_block hr hx waflparagraph ul ol blockquote table p) 14 17 ]; 15 18 … … 27 30 28 31 p => { 29 match => qr/( # Capture whole thing 30 (?: 31 ^(?! # All consecutive lines *not* starting with 32 (?: 33 [\#\-\*]+[\ ] | 34 [\^\|\>] | 35 \.\w+\s*\n | 36 \{[^\}]+\}\s*\n 32 match => qr/^( # Capture whole thing 33 (?m: 34 ^(?! # All consecutive lines *not* starting with 35 (?: 36 [\#\-\*]+[\ ] | 37 [\^\|\>] | 38 \.\w+\s*\n | 39 \{[^\}]+\}\s*\n 40 ) 41 ) 42 .*\S.*\n 43 )+ 37 44 ) 38 )39 .*\S.*\n40 )+41 45 (\s*\n)* # and all blank lines after 42 )/x,46 /x, 43 47 phrases => $all_phrases, 44 48 filter => sub { chomp }, 45 49 }, 50 51 pre => { 52 match => qr/^(?m:^\.pre\ *\n)((?:.*\n)*?)(?m:^\.pre\ *\n)(?:\s*\n)?/, 53 }, 54 55 blockquote => { 56 match => qr/^((?m:^>.*\n)+)/, 57 blocks => $all_blocks, 58 filter => sub { 59 s/^>\ //gm; 60 }, 61 }, 62 63 waflparagraph => { 64 match => qr/^\{(.*)\}[\ \t]*\n(?:\s*\n)?/, 65 filter => sub { 66 my $node = shift; 67 my ($function, $options) = split /[: ]/, $node->{text}, 2; 68 $options =~ s/\s*(.*?)\s*/$1/; 69 $node->{attributes}{function} = $function; 70 $node->{attributes}{options} = $options; 71 undef $_; 72 }, 73 }, 74 46 75 hx => { 47 76 match => qr/^(\^+) +(.*?)(\s+=+)?\s*?\n+/, … … 52 81 }, 53 82 }, 83 54 84 ul => { 55 85 match => re_list('\*'), … … 57 87 filter => sub { s/^[\*\#] *//mg }, 58 88 }, 89 59 90 ol => { 60 91 match => re_list('\#'), … … 62 93 filter => sub { s/^[\*\#] *//mg }, 63 94 }, 95 64 96 subl => { 65 97 type => 'li', … … 73 105 blocks => [qw(ul ol li2)], 74 106 }, 107 75 108 li => { 76 109 match => qr/(.*)\n/, # Capture the whole line 77 110 phrases => $all_phrases, 78 111 }, 112 79 113 li2 => { 80 114 type => '', … … 82 116 phrases => $all_phrases, 83 117 }, 118 84 119 hr => { 85 match => qr/^ (--+)\s*\n/,120 match => qr/^--+(?:\s*\n)?/, 86 121 }, 122 87 123 table => { 88 124 match => qr/^( … … 94 130 (?ms:^\|.*?\|\n) 95 131 )+ 96 ) /x,132 )(?:\s*\n)?/x, 97 133 blocks => ['tr'], 98 134 }, 135 99 136 tr => { 100 137 match => qr/^((?m:^\|.*?\|(?:\n| \n(?=\|)| +\n)))/s, 101 138 blocks => ['td'], 102 139 }, 140 103 141 td => { 104 142 match => qr/\|?\s*(.*?)\s*\|\n?/s, … … 106 144 }, 107 145 146 wikilink => { 147 type => 'a', 148 match => qr/ 149 (?:"([^"]*)"\s*)?(?:^|(?<=[^$ALPHANUM]))\[(?=[^\s\[\]]) 150 (.*?) 151 \](?=[^$ALPHANUM]|\z) 152 /x, 153 filter => sub { 154 my $node = shift; 155 $node->{attributes}{target} = $node->{2}; 156 $_ = $node->{1} || $node->{2}; 157 }, 158 }, 159 108 160 b => { 109 161 match => re_huggy(q{\*}), 110 162 }, 163 111 164 tt => { 112 165 match => re_huggy(q{\`}), 113 166 }, 167 114 168 i => { 115 match => re_huggy(q{\/}),169 match => WikiText::Socialtext::Parser::re_huggy(q{\_}), 116 170 }, 171 117 172 del => { 118 173 match => re_huggy(q{\-}), … … 120 175 }; 121 176 } 122 123 # Reusable regexp generators used by the grammar124 my $ALPHANUM = '\p{Letter}\p{Number}\pM';125 177 126 178 sub re_huggy { trunk/src/ingy/WikiText-Socialtext/t/parser.t
r284 r285 2 2 use t::TestWikiText; 3 3 4 plan tests => 5;4 plan tests => 11; 5 5 6 6 #no_diff; … … 14 14 15 15 __DATA__ 16 === First Test 16 === Multiline Paragraphs 17 18 --- wikitext 19 this is a multiline blob of 20 text that should be in a 21 single paragraph 22 23 but this should be alone 24 25 --- wikibyte 26 +p 27 this is a multiline blob of 28 text that should be in a 29 single paragraph 30 -p 31 +p 32 but this should be alone 33 -p 34 35 === H1 and Bold 17 36 --- wikitext 18 37 ^ Hello … … 32 51 -p 33 52 34 === Second Test53 === H4 and Bold 35 54 --- wikitext 36 55 ^^^^ Goodbye … … 73 92 |two|2| 74 93 94 Some text. 95 75 96 --- wikibyte 76 97 +table … … 102 123 -tr 103 124 -table 125 +p 126 Some text. 127 -p 104 128 105 129 === Unordered and Ordered Lists … … 139 163 -ul 140 164 165 === Italics and Indented 166 --- wikitext 167 > This is _italic_ indented text 168 > that has more indents 169 170 --- wikibyte 171 +blockquote 172 +p 173 This is 174 +i 175 italic 176 -i 177 indented text 178 that has more indents 179 -p 180 -blockquote 181 182 === Links and Named Links 183 --- wikitext 184 [Link to a page] 185 "other page"[Second link] 186 187 --- wikibyte 188 +p 189 +a target="Link to a page" 190 Link to a page 191 -a 192 193 194 +a target="Second link" 195 other page 196 -a 197 -p 198 199 === pre text 200 --- wikitext 201 .pre 202 no *bold* here 203 .pre 204 but *bold* here 205 206 --- wikibyte 207 +pre 208 no *bold* here 209 210 -pre 211 +p 212 but 213 +b 214 bold 215 -b 216 here 217 -p 218 219 === WAFL Paragraph 220 --- wikitext 221 {foo: bar} 222 223 some text 224 --- wikibyte 225 +waflparagraph function="foo" options="bar" 226 -waflparagraph 227 +p 228 some text 229 -p 230 231 === Horizonal Rule 232 --- wikitext 233 line 234 235 ---- 236 237 goes here 238 239 --- wikibyte 240 +p 241 line 242 -p 243 +hr 244 -hr 245 +p 246 goes here 247 -p 248
