1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Source: Restore broken commit

This commit is contained in:
gnosygnu
2017-02-06 22:14:55 -05:00
parent 938beac9f9
commit 3bfeb94b43
4380 changed files with 328018 additions and 0 deletions

View File

@@ -0,0 +1,131 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.translates; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.primitives.*; import gplx.core.brys.fmtrs.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.langs.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*;
public class Xop_languages_xnde implements Xox_xnde {
public Xop_xnde_tkn Xnde() {return xnde;} private Xop_xnde_tkn xnde;
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
this.xnde = xnde;
langs = Find_lang_pages(ctx, wiki);
}
public List_adp Langs() {return langs;} private List_adp langs;
public Xoa_ttl Root_ttl() {return root_ttl;} private Xoa_ttl root_ttl;
private Xoa_ttl Root_ttl_of(Xowe_wiki wiki, Xoa_ttl ttl) {
byte[] page_bry = ttl.Page_db();
int slash_pos = Bry_find_.Find_bwd(page_bry, Xoa_ttl.Subpage_spr);
if (slash_pos == Bry_find_.Not_found) return ttl;
byte[] root_bry = Bry_.Mid(page_bry, 0, slash_pos);
return Xoa_ttl.Parse(wiki, ttl.Ns().Id(), root_bry);
}
private List_adp Find_lang_pages(Xop_ctx ctx, Xowe_wiki wiki) {
this.root_ttl = Root_ttl_of(wiki, ctx.Page().Ttl());
List_adp rslts = List_adp_.New();
Int_obj_ref rslt_count = Int_obj_ref.New(0);
Xow_ns page_ns = root_ttl.Ns();
wiki.Db_mgr().Load_mgr().Load_ttls_for_all_pages(Cancelable_.Never, rslts, null, null, rslt_count, page_ns, root_ttl.Page_db(), Int_.Max_value, 0, Int_.Max_value, true, false);
int len = rslt_count.Val();
if (len == 0) return List_adp_.Noop; // no lang pages; return;
List_adp rv = List_adp_.New();
byte[] root_ttl_bry = root_ttl.Page_db(); // get root_ttl_bry; do not use ns
int lang_bgn = root_ttl_bry.length + 1; // lang starts after /; EX: "Page" will have subpage of "Page/fr" and lang_bgn of 5
boolean english_needed = true;
for (int i = 0; i < len; i++) {
Xowd_page_itm page = (Xowd_page_itm)rslts.Get_at(i);
byte[] page_ttl_bry = page.Ttl_page_db();
int page_ttl_bry_len = page_ttl_bry.length;
if (Bry_.Eq(root_ttl_bry, page_ttl_bry)) continue; // ignore self; EX: "page"
if (lang_bgn < page_ttl_bry_len // guard against out of bounds
&& page_ttl_bry[lang_bgn - 1] == Xoa_ttl.Subpage_spr // prv char must be /; EX: "Page/fr"
) {
byte[] lang_key = Bry_.Mid(page_ttl_bry, lang_bgn, page_ttl_bry_len);
if (Bry_.Eq(lang_key, Xol_lang_itm_.Key_en)) // lang is english; mark english found;
english_needed = false;
Xol_lang_stub lang_itm = Xol_lang_stub_.Get_by_key_or_null(lang_key);
if (lang_itm == null) continue; // not a known lang
rv.Add(lang_itm);
}
}
if (rv.Count() == 0) return List_adp_.Noop; // no lang items; handles situations where just "Page" is returned
if (english_needed) // english not found; always add; handles situations wherein Page/fr and Page/de added, but not Page/en
rv.Add(Xol_lang_stub_.Get_by_key_or_en(Xol_lang_itm_.Key_en));
rv.Sort_by(Xol_lang_stub_.Comparer_key);
return rv;
}
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) {
if (langs.Count() == 0) return; // no langs; don't write anything;
fmtr_mgr_itms.Init(langs, ctx.Wiki(), root_ttl, ctx.Page().Lang().Key_bry());
fmtr_all.Bld_bfr_many(bfr, "Other languages", fmtr_mgr_itms);
}
private static final Xop_languages_fmtr fmtr_mgr_itms = new Xop_languages_fmtr();
public static final Bry_fmtr fmtr_all = Bry_fmtr.new_(String_.Concat_lines_nl
( "<table>"
, " <tbody>"
, " <tr valign=\"top\">"
, " <td class=\"mw-pt-languages-label\">~{other_languages_hdr}:</td>"
, " <td class=\"mw-pt-languages-list\">~{language_itms}"
, " </td>"
, " </tr>"
, " </tbody>"
, "</table>"
), "other_languages_hdr", "language_itms")
, fmtr_itm_basic = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <a href=\"~{anchor_href}\" title=\"~{anchor_title}\">~{anchor_text}</a>&#160;•"
), "anchor_href", "anchor_title", "anchor_text")
, fmtr_itm_english = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <a href=\"~{anchor_href}\" title=\"~{anchor_title}\"><span class=\"mw-pt-languages-ui\">~{anchor_text}</span></a>&#160;•"
), "anchor_href", "anchor_title", "anchor_text")
, fmtr_itm_selected = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <span class=\"mw-pt-languages-selected\">~{anchor_text}</span>&#160;•"
), "anchor_href", "anchor_title", "anchor_text")
;
// "<img src=\"//bits.wikimedia.org/static-1.22wmf9/extensions/Translate/res/images/prog-1.png\" alt=\"~{img_alt}\" title=\"~{img_title}\" width=\"9\" height=\"9\" />&#160;•&#160;"
}
class Xop_languages_fmtr implements gplx.core.brys.Bfr_arg {
public void Init(List_adp langs, Xowe_wiki wiki, Xoa_ttl root_ttl, byte[] cur_lang) {
this.langs = langs;
this.wiki = wiki;
this.root_ttl = root_ttl;
this.cur_lang = cur_lang;
} private List_adp langs; private Xowe_wiki wiki; private Xoa_ttl root_ttl; private byte[] cur_lang;
public void Bfr_arg__add(Bry_bfr bfr) {
int len = langs.Count();
Xoh_href_wtr href_wtr = wiki.Html__href_wtr();
int ns_id = root_ttl.Ns().Id();
byte[] root_ttl_bry = root_ttl.Page_db(); // NOTE: do not use .Full(); ns will be added in Xoa_ttl.Parse below
for (int i = 0; i < len; i++) {
Xol_lang_stub lang = (Xol_lang_stub)langs.Get_at(i);
byte[] lang_key = lang.Key();
boolean lang_is_en = Bry_.Eq(lang_key, Xol_lang_itm_.Key_en);
byte[] lang_ttl_bry = lang_is_en ? root_ttl_bry : Bry_.Add_w_dlm(Xoa_ttl.Subpage_spr, root_ttl_bry, lang_key);
Xoa_ttl lang_ttl = Xoa_ttl.Parse(wiki, ns_id, lang_ttl_bry);
byte[] lang_href = href_wtr.Build_to_bry(wiki, lang_ttl);
byte[] lang_title = lang_ttl.Full_txt_w_ttl_case();
Bry_fmtr fmtr = null;
if (Bry_.Eq(lang_key, Xol_lang_itm_.Key_en)) fmtr = Xop_languages_xnde.fmtr_itm_english;
else if (Bry_.Eq(lang_key, cur_lang)) fmtr = Xop_languages_xnde.fmtr_itm_selected;
else fmtr = Xop_languages_xnde.fmtr_itm_basic;
fmtr.Bld_bfr_many(bfr, lang_href, lang_title, lang.Canonical_name());
}
}
}

View File

@@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.translates; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Xop_languages_xnde_tst {
@Before public void init() {
Io_mgr.Instance.InitEngine_mem();
fxt.Reset();
fxt.Page_ttl_("Help:A");
fxt.Init_page_create("Help:A", ""); // create for AllPages
} private final Xop_fxt fxt = new Xop_fxt();
@Test public void None() {
fxt.Test_parse_page_all_str("<languages/>", ""); // empty
}
@Test public void Many() {
fxt.Init_page_create("Help:A/de", "");
fxt.Init_page_create("Help:A/en", "");
fxt.Init_page_create("Help:A/fr", "");
fxt.Test_parse_page_all_str("<languages/>", Many_expd);
}
@Test public void Many_english_implied() {
fxt.Init_page_create("Help:A/de", "");
fxt.Init_page_create("Help:A/fr", "");
fxt.Test_parse_page_all_str("<languages/>", Many_expd);
}
@Test public void Current_is_french() {
fxt.Init_page_create("Help:A/de", "");
fxt.Init_page_create("Help:A/fr", "");
fxt.Page_ttl_("Help:A/fr");
fxt.Test_parse_page_all_str("<languages/>", String_.Concat_lines_nl
( "<table>"
, " <tbody>"
, " <tr valign=\"top\">"
, " <td class=\"mw-pt-languages-label\">Other languages:</td>"
, " <td class=\"mw-pt-languages-list\">"
, " <a href=\"/wiki/Help:A/de\" title=\"Help:A/de\">Deutsch</a>&#160;•"
, " <a href=\"/wiki/Help:A\" title=\"Help:A\"><span class=\"mw-pt-languages-ui\">English</span></a>&#160;•"
, " <a href=\"/wiki/Help:A/fr\" title=\"Help:A/fr\">Français</a>&#160;•"
, " </td>"
, " </tr>"
, " </tbody>"
, "</table>"
));
}
private static final String Many_expd = String_.Concat_lines_nl
( "<table>"
, " <tbody>"
, " <tr valign=\"top\">"
, " <td class=\"mw-pt-languages-label\">Other languages:</td>"
, " <td class=\"mw-pt-languages-list\">"
, " <a href=\"/wiki/Help:A/de\" title=\"Help:A/de\">Deutsch</a>&#160;•"
, " <a href=\"/wiki/Help:A\" title=\"Help:A\"><span class=\"mw-pt-languages-ui\">English</span></a>&#160;•"
, " <a href=\"/wiki/Help:A/fr\" title=\"Help:A/fr\">Français</a>&#160;•"
, " </td>"
, " </tr>"
, " </tbody>"
, "</table>"
);
}

