Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 38 by dfisla: Parsing of template redirects
http://code.google.com/p/gwtwiki/issues/detail?id=38
Consider:
Template:Test1
------- contents -------
#REDIRECT[[Template:Test2]]
Template:Test
-------- contents ------
<p>Hello World!</p>
given any article that references {{Test1}} should output:
<p>Hello World!</p>
for specific wikipedia example you can refer to:
Template:InfosectionEnd, and
Template:InfoboxEnd
I got this to work by making the following changes to TemplateParser class:
private static final Pattern REDIRECT_PATTERN =
Pattern.compile(".*#REDIRECT[ ]*\\[\\[Template:(.*)\\]\\].*",
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
in method:
protected static void parseRecursive(String rawWikitext, IWikiModel
wikiModel, Appendable writer, boolean parseOnlySignature, boolean
renderTemplate, HashMap<String, String> templateParameterMap) throws
IOException {
...
// Experimental to handle #REDIRECT [[Template:Foo]]
Matcher m = REDIRECT_PATTERN.matcher(rawWikitext);
if (m.matches()) {
String redirectTemplate = m.group(1);
rawWikitext = m.replaceAll("{{" + redirectTemplate + "}}");
}
There has to be a better way to implement this, I don't really like mixing
in the regex matcher with the rest of the template parser based on the fact
the template parser operates on the character level.
Also, currently this works because the parser will replace the redirect
reference with the actual template markup and recurse on it - therefore the
redirect is followed and content is evaluated/parsed. The template parser
will also not stop and continue parsing the rest of the main template which
is opposite to how page redirects are handled where the page parser stops
processing the rest of the content after running into a redirect construct.
I also allow for whitespace between #REDIRECT keyword and the first outer
"[[" brackets as there are many Wikipedia articles that do this instead of
the proper #REDIRECT[[...]] syntax.
In any case, the above change works for now - this was a big deal for me
when parsing Wikipedia pages & templates.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups "Bliki - Java/Eclipse Wikipedia API" group.
To post to this group, send email to
bl...@googlegroups.com
To unsubscribe from this group, send email to
bliki-un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bliki?hl=en
or visit the projects homepage at
http://matheclipse.org/en/Eclipse_Wikipedia_Editor