use of info.bliki.wiki.filter.HTMLConverter in project OsmAnd-tools by osmandapp.
the class WikiDatabasePreparation method mainTest.
public static void mainTest(String[] args) throws ConversionException, ComponentLookupException, ParseException, IOException {
EmbeddableComponentManager cm = new EmbeddableComponentManager();
cm.initialize(WikiDatabasePreparation.class.getClassLoader());
Parser parser = cm.getInstance(Parser.class, Syntax.MEDIAWIKI_1_0.toIdString());
FileReader fr = new FileReader(new File("/Users/victorshcherb/Documents/b.src.html"));
BufferedReader br = new BufferedReader(fr);
String content = "";
String s;
while ((s = br.readLine()) != null) {
content += s;
}
content = removeMacroBlocks(content, new HashMap<>());
XDOM xdom = parser.parse(new StringReader(content));
// Find all links and make them italic
for (Block block : xdom.getBlocks(new ClassBlockMatcher(LinkBlock.class), Block.Axes.DESCENDANT)) {
Block parentBlock = block.getParent();
Block newBlock = new FormatBlock(Collections.<Block>singletonList(block), Format.ITALIC);
parentBlock.replaceChild(newBlock, block);
}
// for (Block block : xdom.getBlocks(new ClassBlockMatcher(ParagraphBlock.class), Block.Axes.DESCENDANT)) {
// ParagraphBlock b = (ParagraphBlock) block;
// block.getParent().removeBlock(block);
// }
WikiPrinter printer = new DefaultWikiPrinter();
// BlockRenderer renderer = cm.getInstance(BlockRenderer.class, Syntax.XHTML_1_0.toIdString());
// renderer.render(xdom, printer);
// System.out.println(printer.toString());
Converter converter = cm.getInstance(Converter.class);
// Convert input in XWiki Syntax 2.1 into XHTML. The result is stored in the printer.
printer = new DefaultWikiPrinter();
converter.convert(new FileReader(new File("/Users/victorshcherb/Documents/a.src.html")), Syntax.MEDIAWIKI_1_0, Syntax.XHTML_1_0, printer);
System.out.println(printer.toString());
final HTMLConverter nconverter = new HTMLConverter(false);
String lang = "be";
WikiModel wikiModel = new WikiModel("http://" + lang + ".wikipedia.com/wiki/${image}", "http://" + lang + ".wikipedia.com/wiki/${title}");
// String plainStr = wikiModel.render(nconverter, content);
// System.out.println(plainStr);
// downloadPage("https://be.m.wikipedia.org/wiki/%D0%93%D0%BE%D1%80%D0%B0%D0%B4_%D0%9C%D1%96%D0%BD%D1%81%D0%BA",
// "/Users/victorshcherb/Documents/a.wiki.html");
}
Aggregations