View File

@@ -0,0 +1,38 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.translates; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.langs.*;
import gplx.xowa.specials.*;
public class Xop_mylanguage_page implements Xow_special_page {
public Xow_special_meta Special__meta() {return Xow_special_meta_.Itm__my_language;}
public void Special__gen(Xow_wiki wikii, Xoa_page pagei, Xoa_url url, Xoa_ttl ttl) {
// Special:MyLanguage/Help:A -> Help:A/fr
Xowe_wiki wiki = (Xowe_wiki)wikii; Xoae_page page = (Xoae_page)pagei;
byte[] page_bry = ttl.Leaf_txt_wo_qarg(); // EX: Help:A
byte[] lang_key = wiki.Appe().Usere().Lang().Key_bry(); // EX: fr
byte[] trg_bry = page_bry;
boolean lang_is_english = Bry_.Eq(lang_key, Xol_lang_itm_.Key_en);
if (!lang_is_english)
trg_bry = Bry_.Add_w_dlm(Xoa_ttl.Subpage_spr, page_bry, lang_key);
wiki.Data_mgr().Redirect(page, trg_bry);
if (page.Db().Page().Exists_n() && !lang_is_english) // foreign lang does not exist; default to english
wiki.Data_mgr().Redirect(page, page_bry);
}
public Xow_special_page Special__clone() {return this;}
}

View File

@@ -0,0 +1,58 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.translates; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Xop_mylanguage_page_tst {
@Before public void init() {fxt.Clear();} private Xop_mylanguage_page_fxt fxt = new Xop_mylanguage_page_fxt();
@Test public void Non_english_exists() {
fxt.Init_create_page("Help:A/fr");
fxt.Init_cur_lang("fr");
fxt.Test_open("Special:MyLanguage/Help:A", "Help:A/fr");
}
@Test public void English() {
fxt.Init_create_page("Help:A");
fxt.Init_cur_lang("en");
fxt.Test_open("Special:MyLanguage/Help:A", "Help:A");
}
@Test public void Non_english_absent() {
fxt.Init_create_page("Help:A");
fxt.Init_cur_lang("fr");
fxt.Test_open("Special:MyLanguage/Help:A", "Help:A");
}
}
class Xop_mylanguage_page_fxt {
public void Clear() {
parser_fxt = new Xop_fxt();
parser_fxt.Reset();
app = parser_fxt.App();
wiki = parser_fxt.Wiki();
special_page = wiki.Special_mgr().Page_mylanguage();
} private Xop_fxt parser_fxt; private Xoae_app app; private Xop_mylanguage_page special_page; private Xowe_wiki wiki;
public void Init_create_page(String page) {parser_fxt.Init_page_create(page, page);}
public void Init_cur_lang(String lang) {app.Sys_cfg().Lang_(Bry_.new_a7(lang));}
public void Test_open(String link, String expd) {
Xoae_page page = parser_fxt.Ctx().Page();
Xoa_url url = app.User().Wikii().Utl__url_parser().Parse(Bry_.new_u8(link));
page.Url_(url);
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_a7(link));
page.Ttl_(ttl);
special_page.Special__gen(wiki, page, url, ttl);
Tfds.Eq(expd, String_.new_a7(page.Url().Page_bry()));
Tfds.Eq(expd, String_.new_a7(page.Db().Text().Text_bry()));
}
}

