Index: Render.pm =================================================================== --- Render.pm (revision 1617) +++ Render.pm (working copy) @@ -777,6 +777,35 @@ =pod +---++ sub getFirstHeading( $web, $topic ) + ++Returns the first heading (any level) found in the given topic. The topic read is +treated as internal, and therefore access restrictions are _not_ respected. If +the topic is not found, returns the wikiname of the topic. + +=cut + +sub getFirstHeading { + my ( $web, $topic ) = @_; + + my ( $meta, $text ) = TWiki::Store::readTopic( $web, $topic, 1 ); + + if ( $text =~ m/$regex{headerPatternHt}/mo ) { + # '
...
' HTML rule + return $2; + } elsif ( $text =~ m/$regex{headerPatternSp}/mo ) { + # '\t+++++++' rule + return $2; + } elsif ( $text =~ m/$regex{headerPatternDa}/mo ) { + # '----+++++++' rule + return $2; + } else { + return $topic; + } +} + +=pod + ---++ sub getFormField ( $web, $topic, $args ) +Returns the expansion of a %FORMFIELD{}% tag. @@ -1062,6 +1091,9 @@ # do normal WikiWord link if not disabled by or NOAUTOLINK preferences variable unless( $noAutoLink || $insideNoAutoLink ) { + # {{Web.Topic}} or {{Topic}} link (first heading) + s/([\s\(])\{\{(($regex{webNameRegex})\.)?($regex{wikiWordRegex})\}\}/&internalLink($1,$3||$theWeb,$4,getFirstHeading($3||$theWeb,$4),"",1)/geo; + # 'Web.TopicName#anchor' link: s/([\s\(])($regex{webNameRegex})\.($regex{wikiWordRegex})($regex{anchorRegex})/&internalLink($1,$2,$3,"$TranslationToken$3$4$TranslationToken",$4,1)/geo; # 'Web.TopicName' link: