9

構成可能な使いやすい API を備えた素敵なパーサーのアイデアはありますか? http://wikitravel.org/wiki/en/api.php?format=xml&action=parse&prop=wikitext&page=San%20Franciscoなどのデータをフィードし、必要なデータのセクションを選択し、カスタム html を出力することを検討していますそれぞれのユニークなタイプの要素? Java が望ましいですが、ほとんどの (99% 以上) ウィキテキストと互換性のある php/js ソリューションがあれば、それも問題ありません。

4

4 に答える 4

15

Swebleはおそらくウィキテキストの最高の Java パーサーです。ウィキテキストに100% 準拠していると主張していますが、私はそれを真剣に疑っています。ウィキテキストを解析して抽象的な構文ツリーにし、それを使って何らかの処理を行う必要があります (HTML への変換など)。

mediawiki.org には、さまざまなプログラミング言語のウィキテキスト パーサーを一覧表示するページがあります。私はそれらのどれもウィキテキストの 99% 以上を行っているとは思いません。一般に、ウィキテキストの解析は非常に複雑な問題です。ウィキテキストは、MediaWiki パーサー自体以外では正式に定義されていません。

于 2012-07-23T18:52:22.377 に答える
2

Bliki で成功しました: https://bitbucket.org/axelclk/info.bliki.wiki/wiki/Mediawiki2HTML

Bliki は XWiki で使用されているもので、使い方は非常に簡単です。

String htmlText = WikiModel.toHtml("This is a simple [[Hello World]] wiki tag");

ダウンロードのリストは次のとおりです: https://oss.sonatype.org/content/repositories/snapshots/info/bliki/wiki/bliki-core/

しかし、これを Maven で使用する方がはるかに簡単です。

于 2016-12-14T18:20:29.873 に答える
0

XWiki のレンダリング エンジン ( http://rendering.xwiki.org ) を使用することもできます。一部のメディアウィキ コンテンツを解析する方法の例を次に示します。

// Initialize Rendering components and allow getting instances
EmbeddableComponentManager componentManager = new EmbeddableComponentManager();
componentManager.initialize(this.getClass().getClassLoader());

// Get the MediaWiki Parser
Parser parser = componentManager.getInstance(Parser.class, "mediawiki/1.0);

// Parse the content in mediawiki markup and generate an AST (it's also possible to use a streaming parser for large content)
XDOM xdom = parser.parse(new StringReader("... input here"));

// Perform any transformation you wish to the XDOM here
...

// Generate XHTML out of the modified XDOM
WikiPrinter printer = new DefaultWikiPrinter();
BlockRenderer renderer = componentManager.getInstance(BlockRenderer.class, "xhtml/1.0");
renderer.render(xdom, printer);

// The result is now in the printer object
printer.toString();

http://rendering.xwiki.org/xwiki/bin/view/Main/GettingStartedでその他の例を参照してください。

それが役に立てば幸い。

于 2015-08-02T16:20:01.057 に答える