mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Parser: Fix anchorencode for trailing lnki [#373]
This commit is contained in:
parent
dd750c6c4e
commit
91a100f154
@ -47,6 +47,7 @@ public class Xop_lnki_tkn extends Xop_tkn_itm_base implements gplx.xowa.wikis.pa
|
|||||||
public int Html_uid() {return html_uid;} public void Html_uid_(int v) {html_uid = v;} private int html_uid;
|
public int Html_uid() {return html_uid;} public void Html_uid_(int v) {html_uid = v;} private int html_uid;
|
||||||
public int Pipe_count() {return pipe_count;} private int pipe_count;
|
public int Pipe_count() {return pipe_count;} private int pipe_count;
|
||||||
public boolean Pipe_count_is_zero() {return pipe_count++ == 0;}
|
public boolean Pipe_count_is_zero() {return pipe_count++ == 0;}
|
||||||
|
public int Brack_end_pos() {return brack_end_pos;} public void Brack_end_pos_(int v) {this.brack_end_pos = v;} private int brack_end_pos;
|
||||||
public boolean Xtn_sites_link() {return xtn_sites_link;} public void Xtn_sites_link_(boolean v) {xtn_sites_link = v;} private boolean xtn_sites_link;
|
public boolean Xtn_sites_link() {return xtn_sites_link;} public void Xtn_sites_link_(boolean v) {xtn_sites_link = v;} private boolean xtn_sites_link;
|
||||||
public Xoh_file_fmtr Lnki_file_wkr() {return lnki_file_wkr;} public void Lnki_file_wkr_(Xoh_file_fmtr v) {lnki_file_wkr = v;} private Xoh_file_fmtr lnki_file_wkr;
|
public Xoh_file_fmtr Lnki_file_wkr() {return lnki_file_wkr;} public void Lnki_file_wkr_(Xoh_file_fmtr v) {lnki_file_wkr = v;} private Xoh_file_fmtr lnki_file_wkr;
|
||||||
public byte[] Target;
|
public byte[] Target;
|
||||||
|
@ -46,8 +46,9 @@ public class Xop_lnki_wkr implements Xop_ctx_wkr, Xop_arg_wkr {
|
|||||||
return Xop_lnki_wkr_.Invalidate_lnki(ctx, src, root, lnki, bgn_pos);
|
return Xop_lnki_wkr_.Invalidate_lnki(ctx, src, root, lnki, bgn_pos);
|
||||||
if (lnki.Ns_id() != Xow_ns_.Tid__main && Bry_.Len_eq_0(lnki.Ttl().Page_txt())) // handle anchor-only pages; EX:[[File:#A]] PAGE:en.w:Spindale,_North_Carolina; DATE:2015-12-28
|
if (lnki.Ns_id() != Xow_ns_.Tid__main && Bry_.Len_eq_0(lnki.Ttl().Page_txt())) // handle anchor-only pages; EX:[[File:#A]] PAGE:en.w:Spindale,_North_Carolina; DATE:2015-12-28
|
||||||
return Xop_lnki_wkr_.Invalidate_lnki(ctx, src, root, lnki, bgn_pos);
|
return Xop_lnki_wkr_.Invalidate_lnki(ctx, src, root, lnki, bgn_pos);
|
||||||
if (Xop_lnki_wkr_.Adjust_for_brack_end_len_of_3(ctx, tkn_mkr, root, src, src_len, cur_pos, lnki)) // convert "]]]" into "]" + "]]", not "]]" + "]"
|
if (Xop_lnki_wkr_.Adjust_for_brack_end_len_of_3(ctx, tkn_mkr, root, src, src_len, cur_pos, lnki)) // convert "]]]" into "]" + "]]", not "]]" + "]"; EX: "[[a|[b]]]"
|
||||||
++cur_pos; // position "]]" at end of "]]]"
|
++cur_pos; // position "]]" at end of "]]]"
|
||||||
|
lnki.Brack_end_pos_(cur_pos - Xop_tkn_.Lnki_end_len); // brack_end_pos defined as first "]" in "]]"; ISSUE#:373; DATE:2019-03-10
|
||||||
cur_pos = Xop_lnki_wkr_.Chk_for_tail(ctx.Lang(), src, cur_pos, src_len, lnki);
|
cur_pos = Xop_lnki_wkr_.Chk_for_tail(ctx.Lang(), src, cur_pos, src_len, lnki);
|
||||||
lnki.Src_end_(cur_pos); // NOTE: must happen after Chk_for_tail; redundant with above, but above needed b/c of returns
|
lnki.Src_end_(cur_pos); // NOTE: must happen after Chk_for_tail; redundant with above, but above needed b/c of returns
|
||||||
root.Subs_del_after(lnki.Tkn_sub_idx() + 1); // all tkns should now be converted to args in owner; delete everything in root
|
root.Subs_del_after(lnki.Tkn_sub_idx() + 1); // all tkns should now be converted to args in owner; delete everything in root
|
||||||
|
@ -77,17 +77,20 @@ public class Pfunc_anchorencode_mgr { // TS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static void Lnki(byte[] src, Xop_lnki_tkn lnki, Bry_bfr tmp_bfr) {
|
private static void Lnki(byte[] src, Xop_lnki_tkn lnki, Bry_bfr tmp_bfr) {
|
||||||
int src_end = lnki.Src_end();
|
int trg_end = lnki.Trg_tkn().Src_end(); // pos after last trg char; EX: "]" in "[[A]]"; "|" in "[[A|b]]"
|
||||||
int trg_end = lnki.Trg_tkn().Src_end();
|
if (lnki.Pipe_count_is_zero()) { // trg only; EX: [[A]]
|
||||||
|
|
||||||
if (trg_end == src_end - Xop_tkn_.Lnki_end_len) { // only trg
|
|
||||||
int trg_bgn = lnki.Trg_tkn().Src_bgn();
|
int trg_bgn = lnki.Trg_tkn().Src_bgn();
|
||||||
if (lnki.Ttl().ForceLiteralLink()) ++trg_bgn; // literal link; skip colon; EX: [[:a]] -> a
|
if (lnki.Ttl().ForceLiteralLink()) // literal link; skip colon; EX: [[:a]] -> a
|
||||||
|
++trg_bgn;
|
||||||
|
|
||||||
|
// add trg only
|
||||||
tmp_bfr.Add_mid(src, trg_bgn, trg_end);
|
tmp_bfr.Add_mid(src, trg_bgn, trg_end);
|
||||||
}
|
}
|
||||||
else {
|
else { // trg + caption + other; EX: [[A|b]]; [[File:A.png|thumb|caption]]
|
||||||
tmp_bfr.Add_mid(src, trg_end + 1, src_end - Xop_tkn_.Lnki_end_len); //+1 is len of pipe
|
tmp_bfr.Add_mid(src, trg_end + 1, lnki.Brack_end_pos()); //+1 is len of pipe
|
||||||
}
|
}
|
||||||
|
if (lnki.Tail_bgn() != -1)
|
||||||
|
tmp_bfr.Add_mid(src, lnki.Tail_bgn(), lnki.Tail_end());
|
||||||
}
|
}
|
||||||
private static void Xnde(Xop_ctx ctx, byte[] src, Xop_xnde_tkn xnde, Bry_bfr tmp_bfr) {
|
private static void Xnde(Xop_ctx ctx, byte[] src, Xop_xnde_tkn xnde, Bry_bfr tmp_bfr) {
|
||||||
int subs_len = xnde.Subs_len();
|
int subs_len = xnde.Subs_len();
|
||||||
|
@ -24,6 +24,7 @@ public class Pfunc_anchorencode_tst {
|
|||||||
@Test public void Lnki_trg() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a [[b]] c}}" , "{{test}}" , "a_b_c");}
|
@Test public void Lnki_trg() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a [[b]] c}}" , "{{test}}" , "a_b_c");}
|
||||||
@Test public void Lnki_caption() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a [[b|c]] c}}" , "{{test}}" , "a_c_c");}
|
@Test public void Lnki_caption() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a [[b|c]] c}}" , "{{test}}" , "a_c_c");}
|
||||||
@Test public void Lnki_file() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a [[Image:b|thumb|c]] d}}" , "{{test}}" , "a_thumb.7Cc_d");}
|
@Test public void Lnki_file() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a [[Image:b|thumb|c]] d}}" , "{{test}}" , "a_thumb.7Cc_d");}
|
||||||
|
@Test public void Lnki_trailing() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a [[b]]c d}}" , "{{test}}" , "a_bc_d");}
|
||||||
@Test public void Xnde() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a <i>b</i> c}}" , "{{test}}" , "a_b_c");}
|
@Test public void Xnde() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a <i>b</i> c}}" , "{{test}}" , "a_b_c");}
|
||||||
@Test public void Html_ncr() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a " b}}" , "{{test}}" , "a_.22_b");}
|
@Test public void Html_ncr() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a " b}}" , "{{test}}" , "a_.22_b");}
|
||||||
@Test public void Html_ref() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a " b}}" , "{{test}}" , "a_.22_b");}
|
@Test public void Html_ref() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a " b}}" , "{{test}}" , "a_.22_b");}
|
||||||
|
@ -47,11 +47,12 @@ public class Scrib_lib_uri implements Scrib_lib {
|
|||||||
public boolean AnchorEncode(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
public boolean AnchorEncode(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
byte[] raw_bry = args.Pull_bry(0);
|
byte[] raw_bry = args.Pull_bry(0);
|
||||||
Bry_bfr bfr = core.Wiki().Utl__bfr_mkr().Get_b512();
|
Bry_bfr bfr = core.Wiki().Utl__bfr_mkr().Get_b512();
|
||||||
// Pfunc_anchorencode.Func_init(core.Ctx());
|
try {
|
||||||
Pfunc_anchorencode.Anchor_encode(bfr, core.Ctx(), raw_bry);
|
Pfunc_anchorencode.Anchor_encode(bfr, core.Ctx(), raw_bry);
|
||||||
// Bry_bfr tmp_bfr = core.Wiki().Utl__bfr_mkr().Get_b512();
|
|
||||||
// tmp_bfr.Clear_and_rls();
|
|
||||||
return rslt.Init_obj(bfr.To_str_and_rls());
|
return rslt.Init_obj(bfr.To_str_and_rls());
|
||||||
|
} finally {
|
||||||
|
bfr.Mkr_rls();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public boolean Url_func(Scrib_proc_args args, Scrib_proc_rslt rslt, byte url_tid) {
|
public boolean Url_func(Scrib_proc_args args, Scrib_proc_rslt rslt, byte url_tid) {
|
||||||
Xowe_wiki wiki = core.Wiki();
|
Xowe_wiki wiki = core.Wiki();
|
||||||
|
Loading…
Reference in New Issue
Block a user