mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Parser.Ref: Add commented fix for ref tag in template
This commit is contained in:
parent
3023353154
commit
3441135fad
@ -50,7 +50,7 @@ public class Xob_page_wkr_cmd implements Xob_cmd {
|
||||
Err_.Noop(e);
|
||||
long dividend = fil.Fil_pos();
|
||||
if (dividend >= fil_len) dividend = fil_len - 1; // prevent % from going over 100
|
||||
String msg = Decimal_adp_.CalcPctStr(dividend, fil_len, "00.00") + "|" + String_.new_u8(page.Ttl_full_db()) + "|" + Err_.Message_gplx_log(e) + "|" + Xot_tmpl_wtr.Err_string; Xot_tmpl_wtr.Err_string = "";
|
||||
String msg = Decimal_adp_.CalcPctStr(dividend, fil_len, "00.00") + "|" + String_.new_u8(page.Ttl_full_db()) + "|" + Err_.Message_gplx_log(e);
|
||||
bldr.Usr_dlg().Log_wkr().Log_to_session(msg);
|
||||
Console_adp__sys.Instance.Write_str_w_nl(msg);
|
||||
}
|
||||
|
@ -33,8 +33,9 @@ public class Xoh_make_fxt {
|
||||
) {
|
||||
// fxt.Init_cache("en.wikipedia.org", "A.png", 0, 220, 110, 0.5, -1, -1, Bool_.Y, "B.png", 330, 110, -1, -1);
|
||||
}
|
||||
public void Test__html(String wtxt, String expd) {
|
||||
expd = String_.Replace(expd, "'", "\"");
|
||||
public void Test__html(String wtxt, String expd) {Test__html(wtxt, expd, true);}
|
||||
public void Test__html(String wtxt, String expd, boolean escape_apos) {
|
||||
if (escape_apos) expd = String_.Replace(expd, "'", "\"");
|
||||
String actl = parser_fxt.Exec__parse_to_hdump(wtxt);
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
|
@ -35,13 +35,13 @@ public class Xoh_hdr_html_tst {
|
||||
));
|
||||
}
|
||||
@Test public void Uniq() {
|
||||
byte[] uniq = fxt.Parser_fxt().Wiki().Parser_mgr().Uniq_mgr().Add(Bry_.new_a7("bcd"));
|
||||
fxt.Test__html(String_.Concat_lines_nl_skip_last
|
||||
( "== a" + String_.new_u8(uniq) + "e =="
|
||||
( "== a <math>c</math> e =="
|
||||
, "text"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<h2><span class='mw-headline' id='abcde'> abcde </span></h2>"
|
||||
( "<h2><span class=\"mw-headline\" id=\"a_c_e\"> a <span id='xowa_math_txt_0'>c</span> e </span></h2>"
|
||||
, "text"
|
||||
));
|
||||
)
|
||||
, false);
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ public class Xow_popup_parser {
|
||||
int subs_len = tmpl_root.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
tmpl_root.Subs_get(i).Tmpl_compile(tmpl_ctx, src, tmpl_props);
|
||||
return Xot_tmpl_wtr.Instance.Write_all(tmpl_ctx, tmpl_root, src);
|
||||
return Xot_tmpl_wtr.Write_all(tmpl_ctx, tmpl_root, src);
|
||||
}
|
||||
}
|
||||
class Xow_popup_parser_ {
|
||||
|
@ -46,7 +46,7 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
|
||||
int len = root.Subs_len();
|
||||
for (int i = 0; i < len; ++i)
|
||||
root.Subs_get(i).Tmpl_compile(ctx, src, tmpl_props);
|
||||
return Xot_tmpl_wtr.Instance.Write_all(ctx, root, src);
|
||||
return Xot_tmpl_wtr.Write_all(ctx, root, src);
|
||||
}
|
||||
|
||||
public byte[] Parse_text_to_html(Xop_ctx ctx, byte[] src) {
|
||||
|
@ -17,15 +17,16 @@ package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.
|
||||
import gplx.core.envs.*;
|
||||
import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.miscs.*;
|
||||
public class Xot_tmpl_wtr {
|
||||
public byte[] Write_all(Xop_ctx ctx, Xop_root_tkn root, byte[] src) {
|
||||
Bry_bfr rslt_bfr = ctx.Wiki().Utl__bfr_mkr().Get_m001();
|
||||
rslt_bfr.Reset_if_gt(Io_mgr.Len_mb);
|
||||
Write_tkn(rslt_bfr, ctx, src, src.length, root);
|
||||
return rslt_bfr.To_bry_and_rls();
|
||||
public static byte[] Write_all(Xop_ctx ctx, Xop_root_tkn root, byte[] src) {
|
||||
Bry_bfr bfr = ctx.Wiki().Utl__bfr_mkr().Get_m001().Reset_if_gt(Io_mgr.Len_mb);
|
||||
Write_tkn(bfr, ctx, src, src.length, root);
|
||||
return bfr.To_bry_and_rls();
|
||||
// byte[] rv = bfr.To_bry_and_rls();
|
||||
// return ctx.Wiki().Parser_mgr().Uniq_mgr().Parse(rv); // NOTE: noops if no UNIQs
|
||||
}
|
||||
private void Write_tkn(Bry_bfr rslt_bfr, Xop_ctx ctx, byte[] src, int src_len, Xop_tkn_itm tkn) {
|
||||
private static void Write_tkn(Bry_bfr rslt_bfr, Xop_ctx ctx, byte[] src, int src_len, Xop_tkn_itm tkn) {
|
||||
switch (tkn.Tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_root: // write each sub
|
||||
case Xop_tkn_itm_.Tid_root: // write each sub
|
||||
int subs_len = tkn.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
Xop_tkn_itm sub_tkn = tkn.Subs_get(i);
|
||||
@ -94,15 +95,13 @@ public class Xot_tmpl_wtr {
|
||||
tkn.Tmpl_evaluate(ctx, src, Xot_invk_temp.Page_is_caller.Src_(src), rslt_bfr);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Err_string = String_.new_u8(src, tkn.Src_bgn(), tkn.Src_end()) + "|" + Type_adp_.NameOf_obj(e) + "|" + Err_.Cast_or_make(e).To_str__log();
|
||||
String err_string = String_.new_u8(src, tkn.Src_bgn(), tkn.Src_end()) + "|" + Type_adp_.NameOf_obj(e) + "|" + Err_.Cast_or_make(e).To_str__log();
|
||||
if (Env_.Mode_testing())
|
||||
throw Err_.new_exc(e, "xo", Err_string);
|
||||
throw Err_.new_exc(e, "xo", err_string);
|
||||
else
|
||||
ctx.App().Usr_dlg().Warn_many("", "", "failed to write tkn: page=~{0} err=~{1}", String_.new_u8(ctx.Page().Ttl().Page_db()), Err_string);
|
||||
ctx.App().Usr_dlg().Warn_many("", "", "failed to write tkn: page=~{0} err=~{1}", String_.new_u8(ctx.Page().Ttl().Page_db()), err_string);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public static String Err_string = "";
|
||||
public static final Xot_tmpl_wtr Instance = new Xot_tmpl_wtr(); Xot_tmpl_wtr() {}
|
||||
}
|
||||
|
@ -21,9 +21,10 @@ public class Xop_uniq_mgr { // REF.MW:/parser/StripState.php
|
||||
private int idx = -1;
|
||||
public void Clear() {idx = -1; general_trie.Clear();}
|
||||
public byte[] Get(byte[] key) {return (byte[])general_trie.Match_exact(key, 0, key.length);}
|
||||
public byte[] Add(byte[] val) { // "<b>" -> "\u007fUNIQ-item-1--QINU\u007f"
|
||||
public byte[] Add(byte[] type, byte[] val) {// "<b>" -> "\u007fUNIQ-item-1--QINU\u007f"
|
||||
byte[] key = key_bfr
|
||||
.Add(Bry__uniq__add__bgn)
|
||||
.Add(Bry__uniq__bgn_w_dash)
|
||||
.Add(type).Add_byte(Byte_ascii.Dash) // EX: "ref-"
|
||||
.Add_int_variable(++idx)
|
||||
.Add(Bry__uniq__add__end).To_bry_and_clear();
|
||||
general_trie.Add_bry_bry(key, val);
|
||||
@ -36,10 +37,20 @@ public class Xop_uniq_mgr { // REF.MW:/parser/StripState.php
|
||||
int cur = 0;
|
||||
int len = src.length;
|
||||
while (cur < len) {
|
||||
// look for \u007fUNIQ
|
||||
int uniq_bgn = Bry_find_.Find_fwd(src, Bry__uniq__add__bgn, cur);
|
||||
// find "\u007fUNIQ-"
|
||||
int uniq_bgn = Bry_find_.Find_fwd(src, Bry__uniq__bgn_w_dash, cur);
|
||||
if (uniq_bgn == Bry_find_.Not_found) break;
|
||||
int uniq_end = Bry_find_.Find_fwd(src, Bry__uniq__add__end, uniq_bgn);
|
||||
|
||||
// find "-"; EX: ref-
|
||||
int tmp_pos = uniq_bgn;
|
||||
tmp_pos = Bry_find_.Find_fwd(src, Byte_ascii.Dash, tmp_pos, len);
|
||||
if (tmp_pos == Bry_find_.Not_found) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "uniq_mgr:unable to find 2nd dash; src=~{0}", src);
|
||||
return src;
|
||||
}
|
||||
|
||||
// find end
|
||||
int uniq_end = Bry_find_.Find_fwd(src, Bry__uniq__add__end, tmp_pos);
|
||||
if (uniq_end == Bry_find_.Not_found) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "uniq_mgr:unable to convert uniq; src=~{0}", src);
|
||||
return src;
|
||||
@ -111,10 +122,10 @@ public class Xop_uniq_mgr { // REF.MW:/parser/StripState.php
|
||||
key_bfr.Clear();
|
||||
return rv;
|
||||
}
|
||||
private final static byte[]
|
||||
|
||||
private static final byte[]
|
||||
Bry__uniq__bgn = Bry_.new_a7("\u007fUNIQ")
|
||||
// , Bry__uniq__end = Bry_.new_a7("-QINU\u007f")
|
||||
, Bry__uniq__add__bgn = Bry_.new_a7("\u007fUNIQ-item-")
|
||||
, Bry__uniq__bgn_w_dash = Bry_.new_a7("\u007fUNIQ-")
|
||||
, Bry__uniq__add__end = Bry_.new_a7("--QINU\u007f")
|
||||
;
|
||||
}
|
||||
|
@ -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.xowa.parsers.uniqs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xop_uniq_mgr__parse__tst {
|
||||
private final Xop_fxt fxt = Xop_fxt.New_app_html();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@Test public void Ref_becomes_UNIQ() {
|
||||
// String wikitext = "<ref>b</ref>";
|
||||
// fxt.Init_defn_add("test", "{{#ifeq:{{{1}}}|a" + wikitext + "c|fail|pass}}"); // fail if {{{1}}} is still wikitext; should be UNIQ
|
||||
// fxt.Test__parse__tmpl_to_html("{{test|a" + wikitext + "c}}", "pass");
|
||||
}
|
||||
}
|
@ -65,7 +65,7 @@ class Xop_uniq_mgr__fxt {
|
||||
Gftest.Eq__str(expd, String_.new_a7(mgr.Uniq_bry_new()), "unique_bry");
|
||||
}
|
||||
public void Test__add(String raw, String expd) {
|
||||
Gftest.Eq__str(expd, String_.new_a7(mgr.Add(Bry_.new_a7(raw))), "add");
|
||||
Gftest.Eq__str(expd, String_.new_a7(mgr.Add(Bry_.new_a7("item"), Bry_.new_a7(raw))), "add");
|
||||
}
|
||||
public void Test__get(String key, String expd) {
|
||||
Gftest.Eq__str(expd, String_.new_a7(mgr.Get(Bry_.new_a7(key))), "get");
|
||||
|
@ -105,14 +105,33 @@ public class Xop_xnde_tkn extends Xop_tkn_itm_base implements Xop_tblw_tkn {
|
||||
break;
|
||||
default: // ignore tags except for xtn; NOTE: Xtn tags are part of tagRegy_wiki_tmpl stage
|
||||
if (tag.Xtn()) {
|
||||
bfr.Add_mid(src, tag_open_bgn, tag_open_end); // write tag_bgn
|
||||
for (int i = 0; i < subs_len; i++) // always evaluate subs; handle <poem>{{{1}}}</poem>; DATE:2014-03-03
|
||||
this.Subs_get(i).Tmpl_evaluate(ctx, src, caller, bfr);
|
||||
bfr.Add_mid(src, tag_close_bgn, tag_close_end); // write tag_end
|
||||
if (tag_close_bgn == Int_.Min_value) {// xtn is unclosed; add a </xtn> else rest of page will be gobbled; PAGE:en.w:Provinces_and_territories_of_Canada DATE:2014-11-13
|
||||
bfr.Add(tag.Xtn_end_tag());
|
||||
bfr.Add(Byte_ascii.Gt_bry);
|
||||
Bry_bfr cur_bfr = bfr;
|
||||
// boolean is_tmpl_mode = ctx.Wiki().Parser_mgr().Ctx().Parse_tid() == Xop_parser_tid_.Tid__tmpl;
|
||||
// if (is_tmpl_mode) {
|
||||
// cur_bfr = ctx.Wiki().Utl__bfr_mkr().Get_m001().Reset_if_gt(Io_mgr.Len_mb);
|
||||
// }
|
||||
|
||||
// write tag_bgn; EX: <poem>
|
||||
cur_bfr.Add_mid(src, tag_open_bgn, tag_open_end);
|
||||
|
||||
// write subs; must always evaluate subs; handle <poem>{{{1}}}</poem>; DATE:2014-03-03
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
this.Subs_get(i).Tmpl_evaluate(ctx, src, caller, cur_bfr);
|
||||
|
||||
// write tag_end; EX: </poem>
|
||||
cur_bfr.Add_mid(src, tag_close_bgn, tag_close_end);
|
||||
|
||||
// xtn is unclosed; add a </xtn> else rest of page will be gobbled; PAGE:en.w:Provinces_and_territories_of_Canada DATE:2014-11-13
|
||||
if (tag_close_bgn == Int_.Min_value) {
|
||||
cur_bfr.Add(tag.Xtn_end_tag());
|
||||
cur_bfr.Add(Byte_ascii.Gt_bry);
|
||||
}
|
||||
|
||||
// if (is_tmpl_mode) {
|
||||
// byte[] val = cur_bfr.To_bry_and_clear();
|
||||
// byte[] key = ctx.Wiki().Parser_mgr().Uniq_mgr().Add(tag.Name_bry(), val);
|
||||
// bfr.Add(key);
|
||||
// }
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ class Xomath_html_wtr {
|
||||
private final Bry_fmt
|
||||
fmt__latex = Bry_fmt.Auto( "<img id='xowa_math_img_~{math_idx}' src='' width='' height=''/><span id='xowa_math_txt_~{math_idx}'>~{math_text}</span>")
|
||||
, fmt__mathjax = Bry_fmt.Auto("<span id='xowa_math_txt_~{math_idx}'>~{math_text}</span>");
|
||||
private static final byte[] Bry__math = Bry_.new_a7("math");
|
||||
|
||||
public void Write(Bry_bfr bfr, Xop_ctx ctx, Xop_xnde_tkn xnde, byte[] src, boolean is_latex, boolean enabled) {
|
||||
// init vars
|
||||
@ -66,7 +67,7 @@ class Xomath_html_wtr {
|
||||
}
|
||||
|
||||
// write html: <span>math_expr</math>
|
||||
byte[] unique_bry = wiki.Parser_mgr().Uniq_mgr().Add(math_bry);
|
||||
byte[] unique_bry = wiki.Parser_mgr().Uniq_mgr().Add(Bry__math, math_bry);
|
||||
Bry_fmt fmt = is_latex ? fmt__latex : fmt__mathjax;
|
||||
fmt.Bld_many(tmp_bfr, uid, unique_bry);
|
||||
bfr.Add_bfr_and_clear(tmp_bfr);
|
||||
|
Loading…
Reference in New Issue
Block a user