Changeset 5810 for trunk/core/lib/Foswiki/Render.pm
- Timestamp:
- 12/17/09 19:28:55 (2 years ago)
- File:
-
- 1 edited
-
trunk/core/lib/Foswiki/Render.pm (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/lib/Foswiki/Render.pm
r5792 r5810 340 340 # calc COLSPAN 341 341 $row =~ s/(\|\|+)/ 342 'colspan'.$ Foswiki::TranslationToken.length($1).'|'/ge;342 'colspan'.$REMARKER.length($1).'|'/ge; 343 343 my $cells = ''; 344 344 my $containsTableHeader; … … 348 348 349 349 # Avoid matching single columns 350 if (s/colspan$ Foswiki::TranslationToken([0-9]+)//o) {350 if (s/colspan$REMARKER([0-9]+)//o) { 351 351 push( @attr, colspan => $1 ); 352 352 } … … 566 566 567 567 sub internalLink { 568 my ( $this, $web, $topic, $linkText, $anchor, $linkIfAbsent, $keepWebPrefix,569 $hasExplicitLinkLabel)568 my ( $this, $web, $topic, $linkText, $anchor, 569 $linkIfAbsent, $keepWebPrefix, $hasExplicitLinkLabel, $params ) 570 570 = @_; 571 571 … … 612 612 $linkText =~ s/(?<=[\s\(])([$Foswiki::regex{upperAlpha}])/<nop>$1/go; 613 613 return _renderWikiWord( $this, $web, $topic, $linkText, $anchor, 614 $linkIfAbsent, $keepWebPrefix );614 $linkIfAbsent, $keepWebPrefix, $params ); 615 615 } 616 616 … … 618 618 sub _renderWikiWord { 619 619 my ( $this, $web, $topic, $linkText, $anchor, $linkIfAbsent, 620 $keepWebPrefix ) = @_;620 $keepWebPrefix, $params ) = @_; 621 621 my $session = $this->{session}; 622 622 my $topicExists = $session->topicExists( $web, $topic ); … … 641 641 642 642 return _renderExistingWikiWord( $this, $web, $topic, $linkText, 643 $anchor );643 $anchor, $params ); 644 644 } 645 645 if ($linkIfAbsent) { … … 652 652 # add a dependency so that the page gets invalidated as soon as the 653 653 # WikiWord comes into existance 654 # Note we *ignore* the params if the target topic does not exist 654 655 $this->{session}->{cache}->addDependency($web, $topic) 655 656 if $Foswiki::cfg{Cache}{Enabled}; … … 665 666 666 667 sub _renderExistingWikiWord { 667 my ( $this, $web, $topic, $text, $anchor ) = @_;668 my ( $this, $web, $topic, $text, $anchor, $params ) = @_; 668 669 669 670 my @cssClasses; … … 678 679 my @attrs; 679 680 my $href = $this->{session}->getScriptUrl( 0, 'view', $web, $topic ); 681 if ($params) { 682 $href .= $params; 683 } 684 680 685 if ($anchor) { 681 686 $anchor = $this->_makeAnchorName($anchor); … … 778 783 $link =~ s/\s+$//; 779 784 780 my $hasExplicitLinkLabel = $text ? 1 : undef;781 782 # Explicit external [[ $link][$text]]-style can be handled directly785 my $hasExplicitLinkLabel = $text ? 1 : 0; 786 787 # Explicit external [[http://$link][$text]]-style can be handled directly 783 788 if ( $link =~ m!^($Foswiki::regex{linkProtocolPattern}\:|/)! ) { 784 789 if ( defined $text ) { … … 808 813 $text ||= $link; 809 814 815 # Extract '?params' 816 # $link =~ s/(\?.*?)(?>#|$)//; 817 my $params = ''; 818 if ( $link =~ s/(\?.*$)// ) { 819 $params = $1; 820 my $p = quotemeta($params); 821 $text =~ s/$p//; 822 } 823 810 824 # Extract '#anchor' 811 825 # $link =~ s/(\#[a-zA-Z_0-9\-]*$)//; … … 813 827 if ( $link =~ s/($Foswiki::regex{anchorRegex}$)// ) { 814 828 $anchor = $1; 829 #$text =~ s/#$anchor//; 815 830 } 816 831 … … 845 860 $this->{session}->normalizeWebTopicName( $topicObject->web, $link ); 846 861 return $this->internalLink( $web, $topic, $text, $anchor, 1, undef, 847 $hasExplicitLinkLabel );862 $hasExplicitLinkLabel, $params ); 848 863 } 849 864 … … 1010 1025 1011 1026 # verbatim before literal - see Item3431 1012 $text = $this->takeOutBlocks( $text, 'verbatim', $removed );1013 $text = $this->takeOutBlocks( $text, 'literal', $removed );1014 $text = $this->takeOutBlocks( $text, 'dirtyarea', $removed )1027 $text = Foswiki::takeOutBlocks( $text, 'verbatim', $removed ); 1028 $text = Foswiki::takeOutBlocks( $text, 'literal', $removed ); 1029 $text = Foswiki::takeOutBlocks( $text, 'dirtyarea', $removed ) 1015 1030 if $Foswiki::cfg{Cache}{Enabled}; 1016 1031 … … 1042 1057 $topicObject->topic ); 1043 1058 1044 $text = $this->takeOutBlocks( $text, 'pre', $removed );1059 $text = Foswiki::takeOutBlocks( $text, 'pre', $removed ); 1045 1060 1046 1061 # Join lines ending in '\' (don't need \r?, it was removed already) … … 1100 1115 # locate isolated < and > and translate to entities 1101 1116 # Protect isolated <!-- and --> 1102 $text =~ s/<!--/{$ Foswiki::TranslationToken!--/g;1103 $text =~ s/-->/--}$ Foswiki::TranslationToken/g;1117 $text =~ s/<!--/{$REMARKER!--/g; 1118 $text =~ s/-->/--}$REMARKER/g; 1104 1119 1105 1120 # SMELL: this next fragment does not handle the case where HTML tags … … 1108 1123 # they have been escaped. 1109 1124 $text =~ 1110 s/<(\/?\w+(:\w+)?)>/{$ Foswiki::TranslationToken$1}$Foswiki::TranslationToken/g;1125 s/<(\/?\w+(:\w+)?)>/{$REMARKER$1}$REMARKER/g; 1111 1126 $text =~ 1112 s/<(\w+(:\w+)?(\s+.*?|\/)?)>/{$ Foswiki::TranslationToken$1}$Foswiki::TranslationToken/g;1127 s/<(\w+(:\w+)?(\s+.*?|\/)?)>/{$REMARKER$1}$REMARKER/g; 1113 1128 1114 1129 # XML processing instruction only valid at start of text 1115 1130 $text =~ 1116 s/^<(\?\w.*?\?)>/{$ Foswiki::TranslationToken$1}$Foswiki::TranslationToken/g;1131 s/^<(\?\w.*?\?)>/{$REMARKER$1}$REMARKER/g; 1117 1132 1118 1133 # entitify lone < and >, praying that we haven't screwed up :-( … … 1120 1135 $text =~ s/<(?!\!\[CDATA\[)/<\;/g; 1121 1136 $text =~ s/(?<!\]\])>/>\;/g; 1122 $text =~ s/{$ Foswiki::TranslationToken/</go;1123 $text =~ s/}$ Foswiki::TranslationToken/>/go;1137 $text =~ s/{$REMARKER/</go; 1138 $text =~ s/}$REMARKER/>/go; 1124 1139 1125 1140 # standard URI - don't modify if url(http://as) form … … 1128 1143 1129 1144 # other entities 1130 $text =~ s/&(\w+);/$ Foswiki::TranslationToken$1;/g; # "&abc;"1131 $text =~ s/&(#x?[0-9a-f]+);/$ Foswiki::TranslationToken$1;/gi; # "{"1145 $text =~ s/&(\w+);/$REMARKER$1;/g; # "&abc;" 1146 $text =~ s/&(#x?[0-9a-f]+);/$REMARKER$1;/gi; # "{" 1132 1147 $text =~ s/&/&/g; # escape standalone "&" 1133 $text =~ s/$ Foswiki::TranslationToken(#x?[0-9a-f]+;)/&$1/goi;1134 $text =~ s/$ Foswiki::TranslationToken(\w+;)/&$1/go;1148 $text =~ s/$REMARKER(#x?[0-9a-f]+;)/&$1/goi; 1149 $text =~ s/$REMARKER(\w+;)/&$1/go; 1135 1150 1136 1151 # clear the set of unique anchornames in order to inhibit … … 1296 1311 1297 1312 # Handle WikiWords 1298 $text = $this->takeOutBlocks( $text, 'noautolink', $removed );1313 $text = Foswiki::takeOutBlocks( $text, 'noautolink', $removed ); 1299 1314 $text =~ 1300 1315 s/$STARTWW(?:($Foswiki::regex{webNameRegex})\.)?($Foswiki::regex{wikiWordRegex}|$Foswiki::regex{abbrevRegex})($Foswiki::regex{anchorRegex})?/_handleWikiWord( $this, $topicObject, $1, $2, $3)/geom; 1301 $this->putBackBlocks( \$text, $removed, 'noautolink' );1302 } 1303 1304 $this->putBackBlocks( \$text, $removed, 'pre' );1316 Foswiki::putBackBlocks( \$text, $removed, 'noautolink' ); 1317 } 1318 1319 Foswiki::putBackBlocks( \$text, $removed, 'pre' ); 1305 1320 1306 1321 # DEPRECATED plugins hook after PRE re-inserted … … 1308 1323 1309 1324 # replace verbatim with pre in the final output 1310 $this->putBackBlocks( \$text, $removed, 'verbatim', 'pre',1325 Foswiki::putBackBlocks( \$text, $removed, 'verbatim', 'pre', 1311 1326 \&verbatimCallBack ); 1312 1327 $text =~ s|\n?<nop>\n$||o; # clean up clutch 1313 1328 1314 1329 $this->_putBackProtected( \$text, 'script', $removed, \&_filterScript ); 1315 $this->putBackBlocks( \$text, $removed, 'literal', '', \&_filterLiteral );1330 Foswiki::putBackBlocks( \$text, $removed, 'literal', '', \&_filterLiteral ); 1316 1331 $this->_putBackProtected( \$text, 'literal', $removed ); 1317 $this->putBackBlocks( \$text, $removed, 'dirtyarea' )1332 Foswiki::putBackBlocks( \$text, $removed, 'dirtyarea' ) 1318 1333 if $Foswiki::cfg{Cache}{Enabled}; 1319 1334 $this->_putBackProtected( \$text, 'comment', $removed ); … … 1526 1541 return 1527 1542 '<!--' 1528 . $ Foswiki::TranslationToken1543 . $REMARKER 1529 1544 . $id 1530 1545 . $placeholder 1531 . $ Foswiki::TranslationToken. '-->';1546 . $REMARKER . '-->'; 1532 1547 } 1533 1548 … … 1549 1564 $val = &$callback($val) if ( defined($callback) ); 1550 1565 $$text =~ 1551 s/<!--$ Foswiki::TranslationToken$placeholder$Foswiki::TranslationToken-->/$val/;1566 s/<!--$REMARKER$placeholder$REMARKER-->/$val/; 1552 1567 delete( $map->{$placeholder} ); 1553 }1554 }1555 1556 =begin TML1557 1558 ---++ ObjectMethod takeOutBlocks( \$text, $tag, \%map ) -> $text1559 1560 * =$text= - Text to process1561 * =$tag= - XHTML-style tag.1562 * =\%map= - Reference to a hash to contain the removed blocks1563 1564 Return value: $text with blocks removed1565 1566 Searches through $text and extracts blocks delimited by a tag, appending each1567 onto the end of the @buffer and replacing with a token1568 string which is not affected by TML rendering. The text after these1569 substitutions is returned.1570 1571 Parameters to the open tag are recorded.1572 1573 This is _different_ to takeOutProtected, because it requires tags1574 to be on their own line. it also supports a callback for post-1575 processing the data before re-insertion.1576 1577 =cut1578 1579 sub takeOutBlocks {1580 my ( $this, $intext, $tag, $map ) = @_;1581 1582 return $intext unless ( $intext =~ m/<$tag\b/i );1583 1584 my $out = '';1585 my $depth = 0;1586 my $scoop;1587 my $tagParams;1588 1589 foreach my $token ( split /(<\/?$tag[^>]*>)/i, $intext ) {1590 if ( $token =~ /<$tag\b([^>]*)?>/i ) {1591 $depth++;1592 if ( $depth eq 1 ) {1593 $tagParams = $1;1594 next;1595 }1596 }1597 elsif ( $token =~ /<\/$tag>/i ) {1598 if ( $depth > 0 ) {1599 $depth--;1600 if ( $depth eq 0 ) {1601 my $placeholder = $tag . $placeholderMarker;1602 $placeholderMarker++;1603 $map->{$placeholder}{text} = $scoop;1604 $map->{$placeholder}{params} = $tagParams;1605 $out .= '<!--'1606 . $Foswiki::TranslationToken1607 . $placeholder1608 . $Foswiki::TranslationToken . '-->';1609 $scoop = '';1610 next;1611 }1612 }1613 }1614 if ( $depth > 0 ) {1615 $scoop .= $token;1616 }1617 else {1618 $out .= $token;1619 }1620 }1621 1622 # unmatched tags1623 if ( defined($scoop) && ( $scoop ne '' ) ) {1624 my $placeholder = $tag . $placeholderMarker;1625 $placeholderMarker++;1626 $map->{$placeholder}{text} = $scoop;1627 $map->{$placeholder}{params} = $tagParams;1628 $out .= '<!--'1629 . $Foswiki::TranslationToken1630 . $placeholder1631 . $Foswiki::TranslationToken . '-->';1632 }1633 1634 return $out;1635 }1636 1637 =begin TML1638 1639 ---++ ObjectMethod putBackBlocks( \$text, \%map, $tag, $newtag, $callBack ) -> $text1640 1641 Return value: $text with blocks added back1642 * =\$text= - reference to text to process1643 * =\%map= - map placeholders to blocks removed by takeOutBlocks1644 * =$tag= - Tag name processed by takeOutBlocks1645 * =$newtag= - Tag name to use in output, in place of $tag. If undefined, uses $tag.1646 * =$callback= - Reference to function to call on each block being inserted (optional)1647 1648 Reverses the actions of takeOutBlocks.1649 1650 Each replaced block is processed by the callback (if there is one) before1651 re-insertion.1652 1653 Parameters to the outermost cut block are replaced into the open tag,1654 even if that tag is changed. This allows things like1655 <verbatim class=''>1656 to be mapped to1657 <pre class=''>1658 1659 Cool, eh what? Jolly good show.1660 1661 And if you set $newtag to '', we replace the taken out block with the value itself1662 * which i'm using to stop the rendering process, but then at the end put in the html directly1663 (for <literal> tag.1664 1665 =cut1666 1667 sub putBackBlocks {1668 my ( $this, $text, $map, $tag, $newtag, $callback ) = @_;1669 1670 $newtag = $tag if ( !defined($newtag) );1671 1672 foreach my $placeholder ( keys %$map ) {1673 if ( $placeholder =~ /^$tag\d+$/ ) {1674 my $params = $map->{$placeholder}{params} || '';1675 my $val = $map->{$placeholder}{text};1676 $val = &$callback($val) if ( defined($callback) );1677 if ( $newtag eq '' ) {1678 $$text =~1679 s(<!--$Foswiki::TranslationToken$placeholder$Foswiki::TranslationToken-->)($val);1680 }1681 else {1682 $$text =~1683 s(<!--$Foswiki::TranslationToken$placeholder$Foswiki::TranslationToken-->)1684 (<$newtag$params>$val</$newtag>);1685 }1686 delete( $map->{$placeholder} );1687 }1688 1568 } 1689 1569 } … … 2097 1977 # throw away <verbatim> and <pre> blocks 2098 1978 my %junk; 2099 $text = $this->takeOutBlocks( $text, 'verbatim', \%junk );2100 $text = $this->takeOutBlocks( $text, 'pre', \%junk );1979 $text = Foswiki::takeOutBlocks( $text, 'verbatim', \%junk ); 1980 $text = Foswiki::takeOutBlocks( $text, 'pre', \%junk ); 2101 1981 2102 1982 my $maxDepth = $params->{depth}; … … 2116 1996 my $result = ''; 2117 1997 my $verbatim = {}; 2118 $text = $this->takeOutBlocks( $text, 'verbatim', $verbatim );2119 $text = $this->takeOutBlocks( $text, 'pre', $verbatim );1998 $text = Foswiki::takeOutBlocks( $text, 'verbatim', $verbatim ); 1999 $text = Foswiki::takeOutBlocks( $text, 'pre', $verbatim ); 2120 2000 2121 2001 # Find URL parameters
Note: See TracChangeset
for help on using the changeset viewer.
