import java.io.StringReader;
import java.util.Map;
+import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.text.FreenetLinkParser;
import net.pterodactylus.sone.text.FreenetLinkParserContext;
*/
public class ParserFilter implements Filter {
+ /** The core. */
+ private final Core core;
+
/** The link parser. */
private final FreenetLinkParser linkParser;
* Creates a new filter that runs its input through a
* {@link FreenetLinkParser}.
*
+ * @param core
+ * The core
* @param templateContextFactory
* The context factory for rendering the parts
*/
- public ParserFilter(TemplateContextFactory templateContextFactory) {
+ public ParserFilter(Core core, TemplateContextFactory templateContextFactory) {
+ this.core = core;
linkParser = new FreenetLinkParser(templateContextFactory);
}
soneKey = "sone";
}
Sone sone = (Sone) templateContext.get(soneKey);
+ if (sone == null) {
+ sone = core.getSone(soneKey, false);
+ }
FreenetLinkParserContext context = new FreenetLinkParserContext(sone);
try {
return linkParser.parse(context, new StringReader(text));
templateContextFactory.addFilter("match", new MatchFilter());
templateContextFactory.addFilter("css", new CssClassNameFilter());
templateContextFactory.addFilter("js", new JavascriptFilter());
- templateContextFactory.addFilter("parse", new ParserFilter(templateContextFactory));
+ templateContextFactory.addFilter("parse", new ParserFilter(getCore(), templateContextFactory));
templateContextFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate"));
templateContextFactory.addFilter("format", new FormatFilter());
templateContextFactory.addPlugin("getpage", new GetPagePlugin());