Name

post_page — custom subroutine to run before image paths substitution on a page

VALUE

subroutine_name

DEFAULT

None

DESCRIPTION

This pragma defines a Sub or GlobalSub to run before image paths substitution on a page. A reference to the page contents is passed to the subroutine.

EXAMPLES

Example: Treat URLs relative to current directory

It is possible to have URL links treated as being relative to the current directory. The following is needed in catalog.cfg:

Pragma   post_page=relative_urls

### Take hrefs like <A HREF="about.html"> and make relative to current
### directory
Sub <<EOR
  sub relative_urls {
    my $page = shift;
    my @dirs = split "/", $Tag->var('MV_PAGE', 1);
    pop @dirs;
    my $basedir = join  "/", @dirs;
    $basedir ||= '';
    $basedir .= '/' if $basedir;

    my $sub = sub {
      my ($entire, $pre, $url) = @_;
      return $entire if $url =~ /^\w+:/;
      my($page, $form) = split /\?/, $url, 2;
      my $u = $Tag->area({
        href => "$basedir$page",
        form => $form,
      });
      return qq{$pre"$u"};
    };
    $$page =~ s{(
        (
        <a \s+ (?:[^>]+?\s+)?
          href \s*=\s*
        )
        (["']) ([^\s"'>]+) \3
      )}
      {
        $sub->($1,$2,$4)
      }gsiex;

    return;
  }
EOR

NOTES

The old documentation system improperly describes the phase at which the post_page pragma takes effect (it states it happens after Variable processing and before tags are interpolated).

AVAILABILITY

post_page is available in Interchange versions:

4.6.0-5.7.0 (git-head)

SOURCE

Interchange 5.7.0 (1/1 contexts shown):

Source: lib/Vend/Interpolate.pm
Line 540 (context shows lines 530-544 in substitute_image():532)

}

sub substitute_image {
my ($text) = @_;

## Allow no substitution of downloads
return if $::Pragma->{download};

## If post_page routine processor returns true, return. Otherwise,
## continue image rewrite
if($::Pragma->{post_page}) {
  Vend::Dispatch::run_macro($::Pragma->{post_page}, $text)
    and return;
}


AUTHORS

Interchange Development Group

SEE ALSO

init_page(7ic), pre_page(7ic)

DocBook! Interchange!