Cite: Change Cite to follow MediaWiki behavior for super-scripting [#382]

pull/620/head
gnosygnu 5 years ago
parent 41deb3c0c1
commit a94a9f0c7f

@ -134,6 +134,24 @@ public class Bry_split_ {
}
return rv;
}
public static byte[][] Split_ws(byte[] src) {// REF.PHP: preg_split('/\s+/', $text)
int len = src.length;
if (len == 0) return Bry_.Ary_empty;
List_adp list = List_adp_.New();
int pos = 0;
while (true) {
int bgn = Bry_find_.Find_fwd_while_ws(src, pos, len);
if (bgn == len) break; // EOS
int end = Bry_find_.Find_fwd_until_ws(src, bgn + 1, len);
if (end == -1) end = len;
list.Add(Bry_.Mid(src, bgn, end));
pos = end + 1;
if (pos >= len) break;
}
return (byte[][])list.To_ary_and_clear(byte[].class);
}
public static final int Rv__ok = 0, Rv__extend = 1, Rv__cancel = 2;
}

@ -49,6 +49,11 @@ public class Bry_split__tst {
fxt.Test__split_w_max("a" , Byte_ascii.Pipe, 2, "a", null); // max is more
fxt.Test__split_w_max("|" , Byte_ascii.Pipe, 2, "", ""); // empty itms
}
@Test public void Split_ws() {
fxt.Test__split_ws("a b", "a", "b");
fxt.Test__split_ws(" a ", "a");
fxt.Test__split_ws(" abc def ", "abc", "def");
}
}
class Bry_split__fxt {
private final Bry_split_wkr__example wkr = new Bry_split_wkr__example();
@ -64,6 +69,10 @@ class Bry_split__fxt {
public void Test__split_w_max(String src, byte dlm, int max, String... expd) {
Gftest.Eq__ary(expd, String_.Ary(Bry_split_.Split_w_max(Bry_.new_u8(src), dlm, max)));
}
public void Test__split_ws(String raw, String... expd) {
byte[][] actl = Bry_split_.Split_ws(Bry_.new_u8(raw));
Gftest.Eq__ary(Bry_.Ary(expd), actl, raw);
}
}
class Bry_split_wkr__example implements gplx.core.brys.Bry_split_wkr {
private final List_adp list = List_adp_.New();

@ -0,0 +1,19 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.data_stores; import gplx.*; import gplx.core.*;
public interface Gfo_data_itm {
String Key();
}

@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.data_stores; import gplx.*; import gplx.core.*;
public class Gfo_data_store {
private final Hash_adp hash = Hash_adp_.New();
public Gfo_data_itm Get_or_null(String key) {
return (Gfo_data_itm)hash.Get_by(key);
}
public void Set(Gfo_data_itm itm) {
hash.Add_if_dupe_use_nth(itm.Key(), itm);
}
public void Clear() {
hash.Clear();
}
}

@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
public class Gfh_atr_itm {
public Gfh_atr_itm(byte[] key, byte[] val) {
this.key = key;
this.val = val;
}
public byte[] Key() {return key;} private final byte[] key;
public byte[] Val() {return val;} private final byte[] val;
public static Gfh_atr_itm New(byte[] key, String val) {return new Gfh_atr_itm(key, Bry_.new_u8(val));}
public static Gfh_atr_itm New(byte[] key, byte[] val) {return new Gfh_atr_itm(key, val);}
}

@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
public class Gfh_html_ {
public static byte[] rawElement(Bry_bfr bfr, int tag_id, byte[] body, Gfh_atr_itm... atrs) {
// add "<tag"
byte[] tag_name = Bry_.new_u8(Gfh_tag_.To_str(tag_id));
Gfh_tag_.Bld_lhs_bgn(bfr, tag_name);
// add " key1=val1 ..."
int len = atrs.length;
for (int i = 0; i < len; i++) {
Gfh_atr_itm atr = atrs[i];
Gfh_atr_.Add(bfr, atr.Key(), atr.Val());
}
// add ">"
Gfh_tag_.Bld_lhs_end_nde(bfr);
bfr.Add(body);
// add "</tag>"
Gfh_tag_.Bld_rhs(bfr, tag_name);
return bfr.To_bry_and_clear();
}
}

@ -278,7 +278,7 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
, Comm_end_len = Comm_end.length
;
public static final byte[] Rhs_bgn = Bry_.new_a7("</");
public static void Bld_lhs_bgn(Bry_bfr bfr, byte[] tag) {bfr.Add_byte(Byte_ascii.Lt).Add(tag);} // >
public static void Bld_lhs_bgn(Bry_bfr bfr, byte[] tag) {bfr.Add_byte(Byte_ascii.Lt).Add(tag);} // <tag
public static void Bld_lhs_end_nde(Bry_bfr bfr) {bfr.Add_byte(Byte_ascii.Gt);} // >
public static void Bld_lhs_end_inl(Bry_bfr bfr) {bfr.Add_byte(Byte_ascii.Slash).Add_byte(Byte_ascii.Gt);} // "/>"
public static void Bld_rhs(Bry_bfr bfr, byte[] name) {bfr.Add(Rhs_bgn).Add(name).Add_byte(Byte_ascii.Angle_end);} // EX:"</tag_name>"

@ -16,7 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
package gplx.xowa; import gplx.*;
import gplx.core.tests.*; import gplx.core.log_msgs.*;
import gplx.xowa.apps.cfgs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*; import gplx.xowa.langs.msgs.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.lnkis.*;
import gplx.xowa.files.exts.*; import gplx.xowa.files.repos.*;
@ -161,6 +161,10 @@ public class Xop_fxt {
rv.Find_tkn_(tkn_arg_itm_(find));
return rv;
}
public void Init__msg(String key, String val) {
Xol_msg_itm msg_itm = wiki.Msg_mgr().Get_or_make(Bry_.new_u8(key));
msg_itm.Atrs_set(Bry_.new_u8(val), false, false);
}
public Xop_fxt Init_para_y_() {ctx.Para().Enabled_y_(); return this;}
public Xop_fxt Init_para_n_() {ctx.Para().Enabled_n_(); return this;}
public Xop_fxt Init_log_(Gfo_msg_itm... itms) {for (Gfo_msg_itm itm : itms) log_itms.Add(itm); return this;} List_adp log_itms = List_adp_.New();

@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.parsers; import gplx.*; import gplx.xowa.*;
import gplx.core.primitives.*; import gplx.core.brys.fmtrs.*;
import gplx.core.primitives.*; import gplx.core.brys.fmtrs.*; import gplx.core.data_stores.*;
import gplx.xowa.wikis.*; import gplx.core.envs.*;
import gplx.xowa.files.*;
import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.wbases.hwtrs.*; import gplx.xowa.xtns.pfuncs.ifs.*; import gplx.xowa.xtns.pfuncs.times.*; import gplx.xowa.xtns.pfuncs.ttls.*;
@ -28,6 +28,7 @@ public class Xow_parser_mgr {
}
public Xop_ctx Ctx() {return ctx;} private final Xop_ctx ctx;
public Xop_parser Main() {return parser;} private final Xop_parser parser;
public Gfo_data_store Data_store() {return data_store;} private final Gfo_data_store data_store = new Gfo_data_store();
public Scrib_core_mgr Scrib() {return scrib;} private final Scrib_core_mgr scrib = new Scrib_core_mgr();
public Xof_img_size Img_size() {return img_size;} private final Xof_img_size img_size = new Xof_img_size();
public Pfunc_ifexist_mgr Ifexist_mgr() {return ifexist_mgr;} private final Pfunc_ifexist_mgr ifexist_mgr = new Pfunc_ifexist_mgr();

@ -0,0 +1,40 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
class Cite_link_label_mgr {
private final Hash_adp_bry hash = Hash_adp_bry.cs();
public void Clear() {
hash.Clear();
}
public Cite_link_label_grp Get_or_null(byte[] group) {
return (Cite_link_label_grp)hash.Get_by(group);
}
public void Add(byte[] group, Cite_link_label_grp grp) {
hash.Add(group, grp);
}
}
class Cite_link_label_grp {
private final byte[][] labels;
public Cite_link_label_grp(byte[] name, byte[][] labels) {
this.name = name;
this.labels = labels;
}
public byte[] Name() {return name;} private final byte[] name;
public int Len() {return labels.length;}
public byte[] Get_or_null(int idx) {
return idx < labels.length ? labels[idx] : null;
}
}

@ -0,0 +1,98 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
import gplx.langs.htmls.*;
class Cite_mgr { // REF.MW:/extensions/Cite/includes/Cite.php
private final Xowe_wiki wiki;
private final Hash_adp_bry messages_by_group = Hash_adp_bry.cs();
private Cite_xtn_data xtn_data;
private Cite_link_label_mgr link_label_mgr;
public Cite_mgr(Xowe_wiki wiki) {
this.wiki = wiki;
}
public byte[] getLinkLabel(int offset, byte[] group) {
// get xtn_data; NOTE: should go in Init_by_wiki, but Init_by_wiki doesn't get called by tests
if (xtn_data == null) {
this.xtn_data = Cite_xtn_data.Get_or_make(wiki.Parser_mgr().Data_store());
this.link_label_mgr = xtn_data.Link_labels();
}
// get message; use cache to avoid multiple concantenations; EX: "cite_link_label_group-" + "lower-roman";
byte[] message = (byte[])messages_by_group.Get_by_bry(group);
if (message == null) {
message = Bry_.Add(Msg__cite_link_label_group, group);
messages_by_group.Add(group, message);
}
// get linkLabels or gen
Cite_link_label_grp linkLabels = link_label_mgr.Get_or_null(group);
if (linkLabels == null) {
linkLabels = this.genLinkLabels(group, message);
}
// if linkLabels group missing, just concat; EX: "custom-group 1"
if (linkLabels.Len() == 0) {
return Bry_.Add((group.length == 0 ? Bry_.Empty : Bry_.Add(group, Byte_ascii.Space)), wiki.Lang().Num_mgr().Format_num(offset));
}
// linkLabels group exists; pull corresponding offset; EX: "5" in lower-roman -> "v"
byte[] rv = linkLabels.Get_or_null(offset - 1);
return rv == null
? this.plainError(Msg__cite_error_no_link_label_group, group, message)
: rv;
}
private Cite_link_label_grp genLinkLabels(byte[] group, byte[] message) {
Xol_msg_itm msg = wiki.Msg_mgr().Find_or_null(message);
byte[][] text = msg == null
? Bry_.Ary_empty
: Bry_split_.Split_ws(msg.Val());
Cite_link_label_grp grp = new Cite_link_label_grp(group, text);
link_label_mgr.Add(group, grp);
return grp;
}
private byte[] plainError(byte[] key, Object... ary) {
Bry_bfr tmp_bfr = Bry_bfr_.New();
Bry_fmtr tmp_fmtr = Bry_fmtr.New__tmp();
// build specific error msg
Xol_msg_itm msg_itm = wiki.Msg_mgr().Find_or_null(key);
byte[] msg = (msg_itm == null) ? key : msg_itm.Fmt(tmp_bfr, tmp_fmtr, ary);
// wrap specific error message with "Cite error: "
msg_itm = wiki.Msg_mgr().Find_or_null(Msg__cite_error);
if (msg_itm != null)
msg = msg_itm.Fmt(tmp_bfr, tmp_fmtr, msg);
// generate tag
Xol_lang_itm lang = wiki.Lang();
byte[] ret = Gfh_html_.rawElement
( tmp_bfr, Gfh_tag_.Id__span
, msg
, Gfh_atr_itm.New(Gfh_atr_.Bry__class, "error mw-ext-cite-error")
, Gfh_atr_itm.New(Gfh_atr_.Bry__lang , lang.Key_bry())
, Gfh_atr_itm.New(Gfh_atr_.Bry__dir , lang.Dir_ltr_bry())
);
return ret;
}
public static final byte[]
Msg__cite_link_label_group = Bry_.new_a7("cite_link_label_group-")
, Msg__cite_error = Bry_.new_a7("cite_error")
, Msg__cite_error_no_link_label_group = Bry_.new_a7("cite_error_no_link_label_group")
;
}

@ -0,0 +1,64 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.xowa.langs.msgs.*;
public class Cite_mgr_tst {
private final Cite_mgr_fxt fxt = new Cite_mgr_fxt();
@Test public void getLinkLabel_lower_alpha() {
fxt.Test__getLinkLabel("lower-alpha", 1, "a");
fxt.Test__getLinkLabel("lower-alpha", 2, "b");
fxt.Test__getLinkLabel("lower-alpha", 3, "c");
}
@Test public void getLinkLabel_upper_roman() {
fxt.Test__getLinkLabel("upper-roman", 1, "I");
fxt.Test__getLinkLabel("upper-roman", 2, "II");
fxt.Test__getLinkLabel("upper-roman", 3, "III");
}
@Test public void getLinkLabel_unknown() {
fxt.Test__getLinkLabel("unknown", 1, "unknown 1");
}
@Test public void getLinkLabel_err() {
fxt.Test__getLinkLabel("upper-roman", 4, "<span class=\"error mw-ext-cite-error\" lang=\"en\" dir=\"ltr\">Cite error: Ran out of custom link labels for group \"upper-roman\".\nDefine more in the <nowiki>[[MediaWiki:cite_link_label_group-upper-roman]]</nowiki> message.</span>");
}
}
class Cite_mgr_fxt {
private Cite_mgr mgr;
private Xowe_wiki wiki;
public Cite_mgr_fxt() {
// init cite_mgr
Xoae_app app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
this.mgr = new Cite_mgr(wiki);
// init common messages
this.Init__msg__label_grp("lower-alpha", "a b c");
this.Init__msg__label_grp("upper-roman", "I II III");
this.Init__msg(Cite_mgr.Msg__cite_error, "Cite error: ~{0}");
this.Init__msg(Cite_mgr.Msg__cite_error_no_link_label_group, "Ran out of custom link labels for group \"~{0}\".\nDefine more in the <nowiki>[[MediaWiki:~{1}]]</nowiki> message.");
}
private void Init__msg__label_grp(String key, String val) {
this.Init__msg(String_.new_u8(Cite_mgr.Msg__cite_link_label_group) + key, val);
}
private void Init__msg(String key, String val) {Init__msg(Bry_.new_u8(key), val);}
private void Init__msg(byte[] key, String val) {
Xol_msg_itm msg = wiki.Msg_mgr().Get_or_make(key);
msg.Atrs_set(Bry_.new_u8(val), false, false);
}
public void Test__getLinkLabel(String group, int offset, String expd) {
Gftest.Eq__str(expd, mgr.getLinkLabel(offset, Bry_.new_u8(group)));
}
}

@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.data_stores.*;
class Cite_xtn_data implements Gfo_data_itm {
public String Key() {return KEY;}
public void Clear() {
link_labels.Clear();
}
public Cite_link_label_mgr Link_labels() {return link_labels;} private final Cite_link_label_mgr link_labels = new Cite_link_label_mgr();
private static final String KEY = "xtn.Cite";
public static Cite_xtn_data Get_or_make(Gfo_data_store data_store) {
Cite_xtn_data rv = (Cite_xtn_data)data_store.Get_or_null(KEY);
if (rv == null) {
rv = new Cite_xtn_data();
data_store.Set(rv);
}
return rv;
}
}

@ -17,13 +17,4 @@ package gplx.xowa.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xow
public class Cite_xtn_mgr extends Xox_mgr_base {
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_a7("cite");
@Override public Xox_mgr Xtn_clone_new() {return new Cite_xtn_mgr();}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_group_default_name)) return String_.new_u8(group_default_name);
else if (ctx.Match(k, Invk_group_default_name_)) group_default_name = m.ReadBry("v");
else return super.Invk(ctx, ikey, k, m);
return this;
}
private static final String Invk_group_default_name = "group_default_name", Invk_group_default_name_ = "group_default_name_";
public static byte[] Group_default_name() {return group_default_name;} private static byte[] group_default_name = Bry_.new_a7("lower-alpha");
}

