mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.7.1.1
This commit is contained in:
@@ -21,18 +21,25 @@ class Xop_comm_lxr implements Xop_lxr {
|
||||
public void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie) {core_trie.Add(Bgn_ary, this);}
|
||||
public void Init_by_lang(Xol_lang lang, ByteTrieMgr_fast core_trie) {}
|
||||
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 lhs_end = cur_pos;
|
||||
int end_pos = Bry_finder.Find_fwd(src, End_ary, cur_pos, src_len); // search for "-->" // NOTE: do not reuse cur_pos, else cur_pos may become -1 and fatal error in ctx.Msg_log() below; DATE:2014-06-08
|
||||
int rhs_bgn = end_pos;
|
||||
if (end_pos == Bry_finder.Not_found) { // "-->" not found
|
||||
ctx.Msg_log().Add_itm_none(Xop_comment_log.Eos, src, bgn_pos, cur_pos);
|
||||
cur_pos = src_len; // gobble up rest of content
|
||||
}
|
||||
else
|
||||
cur_pos = end_pos + End_len;
|
||||
cur_pos = Trim_ws_if_entire_line_is_commment(ctx, tkn_mkr, root, src, src_len, cur_pos);
|
||||
cur_pos = Trim_ws_if_entire_line_is_commment(ctx, tkn_mkr, root, src, src_len, cur_pos, lhs_end, rhs_bgn);
|
||||
ctx.Subs_add(root, tkn_mkr.Ignore(bgn_pos, cur_pos, Xop_ignore_tkn.Ignore_tid_comment));
|
||||
return cur_pos;
|
||||
}
|
||||
private static int Trim_ws_if_entire_line_is_commment(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int cur_pos) {// REF.MW:Preprocessor_DOM.php|preprocessToXml|handle comments; DATE:2014-02-24
|
||||
private static int Trim_ws_if_entire_line_is_commment(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int cur_pos, int lhs_end, int rhs_bgn) {// REF.MW:Preprocessor_DOM.php|preprocessToXml|handle comments; DATE:2014-02-24
|
||||
if ( ctx.Tid_is_popup()
|
||||
&& ctx.Parse_tid() == Xop_parser_.Parse_tid_page_wiki // note that only popup parse can generate <!-- --> that makes it to wtxt
|
||||
&& Bry_.Match(src, lhs_end, rhs_bgn, gplx.xowa.html.modules.popups.Xow_popup_parser.Comment_txt) // <!--XOWA_SKIP-->
|
||||
)
|
||||
return cur_pos; // in popup mode only do not gobble trailing \n; PAGE:en.w:Gwynedd; DATE:2014-07-01
|
||||
int nl_lhs = -1;
|
||||
int subs_len = root.Subs_len();
|
||||
for (int i = subs_len - 1; i > -1; i--) { // look bwd for "\n"
|
||||
|
||||
@@ -87,15 +87,17 @@ class Xop_under_lxr implements Xop_lxr {
|
||||
if (o == null) return ctx.Lxr_make_txt_(cur_pos); // kwd not found; EX: "TOCA__"
|
||||
int kwd_id = ((Int_obj_val)(o)).Val();
|
||||
Xop_under_lxr.Make_tkn(ctx, tkn_mkr, root, src, src_len, bgn_pos, rv, kwd_id);
|
||||
|
||||
ctx.Para().Process_block_lnki_div(); // close any existing pre's by faking div; EX:\n\s__TOC; de.w;pt.b; DATE:2014-04-07
|
||||
return rv;
|
||||
}
|
||||
public static void 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 kwd_id) {
|
||||
Xoa_page page = ctx.Cur_page();
|
||||
Xow_hdr_mgr hdr_mgr = page.Hdr_mgr();
|
||||
switch (kwd_id) {
|
||||
case Xol_kwd_grp_.Id_toc: hdr_mgr.Toc_manual_(); ctx.Subs_add(root, tkn_mkr.Under(bgn_pos, cur_pos, kwd_id)); break; // NOTE: only save under_tkn for TOC (b/c its position is needed for insertion); DATE:2013-07-01
|
||||
case Xol_kwd_grp_.Id_toc:
|
||||
hdr_mgr.Toc_manual_();
|
||||
ctx.Para().Process_block_lnki_div(); // NOTE: __TOC__ will manually place <div toc> here; simulate div in order to close any pres; EX:\n\s__TOC__; PAGE:de.w: DATE:2014-07-05
|
||||
ctx.Subs_add(root, tkn_mkr.Under(bgn_pos, cur_pos, kwd_id)); // NOTE: only save under_tkn for TOC (b/c its position is needed for insertion); DATE:2013-07-01
|
||||
break;
|
||||
case Xol_kwd_grp_.Id_forcetoc: hdr_mgr.Toc_force_(); break;
|
||||
case Xol_kwd_grp_.Id_notoc: hdr_mgr.Toc_hide_(); break;
|
||||
case Xol_kwd_grp_.Id_noeditsection: break; // ignore; not handling edit sections
|
||||
|
||||
@@ -107,16 +107,31 @@ public class Xop_under_lxr_tst {
|
||||
@Test public void Eos() { // PURPOSE: check that __ at eos doesn't fail; es.s:Luisa de Bustamante: 3; DATE:2014-02-15
|
||||
fxt.Test_parse_page_all_str("__", "__");
|
||||
}
|
||||
@Test public void Ws_preserve() { // preserve ws; DATE:2014-04-07
|
||||
@Test public void Pre_toc() { // PURPOSE: make sure that "\n\s__TOC" does not create pre; PAGE:de.w:Main_Page; DATE:2014-04-07
|
||||
fxt.Init_para_y_();
|
||||
fxt.Test_parse_page_all_str(String_.Concat_lines_nl
|
||||
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, " __TOC__ "
|
||||
, " __TOC__ " // NOTE: this should not be a pre; DATE:2014-07-05
|
||||
, "b"
|
||||
), String_.Concat_lines_nl
|
||||
( "<p>a"
|
||||
, "</p>"
|
||||
, " " // NOTE: \s should not be captured, but leaving for now
|
||||
, ""
|
||||
, "<p>b"
|
||||
, "</p>"
|
||||
));
|
||||
fxt.Init_para_n_();
|
||||
}
|
||||
@Test public void Pre_notoc() { // PURPOSE: make sure that "\n\s__NOTOC" does not create pre. note that mechanism is different from TOC; DATE:2014-07-05
|
||||
fxt.Init_para_y_();
|
||||
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, " __NOTOC__ " // NOTE: does not capture " "; confirmed against MW
|
||||
, "b"
|
||||
), String_.Concat_lines_nl
|
||||
( "<p>a"
|
||||
, "</p>"
|
||||
, " "
|
||||
, ""
|
||||
, "<p>b"
|
||||
, "</p>"
|
||||
@@ -125,9 +140,15 @@ public class Xop_under_lxr_tst {
|
||||
}
|
||||
@Test public void Hook_alt() { // PURPOSE: ja wikis use alternate __; DATE:2014-03-04
|
||||
Xow_wiki wiki = fxt.Wiki(); Xol_lang lang = wiki.Lang();
|
||||
Xol_kwd_grp kwd_grp = lang.Kwd_mgr().Get_or_new(Xol_kwd_grp_.Id_toc);
|
||||
kwd_grp.Srl_load(true, new byte[][] {Bry_.new_utf8_("__TOC__")});
|
||||
fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc, true, "__TOC__");
|
||||
wiki.Parser().Init_by_lang(lang);
|
||||
fxt.Test_parse_page_all_str("a__TOC__b", "ab");
|
||||
}
|
||||
@Test public void Hook_utf8() { // PURPOSE: ja wikis use alternate __; DATE:2014-03-04
|
||||
Xow_wiki wiki = fxt.Wiki(); Xol_lang lang = wiki.Lang();
|
||||
fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc, false, "__TOC__");
|
||||
wiki.Parser().Init_by_lang(lang);
|
||||
fxt.Test_parse_page_all_str("a__TOC__b", "ab");
|
||||
fxt.Test_parse_page_all_str("a__toc__b", "ab");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user