Skip to content
Browse files

[p6w] restored ugly MediaWiki.pm code to its pristine state. pmichaud++

only one extra line remains as a compromise before HLL mapping works
  • Loading branch information...
1 parent 3343adf commit 4fcfb53cfd95b50dd71f5b27d9a50f4cfeb298ec @masak masak committed Nov 15, 2008
Showing with 14 additions and 50 deletions.
  1. +14 −50 p6w/Text/Markup/Wiki/MediaWiki.pm
View
64 p6w/Text/Markup/Wiki/MediaWiki.pm
@@ -2,61 +2,25 @@ use v6;
class Text::Markup::Wiki::MediaWiki {
- sub entities($words) {
- return map { "&$_;" }, $words;
+ sub entities(*@words) {
+ return map { "&$_;" }, @words.values;
}
method format($text, :$link_maker) {
my @result_pars;
- my @split;
- my $text_copy = $text;
- while $text_copy.index("\n\n") -> $ix {
- push @split, $text_copy.substr(0, $ix);
- $text_copy .= substr($ix);
- while $text_copy.substr(0,1) eq "\n" {
- $text_copy .= substr(1);
- }
- }
- if $text_copy {
- push @split, $text_copy;
- }
-
- # RAKUDO: Awaiting HLL type conversion
- #for split(/\n ** 2..*/, $text) -> $paragraph {
- for @split -> $paragraph {
- #my $cleaned_of_whitespace = $paragraph.trans(
- # [ /\s+/ => ' ' ]
- #);
- my @cleaned_pars;
-
- my $paragraph_copy = $paragraph;
- while $paragraph_copy ~~ /\s/ {
- push @cleaned_pars, $paragraph_copy.substr(0, $/.from);
- $paragraph_copy .= substr($/.from);
- while $paragraph_copy ~~ /^\s/ {
- $paragraph_copy .= substr(1);
- }
- }
- if $paragraph_copy {
- push @cleaned_pars, $paragraph_copy;
- }
-
- my $cleaned_of_whitespace = join ' ', @cleaned_pars;
- #my $xml_escaped = $cleaned_of_whitespace.trans(
- # [ '<', '>', '&', '\'' ] =>
- # [ entities < lt gt amp #039> ]
- #);
- my %conversions =
- ( '<' => 'lt', '>' => 'gt', '&' => 'amp', '\'' => '#039' );
-
- my @xml_escaped_new;
- for split '', $cleaned_of_whitespace -> $c {
- push @xml_escaped_new, %conversions.exists( $c )
- ?? entities %conversions{$c}
- !! $c;
- }
- my $xml_escaped = join '', @xml_escaped_new;
+ for split(/\n ** 2..*/, $text) -> $paragraph {
+ # RAKUDO: Needed right now due to HLL non-mapping.
+ $paragraph = $paragraph;
+ my $cleaned_of_whitespace = $paragraph.trans(
+ [ /\s+/ => ' ' ]
+ );
+
+ my $xml_escaped = $cleaned_of_whitespace.trans(
+ [ '<', '>', '&', '\'' ] =>
+ [ entities < lt gt amp #039> ]
+ );
+ #my $xml_escaped = $cleaned_of_whitespace;
push @result_pars, "<p>$xml_escaped</p>";
}

0 comments on commit 4fcfb53

Please sign in to comment.
Something went wrong with that request. Please try again.