-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1025 from jdufner/feature/toc_of_page_headings
Implemented table of content of all page headings
- Loading branch information
Showing
24 changed files
with
965 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 13 additions & 13 deletions
26
FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteWidgetTests/SimpleWidgets/properties.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<properties> | ||
<Edit/> | ||
<Files/> | ||
<Properties/> | ||
<RecentChanges/> | ||
<Refactor/> | ||
<Search/> | ||
<Suites>slim</Suites> | ||
<Test/> | ||
<Versions/> | ||
<WhereUsed/> | ||
<saveId>1233779413308</saveId> | ||
<ticketId>-5607632332474131237</ticketId> | ||
<Edit/> | ||
<Files/> | ||
<Properties/> | ||
<RecentChanges/> | ||
<Refactor/> | ||
<Search/> | ||
<Suites>slim</Suites> | ||
<Test/> | ||
<Versions/> | ||
<WhereUsed/> | ||
<saveId>1233779413308</saveId> | ||
<ticketId>-5607632332474131237</ticketId> | ||
</properties> |
32 changes: 32 additions & 0 deletions
32
FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteWidgetTests/TestHeadings.wiki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
This page tests the headings on a wiki page. | ||
|
||
First create a page with some headings. | ||
|
||
!|Page Creator | | ||
|page name |page contents |page attributes|valid?| | ||
|HeadingsPage|!-!headings | ||
!1 Title of Page | ||
!2 Heading | ||
!3 Bla Bla Bla | ||
!4 Foo | ||
!5 Bar | ||
!6 Baz-!| |true | | ||
|
||
Then request the page. | ||
|
||
!|Response Requester| | ||
|uri |valid?| | ||
|HeadingsPage|true | | ||
|
||
Examine the page to be sure it contains the headings list. | ||
|
||
!|Response Examiner | | ||
|type |pattern |matches?|value| | ||
|contents|Contents: |true | | | ||
|contents|<a href="#TitleofPage">Title of Page</a> |true | | | ||
|contents|<li class="heading1">.*<a href="#TitleofPage">Title of Page</a>.*</li>|true | | | ||
|contents|<li class="heading2">.*<a href="#Heading">Heading</a>.*</li> |true | | | ||
|contents|<li class="heading3">.*<a href="#BlaBlaBla">Bla Bla Bla</a>.*</li> |true | | | ||
|contents|<li class="heading4">.*<a href="#Foo">Foo</a>.*</li> |true | | | ||
|contents|<li class="heading5">.*<a href="#Bar">Bar</a>.*</li> |true | | | ||
|contents|<li class="heading6">.*<a href="#Baz">Baz</a>.*</li> |true | | |
19 changes: 9 additions & 10 deletions
19
...sseRoot/FitNesse/UserGuide/FitNesseWiki/MarkupLanguageReference/MarkupHeaders/content.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
Headers are created by prefixing a line with !1 or !2 or !3 | ||
|
||
|!c '''Markup Text'''|!c '''Displayed as'''| | ||
|!- !1 Title -!|!1 Title| | ||
|!- !2 Header -!|!2 Header| | ||
|!- !3 Second Header -!|!3 Second Header| | ||
|
||
|
||
|
||
|
||
Headers are created by prefixing a line with !1 or !2 or !3 or !4 or !5 or !6 | ||
|
||
|!c '''Markup Text''' |!c '''Displayed as'''| | ||
|!- !1 Title -!|!1 Title | | ||
|!- !2 Header -!|!2 Header | | ||
|!- !3 Second Header -!|!3 Second Header | | ||
|!- !4 Third Header -!|!4 Third Header | | ||
|!- !5 Fourth Header -!|!5 Fourth Header | | ||
|!- !6 Fifth Header -!|!6 Fifth Header | |
10 changes: 10 additions & 0 deletions
10
...seRoot/FitNesse/UserGuide/FitNesseWiki/MarkupLanguageReference/MarkupHeadings/content.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Headings are created by prefixing a line with !headings | ||
|
||
|!c '''Markup Text''' |!c '''Displayed as'''| | ||
|!- !heading -!|Table of contents | | ||
|
||
Markup: | ||
{{{!headings -style decimal}}} | ||
|
||
|''' argument '''|''' description '''| | ||
|-style |The CSS style of the list items, possible values: decimal, decimal-leading-zero, lower-roman, upper-roman, lower-alpha, upper-alpha, none. Default value: decimal. | |
7 changes: 7 additions & 0 deletions
7
...oot/FitNesse/UserGuide/FitNesseWiki/MarkupLanguageReference/MarkupHeadings/properties.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0"?> | ||
<properties> | ||
<Files/> | ||
<LastModified>20090228113826</LastModified> | ||
<RecentChanges>true</RecentChanges> | ||
<WhereUsed/> | ||
</properties> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package fitnesse.wiki; | ||
|
||
import java.util.Collections; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import fitnesse.wikitext.parser.Symbol; | ||
import fitnesse.wikitext.parser.SymbolType; | ||
|
||
/** | ||
* Utilities for Handling a tree of {@link fitnesse.wikitext.parser.Symbol} aka syntax tree. | ||
*/ | ||
public class SymbolUtil { | ||
|
||
/** | ||
* Walks through the syntax tree either in pre- oder postorder, looking for all symbols of the | ||
* given type and collects it in a list. | ||
* | ||
* @param syntaxTree The syntax tree is a tree of {@link Symbol}. | ||
* @param type The {@link SymbolType} of the searched {@link Symbol}. If type is null, | ||
* each type is accepted. | ||
* @param preorder Walks through the syntax tree in preorder when <code>true</code>, in | ||
* postorder when <code>fals</code>. | ||
* @return A List of Symbols. | ||
*/ | ||
public static List<Symbol> findSymbolsByType(final Symbol syntaxTree, final SymbolType type, | ||
final boolean preorder) { | ||
final List<Symbol> symbols = new LinkedList<>(); | ||
if (preorder) { | ||
addToSymbolsIfIsOfType(symbols, syntaxTree, type); | ||
} | ||
for (Symbol subTree : syntaxTree.getChildren()) { | ||
symbols.addAll(findSymbolsByType(subTree, type, preorder)); | ||
} | ||
if (!preorder) { | ||
addToSymbolsIfIsOfType(symbols, syntaxTree, type); | ||
} | ||
return Collections.unmodifiableList(symbols); | ||
} | ||
|
||
private static void addToSymbolsIfIsOfType(final List<Symbol> symbols, final Symbol symbol, | ||
final SymbolType type) { | ||
if (type == null) { | ||
symbols.add(symbol); | ||
} else { | ||
if (symbol.isType(type)) { | ||
symbols.add(symbol); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package fitnesse.wiki; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import fitnesse.wikitext.parser.Alias; | ||
import fitnesse.wikitext.parser.See; | ||
import fitnesse.wikitext.parser.Symbol; | ||
import fitnesse.wikitext.parser.SymbolTreeWalker; | ||
import fitnesse.wikitext.parser.SymbolType; | ||
|
||
public class WikitextPageUtil { | ||
|
||
public static List<String> getXrefPages(WikitextPage page) { | ||
final List<String> xrefPages = new ArrayList<>(); | ||
page.getSyntaxTree().walkPreOrder(new SymbolTreeWalker() { | ||
@Override | ||
public boolean visit(Symbol node) { | ||
if (node.isType(See.symbolType)) { | ||
if (node.childAt(0).isType(Alias.symbolType)) { | ||
xrefPages.add(node.childAt(0).lastChild().childAt(0).getContent()); | ||
} else { | ||
xrefPages.add(node.childAt(0).getContent()); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean visitChildren(Symbol node) { | ||
return true; | ||
} | ||
}); | ||
return xrefPages; | ||
} | ||
|
||
public static List<Symbol> getSymbols(final WikitextPage page, final SymbolType symbolType) { | ||
final List<Symbol> symbols = new LinkedList<>(); | ||
for (final Symbol symbol : page.getSyntaxTree().getChildren()) { | ||
if (symbol.isType(symbolType)) { | ||
symbols.add(symbol); | ||
} | ||
} | ||
return Collections.unmodifiableList(symbols); | ||
} | ||
|
||
} |
Oops, something went wrong.