-
Notifications
You must be signed in to change notification settings - Fork 713
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 #1382 from jediwhale/master
Markup system plugins
- Loading branch information
Showing
17 changed files
with
191 additions
and
23 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...itNesse/UserGuide/AdministeringFitNesse/WritingPlugins/MarkupSystemPlugIns.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,24 @@ | ||
A markup system plugin allows the use of markup syntax different from the standard !-FitNesse-! wiki markup. | ||
|
||
The plugin registers itself with a name and a factory function: | ||
{{{public class PluginFeatureFactory extends PluginFeatureFactoryBase { | ||
|
||
@Override | ||
public void registerMarkupSystems(MarkUpSystems systems) { | ||
systems.register(MyMarkup.NAME, MyMarkup::new); | ||
System.out.println(MyMarkup.NAME + " system registered"); | ||
... any initialization required ... | ||
} | ||
} | ||
}}} | ||
The markup system class must implement the !-MarkUpSystem-! interface: | ||
{{{public class MyMarkup implements MarkUpSystem { | ||
public static final String NAME = "mymarkup"; | ||
... implemented methods... | ||
} | ||
}}} | ||
To use the new markup syntax, include a comment with the markup system name on the first line of the page: | ||
{{{#lang mymarkup | ||
... page content ... | ||
}}} | ||
Other pages in the wiki will continue to use the standard wiki syntax. |
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
10 changes: 5 additions & 5 deletions
10
FitNesseRoot/FitNesse/UserGuide/AdministeringFitNesse/WritingPlugins/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,8 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<properties> | ||
<Files/> | ||
<RecentChanges/> | ||
<Search/> | ||
<Static/> | ||
<WhereUsed/> | ||
<Files/> | ||
<RecentChanges/> | ||
<Search/> | ||
<Static/> | ||
<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
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
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.wikitext; | ||
|
||
import fitnesse.wikitext.parser.MarkUpSystemV2; | ||
import fitnesse.wikitext.parser.MatchResult; | ||
import fitnesse.wikitext.parser.Matcher; | ||
import fitnesse.wikitext.parser.ScanString; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
public class MarkUpSystems { | ||
public static MarkUpSystems STORE = new MarkUpSystems(); | ||
|
||
public MarkUpSystem make(String content) { | ||
String key = findName(content).toLowerCase(); | ||
return key.length() > 0 && systems.containsKey(key) | ||
? systems.get(key).get() | ||
: new MarkUpSystemV2(); | ||
} | ||
|
||
public void register(String name, Supplier<MarkUpSystem> supplier) { | ||
systems.put(name.toLowerCase(), supplier); | ||
} | ||
|
||
public static String findName(String content) { | ||
ScanString input = new ScanString(content, 0); | ||
|
||
while (true) { | ||
MatchResult leadingMatch = LEADING_MATCHER.makeMatch(input); | ||
if (!leadingMatch.isMatched()) break; | ||
leadingMatch.advance(input); | ||
} | ||
|
||
MatchResult langMatch = LANG_MATCHER.makeMatch(input); | ||
if (langMatch.isMatched()) { | ||
langMatch.advance(input); | ||
int startName = input.getOffset(); | ||
MatchResult newLineMatch = NEWLINE_MATCHER.findMatch(input); | ||
if (newLineMatch.isMatched()) { | ||
return input.rawSubstring(startName, input.getOffset()); | ||
} | ||
} | ||
return ""; | ||
} | ||
|
||
private static final Map<String, Supplier<MarkUpSystem>> systems = new HashMap<>(); | ||
|
||
private static final Matcher LANG_MATCHER = new Matcher().string("#lang").whitespace(); | ||
private static final Matcher NEWLINE_MATCHER = new Matcher().newLine(); | ||
private static final Matcher LEADING_MATCHER = new Matcher().ignoreWhitespace().newLine(); | ||
} |
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,18 @@ | ||
package fitnesse.wikitext; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class MarkupSystemsTest { | ||
@Test | ||
public void findsName() { | ||
assertName("lang on first line", "name", "#lang name\nstuff"); | ||
assertName("skips leading blankspace", "name", "\n \n#lang name\nstuff"); | ||
assertName("missing lang", "", "#langname\nstuff"); | ||
assertName("alternate newline", "name", "#lang name\r\nstuff"); | ||
} | ||
|
||
private void assertName(String message, String expected, String content) { | ||
Assert.assertEquals(message, expected, MarkUpSystems.findName(content)); | ||
} | ||
} |
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