App-optex-textconv

 view release on metacpan or  search on metacpan

lib/App/optex/textconv/ooxml/regex.pm  view on Meta::CPAN


sub _xml2text {
    local $_ = shift;
    my $type = shift;
    my $param = $param{$type} or die;

    my @p;
    my $fn_id = "";
    while (m{
	     (?<footnote> <w:footnote \s+ w:id="(?<fn_id>\d+)" )
	   | <(?<tag>[apw]:p|si)\b[^>]*>(?<para>.*?)</\g{tag}>
	   }xsg)
    {
	if ($+{footnote}) {
	    $fn_id = $+{fn_id};
	    next;
	}
	my $para = $+{para};
	my @s;
	while ($para =~ m{
	         (?<fn_ref> <w:footnoteReference \s+ w:id="(?<fn_id>\d+)" )
	       | (?<footnote> <w:footnote \s+ w:id="(?<fn_id>\d+)" )
	       | (?<footnoteRef> <w:footnoteRef/> )
	       | (?<br> <[aw]:br/> )
	       | (?<tab> <w:tab/> | <w:tabs> )
	       | <(?<tag>(?:[apw]:)?t)\b[^>]*> (?<text>[^<]*?) </\g{tag}>
	       }xsg)
	{
	    if    ($+{fn_ref})      { push @s, "[^$+{fn_id}]" }
	    elsif ($+{footnote})    { $fn_id = $+{fn_id} }
	    elsif ($+{footnoteRef}) { push @s, "[^$fn_id]:" }
	    elsif ($+{br})          { push @s, "\n" }
	    elsif ($+{tab})         { push @s, "  " }
	    elsif ($+{text} ne '')  { push @s, $+{text} }
	}
	@s or next;



( run in 0.267 second using v1.01-cache-2.11-cpan-87723dcf8b7 )