#!/usr/bin/perl use warnings; use strict; my $html = <<'EOHTML';
The relationship can be expressed by the following equation:
y <= (7x3 + 3x2)/((x - 3)(x - 5)
Of course x != 3 & x != 5 -- That goes without saying.
EOHTML
use HTML::TreeBuilder;
my $tree = HTML::TreeBuilder->new_from_content($html);
# Look for double-dashes in the text,
# and change them to —es.
$tree->look_down(sub {
my $element = shift;
my @content = $element->content_list();
@content = map {
if(ref) {
$_ # Skip non-text children
} else {
# Break up the text child into pieces on the --'s
my @texts = split /(--)/, $_;
# Replaces those --'s with a ~literal
# pseudo-element containing an —
@texts = map {
$_ eq '--'
? HTML::Element->new('~literal', text => '—')
: $_
} @texts;
@texts;
}
} @content;
# Replace the old content with the modified content
$element->splice_content(0, scalar $element->content_list, @content);
return 0;
});
print $tree->as_HTML;
## The relationship can be expressed by the following equation: Of course x != 3 & x != 5 — That goes without saying.
##
y <= (7x3 + 3x2)/((x - 3)(x - 5)