mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.7.4.1
This commit is contained in:
@@ -16,7 +16,7 @@ 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; import gplx.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.xtns.pfuncs.ttls.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.html.*; import gplx.xowa.xtns.pfuncs.ttls.*;
|
||||
public class Xop_lnki_tkn extends Xop_tkn_itm_base {
|
||||
@Override public byte Tkn_tid() {return tkn_tid;} private byte tkn_tid = Xop_tkn_itm_.Tid_lnki;
|
||||
public void Tkn_tid_to_txt() {tkn_tid = Xop_tkn_itm_.Tid_txt;}
|
||||
@@ -46,6 +46,7 @@ public class Xop_lnki_tkn extends Xop_tkn_itm_base {
|
||||
public int Html_id() {return html_id;} public Xop_lnki_tkn Html_id_(int v) {html_id = v; return this;} private int html_id;
|
||||
public int Pipe_count() {return pipe_count;} private int pipe_count;
|
||||
public boolean Pipe_count_is_zero() {return pipe_count++ == 0;}
|
||||
public Xoh_lnki_file_wkr Lnki_file_wkr() {return lnki_file_wkr;} public void Lnki_file_wkr_(Xoh_lnki_file_wkr v) {lnki_file_wkr = v;} private Xoh_lnki_file_wkr lnki_file_wkr;
|
||||
public byte[] Ttl_ary() {
|
||||
return ttl.ForceLiteralLink() || nsId != Xow_ns_.Id_main // if [[:]] or non-main (Category, Template)
|
||||
? ttl.Full_txt() // use full_txt (no initial colon; capitalize first)
|
||||
|
||||
@@ -30,30 +30,19 @@ public class Xop_lnki_wkr implements Xop_ctx_wkr, Xop_arg_wkr {
|
||||
lnki.Tkn_tid_to_txt();
|
||||
ctx.Msg_log().Add_itm_none(Xop_misc_log.Eos, src, lnki.Src_bgn(), lnki.Src_end());
|
||||
}
|
||||
private static final byte[] Brack_end_bry = Bry_.new_ascii_("]");
|
||||
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) {
|
||||
if (ctx.Cur_tkn_tid() == Xop_tkn_itm_.Tid_lnke) { // if lnke then take 1st ] in "]]" and use it close lnke
|
||||
int lnke_end_pos = bgn_pos + 1;
|
||||
ctx.Lnke().MakeTkn_end(ctx, tkn_mkr, root, src, src_len, bgn_pos, lnke_end_pos);
|
||||
return lnke_end_pos;
|
||||
}
|
||||
if ( cur_pos < src_len // bounds check
|
||||
&& src[cur_pos] == Byte_ascii.Brack_end // is next char after "]]", "]"; i.e.: "]]]"; PAGE:en.w:Aubervilliers DATE:2014-06-25
|
||||
) {
|
||||
int nxt_pos = cur_pos + 1;
|
||||
if ( nxt_pos == src_len // allow "]]]EOS"
|
||||
|| ( nxt_pos < src_len // bounds check
|
||||
&& src[nxt_pos] != Byte_ascii.Brack_end // is next char after "]]]", "]"; i.e.: not "]]]]"; PAGE:ru.w:Меркатале_ин_Валь_ди_Песа; DATE:2014-02-04
|
||||
)
|
||||
|
||||
) {
|
||||
root.Subs_add(tkn_mkr.Bry(bgn_pos, bgn_pos + 1, Brack_end_bry)); // add "]" as bry
|
||||
++bgn_pos; ++cur_pos; // position "]]" at end of "]]]"
|
||||
}
|
||||
int stack_pos = ctx.Stack_idx_typ(Xop_tkn_itm_.Tid_lnki);
|
||||
if (stack_pos == Xop_ctx.Stack_not_found) return ctx.Lxr_make_txt_(cur_pos); // "]]" found but no "[[" in stack; return literal "]]"
|
||||
Xop_lnki_tkn lnki = (Xop_lnki_tkn)ctx.Stack_pop_til(root, src, stack_pos, false, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_lnki_end);
|
||||
if (Xop_lnki_wkr_.Adjust_for_brack_end_len_of_3(ctx, tkn_mkr, root, src, src_len, cur_pos, lnki)) { // convert "]]]" into "]" + "]]", not "]]" + "]"
|
||||
root.Subs_add(tkn_mkr.Bry(bgn_pos, bgn_pos + 1, Byte_ascii.Brack_end_bry)); // add "]" as bry
|
||||
++bgn_pos; ++cur_pos; // position "]]" at end of "]]]"
|
||||
}
|
||||
int lvl_pos = ctx.Stack_idx_typ(Xop_tkn_itm_.Tid_lnki);
|
||||
if (lvl_pos == Xop_ctx.Stack_not_found) return ctx.Lxr_make_txt_(cur_pos); // "]]" found but no "[[" in stack; interpet "]]" literally
|
||||
Xop_lnki_tkn lnki = (Xop_lnki_tkn)ctx.Stack_pop_til(root, src, lvl_pos, false, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_lnki_end);
|
||||
if (!arg_bldr.Bld(ctx, tkn_mkr, this, Xop_arg_wkr_.Typ_lnki, root, lnki, bgn_pos, cur_pos, lnki.Tkn_sub_idx() + 1, root.Subs_len(), src))
|
||||
return Xop_lnki_wkr_.Invalidate_lnki(ctx, src, root, lnki, bgn_pos);
|
||||
cur_pos = Xop_lnki_wkr_.Chk_for_tail(ctx.Lang(), src, cur_pos, src_len, lnki);
|
||||
@@ -162,7 +151,7 @@ public class Xop_lnki_wkr implements Xop_ctx_wkr, Xop_arg_wkr {
|
||||
lnki.Upright_(number_parser.AsDec().XtoDouble());
|
||||
}
|
||||
else // no =; EX: [[Image:a|upright]]
|
||||
lnki.Upright_(1);
|
||||
lnki.Upright_(gplx.xowa.files.Xof_img_size.Upright_default_marker);// NOTE: was incorrectly hardcoded as 1; DATE:2014-07-23
|
||||
break;
|
||||
case Xop_lnki_arg_parser.Tid_noicon: lnki.Media_icon_n_(); break;
|
||||
case Xop_lnki_arg_parser.Tid_page: Xop_lnki_wkr_.Page_parse(ctx, src, number_parser, lnki, arg); break;
|
||||
@@ -266,4 +255,19 @@ class Xop_lnki_wkr_ {
|
||||
else
|
||||
lnki.Thumbtime_(fracs / TimeSpanAdp_.Ratio_f_to_s);
|
||||
}
|
||||
public static boolean Adjust_for_brack_end_len_of_3(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int cur_pos, Xop_lnki_tkn lnki) {
|
||||
if ( cur_pos < src_len // bounds check
|
||||
&& src[cur_pos] == Byte_ascii.Brack_end // is next char after "]]", "]"; i.e.: "]]]"; PAGE:en.w:Aubervilliers DATE:2014-06-25
|
||||
) {
|
||||
int nxt_pos = cur_pos + 1;
|
||||
if ( nxt_pos == src_len // allow "]]]EOS"
|
||||
|| ( nxt_pos < src_len // bounds check
|
||||
&& src[nxt_pos] != Byte_ascii.Brack_end // is next char after "]]]", "]"; i.e.: not "]]]]"; PAGE:ru.w:Меркатале_ин_Валь_ди_Песа; DATE:2014-02-04
|
||||
)
|
||||
) {
|
||||
return lnki.Ttl() != null; // only change "]]]" to "]" + "]]" if lnki is not title; otherwise [[A]]] -> "A]" which will be invalid; PAGE:en.w: Tall_poppy_syndrome DATE:2014-07-23
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public class Xop_lnki_wkr__basic_tst {
|
||||
|
||||
@Test public void Image_upright() {
|
||||
fxt.Test_parse_page_wiki("[[Image:a|upright=.123]]" , fxt.tkn_lnki_().Upright_(.123));
|
||||
fxt.Test_parse_page_wiki("[[Image:a|upright]]" , fxt.tkn_lnki_().Upright_(1)); // no eq tokn
|
||||
fxt.Test_parse_page_wiki("[[Image:a|upright]]" , fxt.tkn_lnki_().Upright_(gplx.xowa.files.Xof_img_size.Upright_default_marker)); // no eq tokn
|
||||
fxt.Test_parse_page_wiki("[[Image:a|upright=.42190046219457]]", fxt.tkn_lnki_().Upright_(.42190046219457)); // many decimal places breaks upright
|
||||
fxt.Init_log_(Xop_lnki_log.Upright_val_is_invalid)
|
||||
.Test_parse_page_wiki("[[Image:a|upright=y]]" , fxt.tkn_lnki_().Upright_(-1)); // invalid
|
||||
|
||||
@@ -26,6 +26,10 @@ public class Xop_lnki_wkr__uncommon_tst {
|
||||
@Test public void Single_bracket() { // PURPOSE: handle [[A|[b]]] PAGE:en.w:Aubervilliers DATE:2014-06-25
|
||||
fxt.Test_html_full_str("[[A|[B]]]", "<a href=\"/wiki/A\">[B]</a>");
|
||||
}
|
||||
@Test public void Triple_bracket() { // PURPOSE: "]]]" shouldn't invalidate tkn; PAGE:en.w:Tall_poppy_syndrome; DATE:2014-07-23
|
||||
fxt.Test_parse_page_all_str("[[A]]]" , "<a href=\"/wiki/A\">A</a>]"); // title only
|
||||
fxt.Test_parse_page_all_str("[[A|B]]]" , "<a href=\"/wiki/A\">B]</a>"); // title + caption; note that ] should be outside </a> b/c MW has more logic that says "if caption starts with '['", but leaving as is; DATE:2014-07-23
|
||||
}
|
||||
@Test public void Multiple_captions() { // PURPOSE: multiple captions should be concatenated (used to only take first); EX:zh.d:维基词典:Unicode字符索引/0000–0FFF; DATE:2014-05-05
|
||||
fxt.Test_parse_page_all_str("[[A|B|C|D]]" , "<a href=\"/wiki/A\">B|C|D</a>");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user