@ -19,22 +19,20 @@ import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*;
public class Ref_html_wtr {
private final Xoh_ref_list_fmtr grp_list_fmtr = new Xoh_ref_list_fmtr();
private final Bfr_arg__bry_fmtr grp_key_fmtr = Bfr_arg_.New_bry_fmtr__null(), itm_id_fmtr = Bfr_arg_.New_bry_fmtr__null(), grp_id_fmtr = Bfr_arg_.New_bry_fmtr__null();
private final Bfr_arg__bry_fmtr itm_id_fmtr = Bfr_arg_.New_bry_fmtr__null(), grp_id_fmtr = Bfr_arg_.New_bry_fmtr__null();
private final Cite_mgr mgr;
public Ref_html_wtr(Xowe_wiki wiki) {
cfg = Ref_html_wtr_cfg.new_();
mgr = new Cite_mgr(wiki);
}
public void Xnde_ref(Xoh_wtr_ctx opts, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
Ref_nde itm = (Ref_nde)xnde.Xnde_xtn();
if (itm == null) return;
if (itm.Follow_y()) return; // NOTE: "follow" is always appended to preceding ref; will never generate its own ^ a
byte[] itm_group = itm.Group();
boolean itm_group_is_default = Bry_.Eq(itm_group, Bry_.Empty) || Bry_.Eq(itm_group, Cite_xtn_mgr.Group_default_name()); // do not show "lower-alpha"; PAGE:en.w:Moon; DATE:2014-07-21
cfg.Itm_html().Bld_bfr_many(bfr
, Itm_id(itm, true)
, Grp_id(itm)
, itm_group_is_default
? itm.Idx_major() + 1
: (Object)grp_key_fmtr.Set(cfg.Itm_grp_text(), itm.Group(), itm.Idx_major() + 1)
, mgr.getLinkLabel(itm.Idx_major() + 1, itm.Group())
);
}
public Ref_html_wtr_cfg Cfg() {return cfg;} private Ref_html_wtr_cfg cfg;

@ -20,7 +20,6 @@ public class Ref_html_wtr_cfg {
public Bry_fmtr Itm_id_uid() {return itm_id_uid;} private Bry_fmtr itm_id_uid; public Ref_html_wtr_cfg Itm_id_uid_(String v) {itm_id_uid = Bry_fmtr.new_(v, "uid"); return this;}
public Bry_fmtr Itm_id_key_one() {return itm_id_key_one;} private Bry_fmtr itm_id_key_one; public Ref_html_wtr_cfg Itm_id_key_one_(String v) {itm_id_key_one = Bry_fmtr.new_(v, "itm_key", "uid", "minor"); return this;}
public Bry_fmtr Itm_id_key_many() {return itm_id_key_many;} private Bry_fmtr itm_id_key_many; public Ref_html_wtr_cfg Itm_id_key_many_(String v) {itm_id_key_many = Bry_fmtr.new_(v, "itm_key", "uid"); return this;}
public Bry_fmtr Itm_grp_text() {return itm_grp_text;} private Bry_fmtr itm_grp_text; public Ref_html_wtr_cfg Itm_grp_text_(String v) {itm_grp_text = Bry_fmtr.new_(v, "grp_key", "major"); return this;}
public Bry_fmtr Grp_html_one() {return grp_html_one;} private Bry_fmtr grp_html_one; public Ref_html_wtr_cfg Grp_html_one_(String v) {grp_html_one = Bry_fmtr.new_(v, "grp_id", "itm_id", "text"); return this;}
public Bry_fmtr Grp_html_many() {return grp_html_many;} private Bry_fmtr grp_html_many; public Ref_html_wtr_cfg Grp_html_many_(String v) {grp_html_many = Bry_fmtr.new_(v, "grp_id", "related_ids", "text"); return this;}
public Bry_fmtr Grp_html_list() {return grp_html_list;} private Bry_fmtr grp_html_list; public Ref_html_wtr_cfg Grp_html_list_(String v) {grp_html_list = Bry_fmtr.new_(v, "itm_id", "backlabel"); return this;}
@ -47,7 +46,6 @@ public class Ref_html_wtr_cfg {
rv.Itm_id_uid_ ("~{uid}");
rv.Itm_id_key_one_ ("~{itm_key}_~{uid}-~{minor}");
rv.Itm_id_key_many_ ("~{itm_key}-~{uid}");
rv.Itm_grp_text_ ("~{grp_key} ~{major}");
rv.Grp_html_one_ ("<li id=\"cite_note-~{grp_id}\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-~{itm_id}\">^</a></span> <span class=\"reference-text\">~{text}</span></li>\n");
rv.Grp_html_many_ ("<li id=\"cite_note-~{grp_id}\"><span class=\"mw-cite-backlink\">^~{related_ids}</span> <span class=\"reference-text\">~{text}</span></li>\n");
rv.Grp_html_list_ (" <sup><a href=\"#cite_ref-~{itm_id}\">~{backlabel}</a></sup>");

@ -16,7 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
package gplx.xowa.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class References_nde_group_tst {
@Before public void init() {fxt.Clear_ref_mgr();} private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Clear_ref_mgr();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Basic() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
@ -39,10 +39,10 @@ public class References_nde_group_tst {
, ""
));
}
@Test public void Lower_alpha_is_ignored() {
@Test public void Unknown() {
String expd =
String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>" // note:do not show lower-alpha; DATE:2014-07-21
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[unknown 1]</a></sup>"
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
@ -53,9 +53,9 @@ public class References_nde_group_tst {
, ""
);
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref group='lower-alpha'>x</ref>"
( "<ref group='unknown'>x</ref>"
, "<ref>y</ref>"
, "<references group='lower-alpha'/>"
, "<references group='unknown'/>"
, "<references group=''/>"
), expd);
}

Loading…
Cancel
Save