MKDoc-XML
view release on metacpan or search on metacpan
lib/MKDoc/XML/Tagger/Preserve.pm view on Meta::CPAN
# -------------------------------------------------------------------------------------
# MKDoc::XML::Tagger::Preserve
# -------------------------------------------------------------------------------------
# Author : Jean-Michel Hiver.
# Copyright : (c) MKDoc Holdings Ltd, 2003
#
# This module uses MKDoc::XML::Tagger, except it preserves specific tags to prevent
# them from being tagged twice. At the moment the module uses regexes to do that so it
# might not be very generic but it should at least work for XHTML <a> tags.
# -------------------------------------------------------------------------------------
package MKDoc::XML::Tagger::Preserve;
use MKDoc::XML::Tagger;
use strict;
use warnings;
use utf8;
our @Preserve = ();
##
# $class->process_data ($xml, @expressions);
# ------------------------------------------
# Tags $xml with @expressions, where expression is a list of hashes.
#
# For example:
#
# MKDoc::XML::Tagger::Preserve->process (
# [ 'i_will_be_preserved', 'a' ],
# 'I like oranges and bananas',
# { _expr => 'oranges', _tag => 'a', href => 'http://www.google.com?q=oranges' },
# { _expr => 'bananas', _tag => 'a', href => 'http://www.google.com?q=bananas' },
#
# Will return
#
# 'I like <a href="http://www.google.com?q=oranges">oranges</a> and \
# <a href="http://www.google.com?q=bananas">bananas</a>.
##
sub process_data
{
my $class = shift;
local @Preserve = @{shift()};
my $text = shift;
my @list = ();
($text, @list) = _preserve_encode ($text);
$text = MKDoc::XML::Tagger->process_data ($text, @_);
$text = _preserve_decode ($text, @list);
return $text;
}
sub process_file
{
my $class = shift;
my $file = shift;
open FP, "<$file" || do {
warn "Cannot read-open $file";
return [];
};
my $data = '';
while (<FP>) { $data .= $_ }
close FP;
return $class->process_data ($data);
}
( run in 1.741 second using v1.01-cache-2.11-cpan-140bd7fdf52 )