File: 01-normalizer.t

package info (click to toggle)
libhtml-wikiconverter-perl 0.68-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 344 kB
  • sloc: perl: 1,186; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,430 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!perl -T

use Test::More tests => 6;
use HTML::WikiConverter::Normalizer;
use HTML::TreeBuilder;

is(
  normalize('<p><font style="font-style:italic;font-weight:bold">text</font></p>'),
            '<p><font><b><i>text</i></b></font></p>',
            'bold italic'
);

is(
  normalize('<p><span style="font-style: italic;">asdf</span><span style="font-style: italic;">asdf</span></p>'),
            '<p><span><i>asdf</i></span><span><i>asdf</i></span></p>',
            'multiple italic'
);

is(
  normalize('<span style="color:#ccc">text</span>'),
            '<span><font color="#ccc">text</font></span>',
            'font color'
);

is(
  normalize('<div align="center">text</div>'),
            '<div><center>text</center></div>',
            'center'
);

is(
  normalize('<p style="font-weight:bold">text</p>'),
            '<p><b>text</b></p>',
            'bold within para'
);

is(
  normalize('<span style="font-family: Symbol;">text</span>'),
            '<span><font face="Symbol">text</font></span>',
            'font-family'
);

sub normalize {
  my $html = shift;

  my $tree = new HTML::TreeBuilder();
  $tree->parse($html);

  my $norm = new HTML::WikiConverter::Normalizer();
  $norm->normalize($tree);

  $tree->deobjectify_text();
  chomp( my $dumped_html = $tree->as_HTML(undef, '', {}) );

  $dumped_html =~ s~^<html><head></head><body>~~;
  $dumped_html =~ s~</body></html>$~~;

  return $dumped_html;
}