Skip to content

Commit

Permalink
Item11317: support for incrementing heading levels in included content
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@14201 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Mar 4, 2012
1 parent 8bf069e commit 31b76b1
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 73 deletions.
89 changes: 87 additions & 2 deletions UnitTestContrib/test/unit/Fn_INCLUDE.pm
Expand Up @@ -190,10 +190,10 @@ sub test_singlequoted_params {

$text =
$this->{test_topicObject}
->expandMacros('%INCLUDE{"I can\'t beleive its not butter"}%');
->expandMacros('%INCLUDE{"I can\'t believe its not butter"}%');
$this->assert_str_equals(
"<span class='foswikiAlert'>
Warning: Can't INCLUDE '<nop>I can't beleive its not butter', path is empty or contains illegal characters.
Warning: Can't INCLUDE '<nop>I can't believe its not butter', path is empty or contains illegal characters.
</span>", $text
);
}
Expand Down Expand Up @@ -320,4 +320,89 @@ EXPECTED
$this->assert_str_equals( $expected, $text );
}

sub test_hassleFreeHoff {
my $this = shift;

# Create topic to include
my $includedTopic = "TopicToInclude";
my ($inkyDink) =
Foswiki::Func::readTopic( $this->{test_web}, $includedTopic );
$inkyDink->text( <<INCLUDE);
---+ H1
---++ H2
---+++ H3
---++++ H4
---+++++ H5
---++++++ H6
<h6>H6</H6>
<H5>H5</h5>
<H4>H4</H4>
<h3>H3</h3>
<h2 style="color:orange">H2</h2>
<h1>H1</h1>
<ho off="1">
---+ H1
<ho off="-1">
---+ H1
INCLUDE
$inkyDink->save();

my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
my $text = $topicObject->expandMacros(<<EXPAND);
%INCLUDE{"$includedTopic" headingoffset="1"}%
%INCLUDE{"$includedTopic" headingoffset="+1"}%
%INCLUDE{"$includedTopic" headingoffset="-1"}%
EXPAND
$text = $topicObject->renderTML($text);
$text =~ s/<nop>//g;
my $expect = <<EXPECT;
<h2 id="H1_AN3"> H1 </h2>
<h3 id="H2"> H2 </h3>
<h4 id="H3_AN3"> H3 </h4>
<h5 id="H4_AN3"> H4 </h5>
<h6 id="H5_AN3"> H5 </h6>
<h6 id="H6_AN3"> H6 </h6>
<h6 id="H6"> H6 </h6>
<h6 id="H5"> H5 </h6>
<h5 id="H4"> H4 </h5>
<h4 id="H3"> H3 </h4>
<h3 style="color:orange">H2</h3>
<h2 id="H1"> H1 </h2>
<h3 id="H1_AN4"> H1 </h3>
<h2 id="H1_AN5"> H1 </h2>
<h2 id="H1_AN6"> H1 </h2>
<h3 id="H2_AN1"> H2 </h3>
<h4 id="H3_AN4"> H3 </h4>
<h5 id="H4_AN4"> H4 </h5>
<h6 id="H5_AN4"> H5 </h6>
<h6 id="H6_AN4"> H6 </h6>
<h6 id="H6_AN1"> H6 </h6>
<h6 id="H5_AN1"> H5 </h6>
<h5 id="H4_AN1"> H4 </h5>
<h4 id="H3_AN1"> H3 </h4>
<h3 style="color:orange">H2</h3>
<h2 id="H1_AN1"> H1 </h2>
<h3 id="H1_AN7"> H1 </h3>
<h2 id="H1_AN8"> H1 </h2>
<h1 id="H1_AN9"> H1 </h1>
<h1 id="H2_AN2"> H2 </h1>
<h2 id="H3_AN5"> H3 </h2>
<h3 id="H4_AN5"> H4 </h3>
<h4 id="H5_AN5"> H5 </h4>
<h5 id="H6_AN5"> H6 </h5>
<h5 id="H6_AN2"> H6 </h5>
<h4 id="H5_AN2"> H5 </h4>
<h3 id="H4_AN2"> H4 </h3>
<h2 id="H3_AN2"> H3 </h2>
<h1 style="color:orange">H2</h1>
<h1 id="H1_AN2"> H1 </h1>
<h1 id="H1_AN10"> H1 </h1>
<h1 id="H1_AN11"> H1 </h1>
EXPECT
$this->assert_html_equals( $expect, $text );
}

1;
54 changes: 54 additions & 0 deletions UnitTestContrib/test/unit/Fn_SEARCH.pm
Expand Up @@ -785,6 +785,60 @@ EXPECT
return;
}

sub test_headingoffset {
my ( $this, $query, $web ) = @_;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'TestHINC' );
$topicObject->text(<<HERE);
---+ H4
<ho off="1">
---+ H5
<h1>H2</h1>
<ho off="+2">
---+ H6
<h1>H6</h1>
<ho off="-3">
---+ H4
HERE
$topicObject->save();
$topicObject->finish();
my $result = $this->{test_topicObject}->expandMacros(<<HERE);
%SEARCH{"---+" web="$this->{test_web}" topic="TestHINC" format="\$text" headingoffset="3"}%
###
%SEARCH{"---+" multiple="on" web="$this->{test_web}" topic="TestHINC" format="\$text" headingoffset="3"}%
HERE

