Skip Menu |
 

This queue is for tickets about the HTML-Toc CPAN distribution.

Report information
The Basics
Id: 43797
Status: open
Priority: 0/
Queue: HTML-Toc

People
Owner: Nobody in particular
Requestors: ddascalescu+perl [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.10
Fixed in: (no value)



Subject: insertionPoint replaces too much text; documentation is a tad misleading
Download (untitled) / with headers
text/plain 633b
Two issues: 1. An insertionPoint of "replace just_the_toc_placeholder" will replace all text around just_the_toc_placeholder, up to surrounding HTML elements. While normally there is no bare text around the ToC placeholder, this is somewhat of a problem because it the replacing includes whitespace surrounding just_the_toc_placeholder. 2. The documentation reads "syntax: [<before|after|replace>] <token>". The square brackets may imply that "before", "after" and "replace" are optional. In fact, specifying one of them is mandatory. A better phrasing may be: syntax: "before" | "after" | "replace" <token> Test case attached.
Subject: insertionPoint.t
Download insertionPoint.t
text/x-perl 3.1k
#!/usr/bin/perl -w use strict; use HTML::Toc; use HTML::TocInsertor; use Test::More tests => 3; use Test::Differences; my $toc = HTML::Toc->new(); my $tocInsertor = HTML::TocInsertor->new(); my $output; # ------------------------------------------------------------------------ # --- insertionPoint should preserve text around the Toc placeholder # ------------------------------------------------------------------------ my $content = <<HTML; <p>this text is in a p tag and is preserved</p> but this text should be preserved as well {{toc}} so should this text <h1>Chapter 1</h1> Some text here <h1>Chapter 2</h1> Second chapter HTML # http://search.cpan.org/dist/HTML-Toc/Toc.pod#HTML::TocInsertor::insert() $toc->setOptions({ insertionPoint => 'replace {{toc}}', doLinkToId => 0, }); $tocInsertor->insert($toc, $content, {output => \$output}); eq_or_diff($output, <<'EOT', 'insertionPoint should preserve text around ToC placeholder'); <p>this text is in a p tag and is preserved</p> but this text should be preserved as well <!-- Table of Contents generated by Perl - HTML::Toc --> <ul> <li><a href="#h-1">Chapter 1</a></li> <li><a href="#h-2">Chapter 2</a></li> </ul> <!-- End of generated Table of Contents --> so should this text <h1><a name="h-1"></a>Chapter 1</h1> Some text here <h1><a name="h-2"></a>Chapter 2</h1> Second chapter EOT # ------------------------------------------------------------------------ # --- insertionPoint should preserve text around the Toc placeholder # ------------------------------------------------------------------------ $content = <<HTML; <p>this text is in a p tag and is preserved</p> but this text should be preserved as well ToC will be placed here so should this text <h1>Chapter 1</h1> Some text here <h1>Chapter 2</h1> Second chapter HTML # http://search.cpan.org/dist/HTML-Toc/Toc.pod#HTML::TocInsertor::insert() $toc->setOptions({ insertionPoint => 'replace ToC will be placed here', doLinkToId => 0, }); $tocInsertor->insert($toc, $content, {output => \$output}); eq_or_diff($output, <<'EOT', '"syntax: [<before|after|replace>] <token>" implies that "before", "after" and "replace" are optional. In fact, they are not.'); <p>this text is in a p tag and is preserved</p> but this text should be preserved as well <!-- Table of Contents generated by Perl - HTML::Toc --> <ul> <li><a href="#h-1">Chapter 1</a></li> <li><a href="#h-2">Chapter 2</a></li> </ul> <!-- End of generated Table of Contents --> so should this text <h1><a name="h-1"></a>Chapter 1</h1> Some text here <h1><a name="h-2"></a>Chapter 2</h1> Second chapter EOT # --------------------------------------------------------------------------- # --- insertionPoint without a "before", "after" or "replace" should not work # --------------------------------------------------------------------------- $toc->setOptions({ insertionPoint => 'ToC will be placed here', doLinkToId => 0, }); $tocInsertor->insert($toc, $content, {output => \$output}); eq_or_diff($output, $content, '"syntax: [<before|after|replace>] <token>" implies that "before", "after" and "replace" are optional. In fact, one of them is mandatory.');
RT-Send-CC: fvulto [...] gmail.com
Download (untitled) / with headers
text/plain 450b
Show quoted text
> 2. The documentation reads "syntax: [<before|after|replace>] <token>". > The square brackets may imply that "before", "after" and "replace" are > optional. In fact, specifying one of them is mandatory. A better > phrasing may be: > > syntax: "before" | "after" | "replace" <token>
Should also be added that not specifying one of "before", "after", or "replace", even if a token is specified, defaults to "after <body>", regardless of the token.
New test attached. Definitely needs a documentation update.
Download insertionPoint.t
text/x-perl 2.9k
#!/usr/bin/perl -w # HTML::TocInsertor tests # http://search.cpan.org/dist/HTML-Toc/Toc.pod#HTML::TocInsertor::insert() use strict; use HTML::Toc; use HTML::TocInsertor; use Test::More tests => 3; use Test::Differences; my $toc = HTML::Toc->new(); my $tocInsertor = HTML::TocInsertor->new(); my $output; # ------------------------------------------------------------------------ # --- insertionPoint not found # ------------------------------------------------------------------------ my $content = <<HTML; <p>this text is in a p tag and is preserved</p> but this text should be preserved as well ToC will be placed here so should this text <h1>Chapter 1</h1> Some text here <h1>Chapter 2</h1> Second chapter HTML $toc->setOptions({ insertionPoint => 'this_text_is_not_found', }); $tocInsertor->insert($toc, $content, {output => \$output}); eq_or_diff($output, <<'HTML', 'insertionPoint not found; create the anchor names only'); <p>this text is in a p tag and is preserved</p> but this text should be preserved as well ToC will be placed here so should this text <h1><a name="h-1"></a>Chapter 1</h1> Some text here <h1><a name="h-2"></a>Chapter 2</h1> Second chapter HTML # ------------------------------------------------------------------------ # --- insertionPoint matches unexpectedly; default placement is 'after' # ------------------------------------------------------------------------ $toc->setOptions({ insertionPoint => 'r 2', }); $tocInsertor->insert($toc, $content, {output => \$output}); eq_or_diff($output, <<'HTML', 'insertionPoint matches unexpectedly', {max_width => 120}); <p>this text is in a p tag and is preserved</p> but this text should be preserved as well ToC will be placed here so should this text <h1><a name="h-1"></a>Chapter 1</h1> Some text here <!-- Table of Contents generated by Perl - HTML::Toc --> <ul> <li><a href="#h-1">Chapter 1</a></li> <li><a href="#h-2">Chapter 2</a></li> </ul> <!-- End of generated Table of Contents --> <h1><a name="h-2"></a>Chapter 2</h1> Second chapter HTML # ------------------------------------------------------------------------ # --- insert should preserve the text around the ToC placeholder token # --- (replicates TestReplaceText() in insert.t # ------------------------------------------------------------------------ $toc->setOptions({ insertionPoint => 'replace ToC will be placed here', }); $tocInsertor->insert($toc, $content, {output => \$output}); eq_or_diff($output, <<'EOT', 'insert should preserve the text around the ToC placeholder token'); <p>this text is in a p tag and is preserved</p> but this text should be preserved as well <!-- Table of Contents generated by Perl - HTML::Toc --> <ul> <li><a href="#h-1">Chapter 1</a></li> <li><a href="#h-2">Chapter 2</a></li> </ul> <!-- End of generated Table of Contents --> so should this text <h1><a name="h-1"></a>Chapter 1</h1> Some text here <h1><a name="h-2"></a>Chapter 2</h1> Second chapter EOT


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.