View File

@@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.translates; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
public class Xop_translate_xnde implements Xox_xnde {
public Xop_root_tkn Xtn_root() {return xtn_root;} private Xop_root_tkn xtn_root;
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {}
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
byte[] translate_src = Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
translate_src = Bry_.Trim(translate_src, 0, translate_src.length);
Xop_ctx sub_ctx = Xop_ctx.New__sub__reuse_page(ctx);
xtn_root = wiki.Parser_mgr().Main().Parse_text_to_wdom_old_ctx(sub_ctx, translate_src, true);
}
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) {
html_wtr.Write_tkn_to_html(bfr, ctx, hctx, xtn_root.Root_src(), xnde, Xoh_html_wtr.Sub_idx_null, xtn_root);
}
}

View File

@@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.translates; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Xop_translate_xnde_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_parse_page_all_str("<translate> ''a'' </translate>", "<i>a</i>"); // NOTE: trim ws
}
@Test public void Header() {
fxt.Test_parse_page_all_str("<translate>==a==</translate>", "<h2>a</h2>\n");
}
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.translates; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.btries.*; import gplx.xowa.langs.*;
import gplx.xowa.parsers.*;
public class Xop_tvar_lxr implements Xop_lxr {
public int Lxr_tid() {return Xop_lxr_.Tid_tvar;}
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Hook_bgn, this);}
public void Init_by_lang(Xol_lang_itm lang, Btrie_fast_mgr core_trie) {}
public void Term(Btrie_fast_mgr core_trie) {}
private static final byte[] Hook_bgn = Bry_.new_a7("<tvar|"), Close_nde = Bry_.new_a7("</>");
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
int rhs_end = Bry_find_.Find_fwd(src, Byte_ascii.Gt, cur_pos); if (rhs_end == Bry_find_.Not_found) return ctx.Lxr_make_txt_(cur_pos);
int lhs_bgn = Bry_find_.Find_fwd(src, Close_nde , rhs_end); if (lhs_bgn == Bry_find_.Not_found) return ctx.Lxr_make_txt_(cur_pos);
byte[] body = Bry_.Mid(src, rhs_end + Int_.Const_position_after_char, lhs_bgn);
Xop_ctx sub_ctx = Xop_ctx.New__sub__reuse_page(ctx);
Xop_root_tkn sub_root = tkn_mkr.Root(body);
body = ctx.Wiki().Parser_mgr().Main().Expand_tmpl(sub_root, sub_ctx, tkn_mkr, body); // NOTE: must parse inner text for templates; EX:<tvar|a>{{B}}</>; PAGE:mw:Download; DATE:2014-04-27
int end_pos = lhs_bgn + Close_nde.length;
ctx.Subs_add(root, tkn_mkr.Tvar(bgn_pos, end_pos, cur_pos, rhs_end, rhs_end + Int_.Const_position_after_char, lhs_bgn, body));
return end_pos;
}
public static final Xop_tvar_lxr Instance = new Xop_tvar_lxr(); Xop_tvar_lxr() {}
}

View File

@@ -0,0 +1,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.translates; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Xop_tvar_lxr_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_parse_page_all_str("<tvar|1>''a''</>", "<i>a</i>");
}
@Test public void Missing_end() {
fxt.Test_parse_page_all_str("<tvar|1>''a''</tvar>", "&lt;tvar|1&gt;<i>a</i>&lt;/tvar&gt;");
}
@Test public void Templates() {
fxt.Init_defn_add("A", "a");
fxt.Test_parse_page_all_str("<tvar|1>{{A}}</>", "a");
}
}

View File

@@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.translates; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.parsers.*;
public class Xop_tvar_tkn extends Xop_tkn_itm_base {
public Xop_tvar_tkn(int tkn_bgn, int tkn_end, int key_bgn, int key_end, int txt_bgn, int txt_end, byte[] wikitext) {
this.Tkn_ini_pos(false, tkn_bgn, tkn_end);
this.key_bgn = key_bgn; this.key_end = key_end;
this.txt_bgn = txt_bgn; this.txt_end = txt_end;
this.wikitext = wikitext;
}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_tvar;}
public int Key_bgn() {return key_bgn;} private int key_bgn;
public int Key_end() {return key_end;} private int key_end;
public int Txt_bgn() {return txt_bgn;} private int txt_bgn;
public int Txt_end() {return txt_end;} private int txt_end;
public byte[] Wikitext() {return wikitext;} private byte[] wikitext;
}