$this->assert_str_equals(<<EXPECT, $result);
<div class="foswikiSearchResultsHeader"><span>Searched: <b><noautolink>---+</noautolink></b></span><span id="foswikiNumberOfResultsContainer"></span></div>
<ho off="3">
---+ H4
<ho off="1">
---+ H5
<h1>H2</h1>
<ho off="+2">
---+ H6
<h1>H6</h1>
<ho off="-3">
---+ H4
<ho off="-3"/>
<div class="foswikiSearchResultCount">Number of topics: <span>1</span></div>
###
<div class="foswikiSearchResultsHeader"><span>Searched: <b><noautolink>---+</noautolink></b></span><span id="foswikiNumberOfResultsContainer"></span></div>
---+ H4
<ho off="1">
---+ H5
<h1>H2</h1>
<ho off="+2">
---+ H6
<h1>H6</h1>
<ho off="-3">
---+ H4
<div class="foswikiSearchResultCount">Number of topics: <span>1</span></div>
EXPECT
}

sub verify_regex_match {
my $this = shift;

Expand Down
24 changes: 24 additions & 0 deletions core/data/System/EditingShorthand.txt
Expand Up @@ -40,6 +40,9 @@ Three or more dashes at the beginning of a line, followed by plus signs and the
You can create a table of contents with the [[VarTOC][%<nop>TOC%]] macro. If you want to *exclude* a heading from the TOC, put =!!= after the =---+=.

%X% Empty headings are allowed, but won't appear in the table of contents.

See the =&lt;ho&gt;= tag below for how to adjust heading levels dynamically.

</td><td>
<verbatim class="tml">
---++ Sushi
Expand Down Expand Up @@ -568,6 +571,27 @@ required
</sticky>
</td>
</tr>
<tr>
<td>
*Adjust heading levels:* %BR%
You can adjust heading levels for headings generated using =---+= markup and also HTML =&lt;h&gt;= tags using the =&lt;ho&gt; tag.<br />The =%<nop>INCLUDE= and =%<nop>SEARCH= macros also have a =headingoffset= parameter to do this for you in included content.<br />Heading levels are limited to the range 1..6 *after* any .
</td><td>
<pre>
---+ Offset is 0
&lt;ho off="1"&gt;
---+ H1 becomes H2
&lt;ho off="-1"&gt;
---+ Offset was 1, so Offset is now 0
</pre>
</td>
<td>
---+ Offset is 0
<ho off="1">
---+ Offset is 1, so H1 becomes H2
<ho off="-1">
---+ Offset is now 0
</td>
</tr>
</table>
<!-- %JQREQUIRE{"chili"}% -->

Expand Down
1 change: 1 addition & 0 deletions core/data/System/VarINCLUDE.txt
Expand Up @@ -10,6 +10,7 @@
| =pattern="..."= |Include a subset of a topic or a web page. Specify a RegularExpression that contains the text you want to keep in parenthesis, e.g. =pattern="(from here.*?to here)"=. IncludeTopicsAndWebPages has more. | none |
| =rev="2"= | Include a previous topic revision; N/A for URLs | top revision |
| =warn="off"= | Warn if topic include fails: Fail silently (if =off=); output default warning (if set to =on=); else, output specific text (use =$topic= for topic name) | =%<nop>INCLUDEWARNING%= [[DefaultPreferences][preferences]] setting |
| =headingoffset="1"= | Adds the given offset to any HTML headings generated in the included text. Works on headings defined by HTML tags as well as headings defined using foswiki markup. | 0 |
| =section="name"= | Includes only the specified named section, as defined in the included topic by the [[%IF{"'%BASETOPIC%'='Macros'" then="#"}%VarSTARTSECTION][STARTSECTION]] and [[%IF{"'%BASETOPIC%'='Macros'" then="#"}%VarENDSECTION][ENDSECTION]] macros. Nothing is shown if the named section does not exists. =section=""= is equivalent to not specifying a section | |
| =PARONE="val 1"%BR% PARTWO="val 2"= | Any other parameter will be defined as a macro within the scope of the included topic. The example parameters on the left will result in =%<nop>PARONE%= and =%<nop>PARTWO%= being defined within the included topic. | |
* Examples: See IncludeTopicsAndWebPages
Expand Down
1 change: 1 addition & 0 deletions core/data/System/VarSEARCH.txt
Expand Up @@ -33,6 +33,7 @@
| =nofinalnewline="on"= | If =on=, the search variable does not end in a line by itself. Any text continuing immediately after the SEARCH macro on the same line will be rendered as part of the table generated by the search, if appropriate. This feature is only active when format is defined. | =on= |
| =recurse="on"= | Recurse into subwebs, if subwebs are enabled. Note: recurse will currently search subwebs of explicitly excluded webs. =(web="all, -%SANDBOXWEB%" recurse="on")= will still search subwebs of =%SANDBOXWEB%=. This behavior is likely to change in a future release. | =off= |
| =separator=", "= | Line separator _between_ search hits (only used when format= is set) uses FormatTokens. <br />If =separator= is not defined, the default is "$n" (newline). Not defining the separator will additionally cause a newline to be added after a header and before a footer. | ="$n"= (Newline) |
| =headingoffset="1"= | Adds the given offset to any HTML headings generated in the search result. Works on headings defined by HTML tags as well as headings defined using foswiki markup. | 0 |
| =newline="%<nop>BR%"= | Line separator _within_ a search hit. Useful if you want to put multi-line content into a table cell, for example if the format="" parameter contains a $pattern() that captures more than one line. | ="$n"= (Newline) |
| =pagesize="25"= | number of items to show per page | ="25"= |
| =showpage="1"= | Page of items to show (starts at 1) (over-ridden by the value specified by the URL parameter hash from =$previousurl= and =$nexturl=) | ="1"= |
Expand Down

0 comments on commit 31b76b1

Please sign in to comment.