1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.7.1.1'

This commit is contained in:
gnosygnu
2016-07-03 22:41:56 -04:00
parent 1a4ca00c0b
commit 36584a0cc2
220 changed files with 4762 additions and 2627 deletions

View File

@@ -72,7 +72,7 @@ public class Xoh_html_wtr {
break;
case Xop_tkn_itm_.Tid_ignore: break;
case Xop_tkn_itm_.Tid_html_ncr: Html_ncr(ctx, hctx, bfr, src, (Xop_amp_tkn_num)tkn); break;
case Xop_tkn_itm_.Tid_html_ref: Html_ref(ctx, hctx, bfr, src, (Xop_amp_tkn_txt)tkn); break;
case Xop_tkn_itm_.Tid_html_ref: Html_ref(ctx, hctx, bfr, src, (Xop_amp_tkn_ent)tkn); break;
case Xop_tkn_itm_.Tid_hr: Hr(ctx, hctx, bfr, src, (Xop_hr_tkn)tkn); break;
case Xop_tkn_itm_.Tid_apos: Apos(ctx, hctx, bfr, src, (Xop_apos_tkn)tkn); break;
case Xop_tkn_itm_.Tid_lnki: lnki_wtr.Write_lnki(bfr, hctx, src, (Xop_lnki_tkn)tkn); break;
@@ -101,7 +101,7 @@ public class Xoh_html_wtr {
public void Html_ncr(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_amp_tkn_num tkn) {
bfr.Add_byte(Byte_ascii.Amp).Add_byte(Byte_ascii.Hash).Add_int_variable(tkn.Val()).Add_byte(Byte_ascii.Semic); // NOTE: do not literalize, else browser may not display multi-char bytes properly; EX:   gets added as   not as {192,160}; DATE:2013-12-09
}
public void Html_ref(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_amp_tkn_txt tkn) {
public void Html_ref(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_amp_tkn_ent tkn) {
if (tkn.Itm_is_custom()) // used by <nowiki>; EX:<nowiki>&#60;</nowiki> -> &xowa_lt; DATE:2014-11-07
tkn.Print_literal(bfr);
else

View File

@@ -62,14 +62,15 @@ public class Xoh_html_wtr_escaper {
i = match_pos - 1;
break;
case Xop_amp_trie_itm.Tid_num_dec:
case Xop_amp_trie_itm.Tid_num_hex: // ncr: dec/hex
boolean pass = amp_mgr.Parse_as_int(itm_tid == Xop_amp_trie_itm.Tid_num_hex, src, end, i, match_pos);
int end_pos = amp_mgr.Rslt_pos();
if (pass) { // parse worked; embed entire ncr
case Xop_amp_trie_itm.Tid_num_hex: // ncr: dec/hex; escape if invalid
Xop_amp_mgr_rslt rslt = new Xop_amp_mgr_rslt();
boolean pass = amp_mgr.Parse_ncr(rslt, itm_tid == Xop_amp_trie_itm.Tid_num_hex, src, end, i, match_pos);
if (pass) { // parse worked; embed entire ncr; EX: "&#123;"
int end_pos = rslt.Pos();
bfr.Add_mid(src, i, end_pos);
i = end_pos - 1;
}
else // parse failed; escape and continue
else // parse failed; escape and continue; EX: "&#a!b;"
bfr.Add(Gfh_entity_.Amp_bry);
break;
default: throw Err_.new_unhandled(itm_tid);

View File

@@ -106,26 +106,26 @@ public class Xoh_make_mgr {
case Xoh_make_trie_.Tid__gallery_box_max: {
Xohd_img_itm__gallery_mgr gly = (Xohd_img_itm__gallery_mgr)hpg.Gallery_itms().Get_by(uid);
if (gly != null) { // -1 means no box_max
byte[] style = Gallery_html_wtr_.Fmtr__ul__style.Bld_bry_many(tmp_bfr, gly.Box_max());
byte[] style = Gallery_mgr_wtr_.Fmtr__ul__style.Bld_bry_many(tmp_bfr, gly.Box_max());
Gfh_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Gfh_atr_.Bry__style, style);
}
return rv;
}
case Xoh_make_trie_.Tid__gallery_box_w: {
Xohd_img_itm__gallery_itm gly = (Xohd_img_itm__gallery_itm)img;
byte[] style = Gallery_html_wtr_.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Box_w());
byte[] style = Gallery_mgr_wtr_.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Box_w());
Gfh_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Gfh_atr_.Bry__style, style);
return rv;
}
case Xoh_make_trie_.Tid__gallery_img_w: {
Xohd_img_itm__gallery_itm gly = (Xohd_img_itm__gallery_itm)img;
byte[] style = Gallery_html_wtr_.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Img_w());
byte[] style = Gallery_mgr_wtr_.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Img_w());
Gfh_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Gfh_atr_.Bry__style, style);
return rv;
}
case Xoh_make_trie_.Tid__gallery_img_pad: {
Xohd_img_itm__gallery_itm gly = (Xohd_img_itm__gallery_itm)img;
byte[] style = Gallery_html_wtr_.hdump_img_pad_fmtr.Bld_bry_many(tmp_bfr, gly.Img_pad());
byte[] style = Gallery_mgr_wtr_.hdump_img_pad_fmtr.Bld_bry_many(tmp_bfr, gly.Img_pad());
Gfh_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Gfh_atr_.Bry__style, style);
return rv;
}

View File

@@ -23,7 +23,7 @@ public class Xoh_make_trie_ {
, Tid__hiero_dir = 7, Tid__gallery_box_max = 8, Tid__gallery_box_w = 9, Tid__gallery_img_w = 10, Tid__gallery_img_pad = 11
, Tid__toc = 12, Tid__hdr = 13
;
public static final byte[]
public static final byte[]
Bry__dir = Bry_.new_a7("~{xowa_dir}")
, Bry__img = Bry_.new_a7("xowa_img=\"")
, Bry__img_style = Bry_.new_a7("xowa_img_style=\"")
@@ -37,7 +37,7 @@ public class Xoh_make_trie_ {
// , Bry__gallery_img_pad = Bry_.new_a7("xowa_gly_img_pad='")
, Bry__toc = Bry_.new_a7("~{xowa_toc}")
;
public static final byte[]
public static final byte[]
A_href_bgn = Bry_.new_a7("/wiki/File:")
, Bry_img_style_bgn = Bry_.new_a7("style='width:")
, Bry_img_style_end = Bry_.new_a7("px;'")

View File

@@ -22,6 +22,7 @@ public class Bfr_arg__hatr_id implements Bfr_arg_clearable {
private final byte[] bry; private int num;
public Bfr_arg__hatr_id(byte[] atr_key, byte[] bry) {this.bry = bry; this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(atr_key);}
public Bfr_arg__hatr_id Set(int num) {this.num = num; return this;}
public byte[] Get_id_val() {return Bry_.Add(bry, Int_.To_bry(num));}
public void Bfr_arg__clear() {num = -1;}
public boolean Bfr_arg__missing() {return num == -1;}
public void Bfr_arg__add(Bry_bfr bfr) {

View File

@@ -0,0 +1,38 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.langs.htmls.*;
class Bfr_arg__elem__capt implements gplx.core.brys.Bfr_arg_clearable {
private byte[] capt;
public Bfr_arg__elem__capt() {
this.Clear();
}
public void Capt_(byte[] v) {this.capt = v;}
public void Clear() {capt = null;}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return capt == null;}
public void Bfr_arg__add(Bry_bfr bfr) { // EX: '\n<li class="gallerycaption">Z</li>'
if (Bfr_arg__missing()) return;
bfr.Add_byte_nl();
bfr.Add(Gfh_tag_.Li_lhs_bgn); // '<li'
Gfh_atr_.Add(bfr, Gfh_atr_.Bry__class, Xoh_gly_grp_data.Atr__cls__gallerycaption); // ' class="gallerycaption"'
bfr.Add_byte(Byte_ascii.Angle_end); // '>'
bfr.Add(capt);
bfr.Add(Gfh_tag_.Li_rhs); // '</li>'
}
}

View File

@@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.xowa.htmls.core.wkrs.bfr_args.*;
class Bfr_arg__hatr__style implements gplx.core.brys.Bfr_arg {
private final byte[] atr_bgn;
private int max_w, w;
private byte[] xtra_cls;
public Bfr_arg__hatr__style(byte[] key) {
this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(key);
this.Clear();
}
public void Set_args(int max_w, int w, byte[] xtra_cls) {this.max_w = max_w; this.w = w; this.xtra_cls = xtra_cls;}
public void Clear() {max_w = 0; w = 0; xtra_cls = null;}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return max_w == 0 && xtra_cls == null;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(atr_bgn);
if (max_w > 0) {
bfr.Add(Style__frag_1);
bfr.Add_int_variable(max_w);
bfr.Add(Style__frag_3);
}
if (w > 0) {
bfr.Add_byte_space();
bfr.Add(Style__frag_2);
bfr.Add_int_variable(w);
bfr.Add(Style__frag_3);
}
if (xtra_cls != null) {
bfr.Add(xtra_cls);
}
bfr.Add_byte_quote();
}
private static final byte[]
Style__frag_1 = Bry_.new_a7("max-width:")
, Style__frag_2 = Bry_.new_a7("_width:")
, Style__frag_3 = Bry_.new_a7("px;")
;
}

View File

@@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.xowa.htmls.core.wkrs.bfr_args.*;
class Bfr_arg__hatr__xogly implements gplx.core.brys.Bfr_arg_clearable {
private final byte[] atr_bgn;
private int xnde_w, xnde_h, xnde_per_row;
public Bfr_arg__hatr__xogly() {
this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(gplx.xowa.xtns.gallery.Gallery_mgr_wtr.Bry__data_xogly);
this.Clear();
}
public void Set_args(int xnde_w, int xnde_h, int xnde_per_row) {
this.xnde_w = xnde_w; this.xnde_h = xnde_h; this.xnde_per_row = xnde_per_row;
}
public void Clear() {xnde_w = xnde_h = xnde_per_row = -1;}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return false;} // NOTE: do not check if "xnde_w == -1 && xnde_h == -1 && xnde_per_row == -1" else will fail hzip diff; DATE:2016-07-02
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(atr_bgn);
bfr.Add_int_variable(xnde_w).Add_byte_pipe();
bfr.Add_int_variable(xnde_h).Add_byte_pipe();
bfr.Add_int_variable(xnde_per_row);
bfr.Add_byte_quote();
}
}

View File

@@ -22,31 +22,38 @@ import gplx.xowa.htmls.core.hzips.*;
import gplx.xowa.xtns.gallery.*;
public class Xoh_gly_grp_data implements Gfh_class_parser_wkr, Gfh_style_wkr { // FUTURE:add gallerycaption
private final List_adp itms_list = List_adp_.New();
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public int Gly_tid() {return gly_tid;} private int gly_tid;
public int Ul_style_max_w() {return ul_style_max_w;} private int ul_style_max_w;
public int Ul_style_w() {return ul_style_w;} private int ul_style_w;
public int Xtra_atr_bgn() {return xtra_atr_bgn;} private int xtra_atr_bgn;
public int Xtra_atr_end() {return xtra_atr_end;} private int xtra_atr_end;
public boolean Xtra_atr_exists() {return xtra_atr_end > xtra_atr_bgn;}
public int Xtra_cls_bgn() {return xtra_cls_bgn;} private int xtra_cls_bgn;
public int Xtra_cls_end() {return xtra_cls_end;} private int xtra_cls_end;
public boolean Xtra_cls_exists() {return xtra_cls_end > xtra_cls_bgn;}
public int Xtra_style_bgn() {return xtra_style_bgn;} private int xtra_style_bgn;
public int Xtra_style_end() {return xtra_style_end;} private int xtra_style_end;
public boolean Xtra_style_exists() {return xtra_style_end > xtra_style_bgn;}
public int Itms__len() {return itms_list.Count();}
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public int Gly_tid() {return gly_tid;} private int gly_tid;
public int Xnde_w() {return xnde_w;} private int xnde_w;
public int Xnde_h() {return xnde_h;} private int xnde_h;
public int Xnde_per_row() {return xnde_per_row;} private int xnde_per_row;
public int Ul_style_max_w() {return ul_style_max_w;} private int ul_style_max_w;
public int Ul_style_w() {return ul_style_w;} private int ul_style_w;
public int Xtra_atr_bgn() {return xtra_atr_bgn;} private int xtra_atr_bgn;
public int Xtra_atr_end() {return xtra_atr_end;} private int xtra_atr_end;
public boolean Xtra_atr_exists() {return xtra_atr_end > xtra_atr_bgn;}
public int Xtra_cls_bgn() {return xtra_cls_bgn;} private int xtra_cls_bgn;
public int Xtra_cls_end() {return xtra_cls_end;} private int xtra_cls_end;
public boolean Xtra_cls_exists() {return xtra_cls_end > xtra_cls_bgn;}
public int Xtra_style_bgn() {return xtra_style_bgn;} private int xtra_style_bgn;
public int Xtra_style_end() {return xtra_style_end;} private int xtra_style_end;
public boolean Xtra_style_exists() {return xtra_style_end > xtra_style_bgn;}
public int Capt_bgn() {return capt_bgn;} private int capt_bgn;
public int Capt_end() {return capt_end;} private int capt_end;
public int Itms__len() {return itms_list.Count();}
public Xoh_gly_itm_data Itms__get_at(int i) {return (Xoh_gly_itm_data)itms_list.Get_at(i);}
private void Clear() {
this.gly_tid = Byte_.Max_value_127;
this.ul_style_max_w = ul_style_w = 0;
this.xtra_atr_bgn = xtra_atr_end = xtra_cls_bgn = xtra_cls_end = xtra_style_bgn = xtra_style_end = -1;
this.xnde_per_row = xnde_w = xnde_h = capt_bgn = capt_end = -1;
itms_list.Clear();
}
public boolean Parse1(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Gfh_tag_rdr tag_rdr, Gfh_tag ul_head) {
this.Clear();
this.src_bgn = ul_head.Src_bgn();
if (!Parse_xogly(src, tag_rdr, ul_head)) return false;
if (!Parse_cls (src, tag_rdr, ul_head)) return false;
if (!Parse_style(src, tag_rdr, ul_head)) return false;
Parse_ul_atrs(src, tag_rdr, ul_head);
@@ -55,10 +62,16 @@ public class Xoh_gly_grp_data implements Gfh_class_parser_wkr, Gfh_style_wkr { /
li_head = tag_rdr.Tag__peek_fwd_head();
if (li_head.Name_id() != Gfh_tag_.Id__li) break; // no more <li>; break;
// FUTURE: galleries with gallerycaption will cause gallery to write raw; instate code below, but would need to then serialize "gallerycaption"; PAGE:en.d:A DATE:2016-06-24
// if (li_head.Atrs__cls_has(Atr__cls__gallerycaption)) {// skip <li class='gallerycaption'>A</li>
// li_head = tag_rdr.Tag__move_fwd_head();
// li_head = tag_rdr.Tag__peek_fwd_head();
// }
if (li_head.Atrs__cls_has(Atr__cls__gallerycaption)) {// skip <li class='gallerycaption'>A</li>
// extract caption between <li></li>
li_head = tag_rdr.Tag__move_fwd_head();
this.capt_bgn = li_head.Src_end();
Gfh_tag li_tail = tag_rdr.Tag__move_fwd_tail(li_head.Name_id());
this.capt_end = li_tail.Src_bgn();
// move tag_rdr to next <li>
li_head = tag_rdr.Tag__peek_fwd_head();
}
if (!li_head.Atrs__cls_has(Atr__cls__gallerybox)) return false;
tag_rdr.Pos_(li_head.Src_end());
Xoh_gly_itm_data itm_parser = new Xoh_gly_itm_data();
@@ -71,6 +84,25 @@ public class Xoh_gly_grp_data implements Gfh_class_parser_wkr, Gfh_style_wkr { /
hdoc_wkr.On_gly(this);
return true;
}
private boolean Parse_xogly(byte[] src, Gfh_tag_rdr tag_rdr, Gfh_tag ul_head) {
Gfh_atr atr = ul_head.Atrs__get_by_or_empty(Gallery_mgr_wtr.Bry__data_xogly);
byte[] val = atr.Val(); int val_len = val.length;
if (val_len == 0) return true; // ignore missing "data-xogly"
int pos = 0;
for (int i = 0; i < 3; ++i) {
int bgn = pos;
int end = Bry_find_.Find_fwd(val, Byte_ascii.Pipe, bgn + 1, val_len);
if (end == Bry_find_.Not_found) end = val_len;
int num = Bry_.To_int_or(val, bgn, end, -1);
pos = end + 1;
switch (i) {
case 0: xnde_w = num; break;
case 1: xnde_h = num; break;
case 2: xnde_per_row = num; break;
}
}
return true;
}
private boolean Parse_cls(byte[] src, Gfh_tag_rdr tag_rdr, Gfh_tag ul_head) {
Gfh_atr ul_cls = ul_head.Atrs__get_by_or_empty(Gfh_atr_.Bry__class);
Gfh_class_parser_.Parse(src, ul_cls.Val_bgn(), ul_cls.Val_end(), this);
@@ -89,9 +121,7 @@ public class Xoh_gly_grp_data implements Gfh_class_parser_wkr, Gfh_style_wkr { /
int atrs_len = ul_head.Atrs__len();
for (int i = 0; i < atrs_len; ++i) {
Gfh_atr hatr = ul_head.Atrs__get_at(i);
if (Bry_.Eq(hatr.Key(), Gfh_atr_.Bry__class)) {}
else if (Bry_.Eq(hatr.Key(), Gfh_atr_.Bry__style)) {}
else {
if (atrs_ignored.Get_by_bry(hatr.Key()) == null) {
if (xtra_atr_bgn == -1) this.xtra_atr_bgn = hatr.Atr_bgn();
this.xtra_atr_end = hatr.Atr_end();
}
@@ -104,7 +134,7 @@ public class Xoh_gly_grp_data implements Gfh_class_parser_wkr, Gfh_style_wkr { /
else if (Bry_.Match(src, val_bgn, val_bgn + Atr__cls__mw_gallery.length, Atr__cls__mw_gallery) // starts with 'mw-gallery-'
&& val_pos == 8) { // occurs after "gallery "
int tid_bgn = val_bgn + Atr__cls__mw_gallery.length;
this.gly_tid = Gallery_mgr_base_.Hash.Get_as_byte_or(src, tid_bgn, val_end, Byte_.Max_value_127);
this.gly_tid = Gallery_mgr_base_.To_tid_or(src, tid_bgn, val_end, Byte_.Max_value_127);
return true;
}
else {
@@ -135,8 +165,16 @@ public class Xoh_gly_grp_data implements Gfh_class_parser_wkr, Gfh_style_wkr { /
return true;
}
public static final byte[] Atr__cls__gallery = Bry_.new_a7("gallery");
private static final byte[] Atr__cls__mw_gallery = Bry_.new_a7("mw-gallery-"), Atr__cls__gallerybox = Bry_.new_a7("gallerybox")
// , Atr__cls__gallerycaption = Bry_.new_a7("gallerycaption")
private static final byte[] Atr__cls__mw_gallery = Bry_.new_a7("mw-gallery-"), Atr__cls__gallerybox = Bry_.new_a7("gallerybox")
, Style__max_width = Bry_.new_a7("max-width"), Style___width = Bry_.new_a7("_width")
;
public static final byte[] Atr__cls__gallerycaption = Bry_.new_a7("gallerycaption");
private static final Hash_adp_bry atrs_ignored = Make_atrs_ignored();
private static Hash_adp_bry Make_atrs_ignored() {
Hash_adp_bry rv = Hash_adp_bry.ci_a7();
rv.Add_as_key_and_val(Gfh_atr_.Bry__class);
rv.Add_as_key_and_val(Gfh_atr_.Bry__style);
rv.Add_as_key_and_val(Gallery_mgr_wtr.Bry__data_xogly);
return rv;
}
}

View File

@@ -20,21 +20,26 @@ import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.wkrs.bfr_args.*;
class Xoh_gly_grp_wtr implements Bfr_arg {
private final Bfr_arg_clearable[] arg_ary;
private final Bfr_arg__hatr_id ul_id = Bfr_arg__hatr_id.New_id("xogly_li_");
private final Bfr_arg__hatr_gly_style ul_style = new Bfr_arg__hatr_gly_style(Gfh_atr_.Bry__style);
private final Bfr_arg__hatr_id ul_id = Bfr_arg__hatr_id.New_id("xogly_ul_");
private final Bfr_arg__hatr__style ul_style = new Bfr_arg__hatr__style(Gfh_atr_.Bry__style);
private final Bfr_arg__hatr__xogly ul_xogly = new Bfr_arg__hatr__xogly();
private final Bfr_arg__elem__capt li_capt = new Bfr_arg__elem__capt();
private byte[] ul_cls, xtra_cls, xtra_atr_bry, ul_nl;
private final Xoh_gly_itm_list_wtr itm_list_wtr = new Xoh_gly_itm_list_wtr();
public Xoh_gly_grp_wtr() {
arg_ary = new Bfr_arg_clearable[] {ul_id};
arg_ary = new Bfr_arg_clearable[] {ul_id, ul_xogly, li_capt};
}
public void Init(boolean mode_is_diff, int id, byte[] cls, int ul_style_max_w, int ul_style_w, byte[] xtra_cls, byte[] xtra_style_bry, byte[] xtra_atr_bry, Xoh_gly_itm_wtr[] ary) {
public void Init(boolean mode_is_diff, int id, int xnde_w, int xnde_h, int xnde_per_row, byte[] cls, int ul_style_max_w, int ul_style_w
, byte[] xtra_cls, byte[] xtra_style_bry, byte[] xtra_atr_bry, byte[] capt, Xoh_gly_itm_wtr[] ary) {
this.Clear();
if (!mode_is_diff)
ul_id.Set(id);
ul_xogly.Set_args(xnde_w, xnde_h, xnde_per_row);
this.ul_cls = cls;
this.xtra_cls = xtra_cls == null ? Bry_.Empty : Bry_.Add(Byte_ascii.Space_bry, xtra_cls);
this.xtra_atr_bry = xtra_atr_bry;
this.ul_nl = ary.length == 0 ? Bry_.Empty : Byte_ascii.Nl_bry; // TIDY: <ul></ul> should be on same line if 0 items
li_capt.Capt_(capt);
itm_list_wtr.Init(ary);
ul_style.Set_args(ul_style_max_w, ul_style_w, xtra_style_bry);
}
@@ -48,11 +53,11 @@ class Xoh_gly_grp_wtr implements Bfr_arg {
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return false;}
public void Bfr_arg__add(Bry_bfr bfr) {
fmtr.Bld_bfr_many(bfr, ul_id, ul_cls, xtra_cls, ul_style, xtra_atr_bry, itm_list_wtr, ul_nl);
fmtr.Bld_bfr_many(bfr, ul_id, ul_xogly, ul_cls, xtra_cls, ul_style, xtra_atr_bry, li_capt, itm_list_wtr, ul_nl);
}
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<ul~{id} class=\"gallery mw-gallery-~{cls}~{xtra_cls}\"~{style}~{xtra_atr}>~{itms}~{ul_nl}</ul>"
), "id", "cls", "xtra_cls", "style", "xtra_atr", "itms", "ul_nl");
( "<ul~{id}~{xogly} class=\"gallery mw-gallery-~{cls}~{xtra_cls}\"~{style}~{xtra_atr}>~{capt}~{itms}~{ul_nl}</ul>"
), "id", "xogly", "cls", "xtra_cls", "style", "xtra_atr", "capt", "itms", "ul_nl");
}
class Xoh_gly_itm_list_wtr implements Bfr_arg {
private Xoh_gly_itm_wtr[] ary; private int ary_len;
@@ -72,40 +77,3 @@ class Xoh_gly_itm_list_wtr implements Bfr_arg {
}
}
}
class Bfr_arg__hatr_gly_style implements Bfr_arg {
private final byte[] atr_bgn;
private int max_w, w;
private byte[] xtra_cls;
public Bfr_arg__hatr_gly_style(byte[] key) {
this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(key);
this.Clear();
}
public void Set_args(int max_w, int w, byte[] xtra_cls) {this.max_w = max_w; this.w = w; this.xtra_cls = xtra_cls;}
public void Clear() {max_w = 0; w = 0; xtra_cls = null;}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return max_w == 0 && xtra_cls == null;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(atr_bgn);
if (max_w > 0) {
bfr.Add(Style__frag_1);
bfr.Add_int_variable(max_w);
bfr.Add(Style__frag_3);
}
if (w > 0) {
bfr.Add_byte_space();
bfr.Add(Style__frag_2);
bfr.Add_int_variable(w);
bfr.Add(Style__frag_3);
}
if (xtra_cls != null) {
bfr.Add(xtra_cls);
}
bfr.Add_byte_quote();
}
private static final byte[]
Style__frag_1 = Bry_.new_a7("max-width:")
, Style__frag_2 = Bry_.new_a7("_width:")
, Style__frag_3 = Bry_.new_a7("px;")
;
}

View File

@@ -17,9 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*;
public class Xoh_gly_html__dump__tst {
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
@Before public void init() {fxt.Clear();}
public class Xoh_gly_html__dump__tst {
@Before public void init() {fxt.Clear();} private final Xoh_make_fxt fxt = new Xoh_make_fxt();
@Test public void Basic() {
fxt.Test__html(String_.Concat_lines_nl_skip_last
( "<gallery>"
@@ -27,7 +26,7 @@ public class Xoh_gly_html__dump__tst {
, "File:B.png|B1"
, "</gallery>"
), String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, " <li class='gallerybox' style='width:155px;'>"
, " <div style='width:155px;'>"
, " <div class='thumb' style='width:150px;'>"
@@ -56,4 +55,52 @@ public class Xoh_gly_html__dump__tst {
, " </li>"
, "</ul>"));
}
@Test public void Atrs() {
fxt.Test__html(String_.Concat_lines_nl_skip_last
( "<gallery perrow='5' widths='200' heights='300'>"
, "File:A.png|A1"
, "</gallery>"
), String_.Concat_lines_nl_skip_last
( "<ul data-xogly='200|300|5' class='gallery mw-gallery-traditional' style='max-width:1215px; _width:1215px;'>"
, " <li class='gallerybox' style='width:235px;'>"
, " <div style='width:235px;'>"
, " <div class='thumb' style='width:230px;'>"
, " <div style='margin:15px auto;'>"
, " <a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xowa-title=\"A.png\" data-xoimg='0|200|300|-1|-1|-1' src='' width='0' height='0' alt=''/></a>"
, " </div>"
, " </div>"
, " <div class='gallerytext'><p>A1"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, "</ul>"));
}
@Test public void Packed() {
fxt.Test__html(String_.Concat_lines_nl_skip_last
( "<gallery mode='packed'>"
, "File:A.png|A1"
, "</gallery>"
), String_.Concat_lines_nl_skip_last
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-packed'>"
, " <li class='gallerybox' style='width:1302px;'>"
, " <div style='width:1302px;'>"
, " <div class='thumb' style='width:1300px;'>"
, " <div style='margin:0px auto;'>"
, " <a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xowa-title=\"A.png\" data-xoimg='0|1950|180|-1|-1|-1' src='' width='0' height='0' alt=''/></a>"
, " </div>"
, " </div>"
, " <div class='gallerytext'><p>A1"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, "</ul>"));
}
// case Gallery_xnde_atrs.Mode_tid: mode = Gallery_mgr_base_.Get_or_traditional(xatr.Val_as_bry()); break;
// case Gallery_xnde_atrs.Perrow_tid: itms_per_row = xatr.Val_as_int_or(Null); break;
// case Gallery_xnde_atrs.Widths_tid: itm_w = xatr.Val_as_int_or(Null); break;
// case Gallery_xnde_atrs.Heights_tid: itm_h = xatr.Val_as_int_or(Null); break;
}

View File

@@ -30,19 +30,27 @@ public class Xoh_gly_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
public Gfo_poolable_itm Encode1(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_gly_grp_data data = (Xoh_gly_grp_data)data_obj;
int ul_style_max_w = data.Ul_style_max_w(), ul_style_w = data.Ul_style_w();
boolean ul_style_w_diff = flag_bldr.Set_as_bool(Flag__ul__style_w_diff , ul_style_max_w != ul_style_w);
boolean xtra_atr = flag_bldr.Set_as_bool(Flag__ul__xtra_atr , data.Xtra_atr_exists());
boolean xtra_cls = flag_bldr.Set_as_bool(Flag__ul__xtra_cls , data.Xtra_cls_exists());
boolean xtra_style = flag_bldr.Set_as_bool(Flag__ul__xtra_style , data.Xtra_style_exists());
boolean xnde_w = flag_bldr.Set_as_bool(Flag__xnde__w , data.Xnde_w() != -1);
boolean xnde_h = flag_bldr.Set_as_bool(Flag__xnde__h , data.Xnde_h() != -1);
boolean xnde_per_row = flag_bldr.Set_as_bool(Flag__xnde__per_row , data.Xnde_per_row() != -1);
boolean capt_exists = flag_bldr.Set_as_bool(Flag__xnde__caption , data.Capt_bgn() != -1);
boolean ul_style_w_diff = flag_bldr.Set_as_bool(Flag__ul__style_w_diff , ul_style_max_w != ul_style_w);
boolean xtra_atr = flag_bldr.Set_as_bool(Flag__ul__xtra_atr , data.Xtra_atr_exists());
boolean xtra_cls = flag_bldr.Set_as_bool(Flag__ul__xtra_cls , data.Xtra_cls_exists());
boolean xtra_style = flag_bldr.Set_as_bool(Flag__ul__xtra_style , data.Xtra_style_exists());
flag_bldr.Set(Flag__gly_tid, data.Gly_tid());
int itms_len = data.Itms__len();
bfr.Add(hook);
Gfo_hzip_int_.Encode(1, bfr, flag_bldr.Encode());
Gfo_hzip_int_.Encode(1, bfr, ul_style_max_w);
if (xnde_w) Gfo_hzip_int_.Encode(4, bfr, data.Xnde_w());
if (xnde_h) Gfo_hzip_int_.Encode(4, bfr, data.Xnde_h());
if (xnde_per_row) Gfo_hzip_int_.Encode(1, bfr, data.Xnde_per_row());
if (ul_style_w_diff) Gfo_hzip_int_.Encode(1, bfr, ul_style_w);
if (xtra_cls) bfr.Add_hzip_mid(src, data.Xtra_cls_bgn(), data.Xtra_cls_end());
if (xtra_style) bfr.Add_hzip_mid(src, data.Xtra_style_bgn(), data.Xtra_style_end());
if (xtra_atr) bfr.Add_hzip_mid(src, data.Xtra_atr_bgn(), data.Xtra_atr_end());
if (xtra_cls) bfr.Add_hzip_mid(src, data.Xtra_cls_bgn(), data.Xtra_cls_end());
if (xtra_style) bfr.Add_hzip_mid(src, data.Xtra_style_bgn(), data.Xtra_style_end());
if (xtra_atr) bfr.Add_hzip_mid(src, data.Xtra_atr_bgn(), data.Xtra_atr_end());
if (capt_exists) bfr.Add_hzip_mid(src, data.Capt_bgn(), data.Capt_end());
Gfo_hzip_int_.Encode(1, bfr, itms_len);
for (int i = 0; i < itms_len; ++i) {
Xoh_gly_itm_data itm_parser = data.Itms__get_at(i);
@@ -59,49 +67,70 @@ public class Xoh_gly_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
}
public void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
int flag = rdr.Read_hzip_int(1); flag_bldr.Decode(flag);
boolean ul_style_w_diff = flag_bldr.Get_as_bool(Flag__ul__style_w_diff);
boolean xtra_atr = flag_bldr.Get_as_bool(Flag__ul__xtra_atr);
boolean xtra_cls = flag_bldr.Get_as_bool(Flag__ul__xtra_cls);
boolean xtra_style = flag_bldr.Get_as_bool(Flag__ul__xtra_style);
byte cls_tid = flag_bldr.Get_as_byte(Flag__gly_tid);
byte[] cls_bry = Gallery_mgr_base_.Get_bry_by_tid(cls_tid);
boolean xnde_w_exists = flag_bldr.Get_as_bool(Flag__xnde__w);
boolean xnde_h_exists = flag_bldr.Get_as_bool(Flag__xnde__h);
boolean xnde_per_row_exists = flag_bldr.Get_as_bool(Flag__xnde__per_row);
boolean capt_exists = flag_bldr.Get_as_bool(Flag__xnde__caption);
boolean ul_style_w_diff = flag_bldr.Get_as_bool(Flag__ul__style_w_diff);
boolean xtra_atr = flag_bldr.Get_as_bool(Flag__ul__xtra_atr);
boolean xtra_cls = flag_bldr.Get_as_bool(Flag__ul__xtra_cls);
boolean xtra_style = flag_bldr.Get_as_bool(Flag__ul__xtra_style);
byte cls_tid = flag_bldr.Get_as_byte(Flag__gly_tid);
byte[] cls_bry = Gallery_mgr_base_.To_bry(cls_tid);
int ul_style_max_w = rdr.Read_hzip_int(1);
int xnde_w = xnde_w_exists ? rdr.Read_hzip_int(4) : -1;
int xnde_h = xnde_h_exists ? rdr.Read_hzip_int(4) : -1;
int xnde_per_row = xnde_per_row_exists ? rdr.Read_hzip_int(1) : -1;
int ul_style_w = ul_style_w_diff ? rdr.Read_hzip_int(1) : ul_style_max_w;
byte[] xtra_cls_bry = xtra_cls ? rdr.Read_bry_to(): null;
byte[] xtra_style_bry = xtra_style ? rdr.Read_bry_to(): null;
byte[] xtra_atr_bry = xtra_atr ? rdr.Read_bry_to(): null;
byte[] capt = capt_exists ? rdr.Read_bry_to(): null;
int li_len = rdr.Read_hzip_int(1);
int uid = hctx.Uid__gly__nxt();
Xoh_gly_itm_wtr[] itm_ary = new Xoh_gly_itm_wtr[li_len];
int li_nth = li_len - 1;
for (int i = 0; i < li_len; ++i) {
// init wtr for <li>
Xoh_gly_itm_wtr itm_wtr = new Xoh_gly_itm_wtr();
itm_ary[i] = itm_wtr;
int li_w = rdr.Read_hzip_int(1);
int div_1_w = rdr.Read_hzip_int(1);
int div_2_margin = rdr.Read_hzip_int(1);
int div_3_margin = rdr.Read_hzip_int(1);
byte capt_tid = (byte)(rdr.Read_byte() - gplx.core.encoders.Base85_.A7_offset);
byte[] capt_bry = rdr.Read_bry_to();
Xoh_data_itm img_data = hctx.Pool_mgr__data().Get_by_tid(Xoh_hzip_dict_.Tid__img);
Xoh_hzip_wkr img_hzip = hctx.Pool_mgr__hzip().Mw__img();
img_hzip.Decode1(bfr, hdoc_wkr, hctx, hpg, rdr, src, src_bgn, src_end, img_data);
((gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_data)img_data).Img_is_gallery_(true);
itm_wtr.Img_wtr().Init_by_decode(hpg, hctx, src, img_data);
itm_wtr.Init(hctx.Mode_is_diff(), itm_wtr.Img_wtr().Fsdb_itm().Html_uid(), li_w, div_1_w, div_2_margin, capt_tid, capt_bry);
// init wtr for <img>
itm_wtr.Img_wtr().Init_by_decode(hpg, hctx, src, img_data);
Xof_fsdb_itm fsdb_itm = itm_wtr.Img_wtr().Fsdb_itm();
fsdb_itm.Html_elem_tid_(Xof_html_elem.Tid_gallery_v2);
fsdb_itm.Html_img_wkr_(itm_wtr);
itm_wtr.Init(hctx.Mode_is_diff(), cls_tid, xnde_w, xnde_h, xnde_per_row, fsdb_itm.Html_uid(), i, li_nth, li_w, div_1_w, div_3_margin, capt_tid, capt_bry);
// release
img_data.Pool__rls();
img_hzip.Pool__rls();
}
grp_wtr.Init(hctx.Mode_is_diff(), uid, cls_bry, ul_style_max_w, ul_style_w, xtra_cls_bry, xtra_style_bry, xtra_atr_bry, itm_ary);
}
grp_wtr.Init(hctx.Mode_is_diff(), uid, xnde_w, xnde_h, xnde_per_row, cls_bry, ul_style_max_w, ul_style_w, xtra_cls_bry, xtra_style_bry, xtra_atr_bry, capt, itm_ary);
grp_wtr.Bfr_arg__add(bfr);
hpg.Xtn__gallery_exists_y_();
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_gly_hzip rv = new Xoh_gly_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_(1, 1, 1, 1, 3);
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_(1, 1, 1, 1, 1, 1, 1, 1, 3);
private static final int // SERIALIZED
Flag__ul__style_w_diff = 0
, Flag__ul__xtra_atr = 1
, Flag__ul__xtra_cls = 2
, Flag__ul__xtra_style = 3
, Flag__gly_tid = 4
Flag__xnde__w = 0
, Flag__xnde__h = 1
, Flag__xnde__per_row = 2
, Flag__xnde__caption = 3
, Flag__ul__style_w_diff = 4
, Flag__ul__xtra_atr = 5
, Flag__ul__xtra_cls = 6
, Flag__ul__xtra_style = 7
, Flag__gly_tid = 8
;
}

View File

@@ -21,7 +21,7 @@ public class Xoh_gly_hzip__basic__tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_();
@Test public void Basic() {
fxt.Test__bicode("~'!{,L#{\"g{\"b0!A1~!1A.png~9\"D\"D{\"g{\"b0!B1~!1B.png~9\"D\"Dabc", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -46,7 +46,7 @@ public class Xoh_gly_hzip__basic__tst {
}
@Test public void Clear_state() { // page # wasn't being cleared between gallery itms; PAGE:en.w:Almagest; DATE:2016-01-05
fxt.Test__bicode("~'!{,L#{\"g{\"b0!A1~!1A.png~{\"d\"D\"D!#{\"g{\"b0!B1~!1B.png~{\"d\"D\"D!$abc", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -71,7 +71,23 @@ public class Xoh_gly_hzip__basic__tst {
}
@Test public void Extra_cls() { // PURPOSE: handle extra cls; EX: <gallery class='abc'>
fxt.Test__bicode("~'1!cls1 cls2~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional cls1 cls2'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional cls1 cls2'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xowa-title='A.png' data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>A1</p>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>"));
}
@Test public void Caption() { // handle <li class='gallerycaption'>A</li>; PAGE:en.d:a; DATE:2016-06-24
fxt.Test__bicode("~'{\"L!Z\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerycaption'>Z</li>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -84,26 +100,9 @@ public class Xoh_gly_hzip__basic__tst {
, "</li>"
, "</ul>"));
}
// FUTURE: galleries with gallerycaption will cause gallery to write raw; instate code below, but would need to then serialize "gallerycaption"; PAGE:en.d:A DATE:2016-06-24
//@Test public void Caption() { // handle <li class='gallerycaption'>A</li>; PAGE:en.d:a; DATE:2016-06-24
// fxt.Test__bicode("~'!!\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
// ( "<ul class='gallery mw-gallery-traditional'>"
// , "<li class='gallerycaption'>A</li>"
// , "<li class='gallerybox' style='width:155px;'>"
// , "<div style='width:155px;'>"
// , "<div class='thumb' style='width:150px;'>"
// , "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xowa-title='A.png' data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
// , "</div>"
// , "<div class='gallerytext'>"
// , "<p>A1</p>"
// , "</div>"
// , "</div>"
// , "</li>"
// , "</ul>"));
//}
@Test public void Extra_cls__gallery() { // handle redundant gallery; EX: <gallery class='gallery'>; PAGE:en.w:Butuan; DATE:2016-01-05
fxt.Test__bicode("~'1!gallery~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional gallery'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional gallery'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -118,7 +117,7 @@ public class Xoh_gly_hzip__basic__tst {
}
@Test public void Xtra_atr() { // PURPOSE: handle extra atr; EX: <gallery id='abc'>
fxt.Test__bicode("~'A! id=\"abc\"\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' id='abc'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' id='abc'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -136,7 +135,7 @@ public class Xoh_gly_hzip__basic__tst {
( "~'!!\"{\"g{\"b0!A1<br>"
, "~!1A.png~9\"D\"D"
), String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -152,6 +151,31 @@ public class Xoh_gly_hzip__basic__tst {
}
@Test public void Tidy__empty() { // PURPOSE: no items should place </ul> on same line
fxt.Test__bicode("~'!!!", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'></ul>")); // TIDY: <ul></ul> should be on same line if 0 items
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'></ul>")); // TIDY: <ul></ul> should be on same line if 0 items
}
@Test public void Xnde_atrs() {
fxt.Test__bicode("~'{6({,L!!#?!!$N&#{\"g{\"b0!A1~!1A.png~9\"D\"D{\"g{\"b0!B1~!1B.png~9\"D\"Dabc", String_.Concat_lines_nl_skip_last
( "<ul data-xogly='200|300|5' class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xowa-title='A.png' data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>A1</p>"
, "</div>"
, "</div>"
, "</li>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:B.png' class='image' xowa_title='B.png'><img data-xowa-title='B.png' data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>B1</p>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>abc"));
}
}

View File

@@ -21,7 +21,7 @@ public class Xoh_gly_hzip__caption__tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_();
@Test public void Capt_is_empty() { // PURPOSE: handle empty caption
fxt.Test__bicode("~'!!#{\"g{\"b0#~!1A.png~9\"D\"D{\"g{\"b0#!1A.png9\"D\"D<p>abc</p>", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -44,7 +44,7 @@ public class Xoh_gly_hzip__caption__tst {
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
( "~'!!\"{\"g{\"b0\"<b><i>A1</i></b>"
, "~!1A.png~9\"D\"D"), String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -63,7 +63,7 @@ public class Xoh_gly_hzip__caption__tst {
, "b</p>"
, "<p><br>"
, "~!1A.png~9\"D\"D"), String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -84,7 +84,7 @@ public class Xoh_gly_hzip__caption__tst {
( "~'!!\"{\"g{\"b>\"<div class=\"center\"><a href=\"/wiki/B.png\" class=\"image\" xowa_title=\"B.png\"><img data-xowa-title=\"A.png\" data-xoimg=\"0|120|-1|-1|-1|-1\" src=\"\" width=\"0\" height=\"0\" alt=\"\"></a></div>"
, "abc~\"\\A.png~#9\"D\"D"
), String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -105,7 +105,7 @@ public class Xoh_gly_hzip__caption__tst {
, "b"
, "~\"\\A.png~#9\"D\"D")
, String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"

View File

@@ -21,7 +21,7 @@ public class Xoh_gly_hzip__style__tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_();
@Test public void Style__no_max_width() { // PURPOSE: if no perrow=# then no "style='max-width:###; _width:###;'"
fxt.Test__bicode("~'!!\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -36,7 +36,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__no_width() { // PURPOSE: if "_width" omitted, do not add back; EX: style="max-width:648px; margin:auto; background:transparent;"; PAGE:en.w:Wikipedia:Village_pump_(technical)/Archive_86 DATE:2016-01-12
fxt.Test__bicode("~'i{,L! color:blue;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px; color:blue;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:978px; color:blue;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -51,7 +51,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__max_width_duped() { // PURPOSE: if max-width duped, do not delete 2nd; EX: style="max-width:648px; color:blue; max-width:648px;"; PAGE:en.w:Wikipedia:Village_pump_(technical)/Archive_86 DATE:2016-01-12
fxt.Test__bicode("~'){(Z max-width:648px; color:blue;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:652px; _width:652px; max-width:648px; color:blue;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:652px; _width:652px; max-width:648px; color:blue;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -66,7 +66,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__append() { // PURPOSE: handle appended style; EX: <gallery perrow=4 style='color:blue; float:left;'>
fxt.Test__bicode("~'){,L color:blue; float:left;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px; color:blue; float:left;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px; color:blue; float:left;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -81,7 +81,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__invalid_unclosed() { // handle broken styles; EX: <gallery style='center'>
fxt.Test__bicode("~'9!center~center~\"{\"g{\"bl!abc~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional center' style='center'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional center' style='center'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -97,7 +97,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__extra_colon() { // handle broken styles; EX: <gallery style='a:b:c:d;' PAGE:en.w:Bronze_Horseman DATE:2016-01-05
fxt.Test__bicode("~'9!center~color:red:float:right;~\"{\"g{\"bl!abc~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional center' style='color:red:float:right;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional center' style='color:red:float:right;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -113,7 +113,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__replace() { // PURPOSE: handle replaced style; EX: <gallery style='color:blue; float:left;'>
fxt.Test__bicode("~')!color:blue; float:left;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='color:blue; float:left;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='color:blue; float:left;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@@ -128,7 +128,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__ws() { // PURPOSE: handle ws in style; EX: <gallery class="gallery mw-gallery-traditional" style="max-width:1115px; _width:1115px; color:blue;'>; PAGE:en.w:Anti-Serb_sentiment; DATE:2016-01-08
fxt.Test__bicode("~'){,L color:blue;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px; color:blue;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px; color:blue;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"

View File

@@ -18,19 +18,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.wkrs.bfr_args.*; import gplx.xowa.htmls.core.wkrs.imgs.*;
public class Xoh_gly_itm_wtr implements Bfr_arg {
import gplx.xowa.parsers.lnkis.*; import gplx.xowa.xtns.gallery.*;
import gplx.xowa.files.*; import gplx.xowa.guis.cbks.js.*;
public class Xoh_gly_itm_wtr implements Bfr_arg, Js_img_wkr {
private final Bfr_arg_clearable[] arg_ary;
private final Bfr_arg__hatr_id li_id = Bfr_arg__hatr_id.New_id("xogly_li_"), img_id = Bfr_arg__hatr_id.New_id(gplx.xowa.htmls.Xoh_img_mgr.Bry__html_uid)
, div_1_id = Bfr_arg__hatr_id.New_id("xowa_gallery_div1_"), div_2_id = Bfr_arg__hatr_id.New_id("xowa_gallery_div2_"), div_3_id = Bfr_arg__hatr_id.New_id("xowa_gallery_div3_");
private final Bfr_arg__hatr_id
li_id = Bfr_arg__hatr_id.New_id("xogly_li_")
, img_id = Bfr_arg__hatr_id.New_id(gplx.xowa.htmls.Xoh_img_mgr.Bry__html_uid)
, div_1_id = Bfr_arg__hatr_id.New_id("xowa_gallery_div1_")
, div_2_id = Bfr_arg__hatr_id.New_id("xowa_gallery_div2_")
, div_3_id = Bfr_arg__hatr_id.New_id("xowa_gallery_div3_");
private final Bfr_arg__itm_caption itm_caption_fmtr = new Bfr_arg__itm_caption();
private int li_w, div_1_w, div_2_margin;
private byte mode;
private int xnde_w_orig, xnde_h_orig, xnde_per_row, div_1_w, div_2_w, div_3_margin, li_idx, li_nth;
public Xoh_gly_itm_wtr() {
arg_ary = new Bfr_arg_clearable[] {li_id, div_1_id, div_2_id, div_3_id, img_id};
}
public Xoh_img_wtr Img_wtr() {return img_wtr;} private final Xoh_img_wtr img_wtr = new Xoh_img_wtr();
public void Init(boolean mode_is_diff, int img_id, int li_w, int div_1_w, int div_2_margin, byte capt_tid, byte[] itm_caption) {
public void Init(boolean mode_is_diff, byte mode, int xnde_w, int xnde_h, int xnde_per_row, int img_id, int li_idx, int li_nth, int div_1_w, int div_2_w, int div_3_margin, byte capt_tid, byte[] itm_caption) {
this.Clear();
this.li_w = li_w; this.div_1_w = div_1_w; this.div_2_margin = div_2_margin;
this.mode = mode; this.xnde_w_orig = xnde_w; this.xnde_h_orig = xnde_h; this.xnde_per_row = xnde_per_row;
this.li_idx = li_idx; this.li_nth = li_nth;
this.div_1_w = div_1_w; this.div_2_w = div_2_w; this.div_3_margin = div_3_margin;
itm_caption_fmtr.Set(capt_tid, itm_caption);
if (!mode_is_diff) {
li_id.Set(img_id); div_1_id.Set(img_id); div_2_id.Set(img_id); div_3_id.Set(img_id); img_wtr.Img_id_(img_id);
@@ -38,6 +47,9 @@ public class Xoh_gly_itm_wtr implements Bfr_arg {
img_wtr.Anch_cls_(Xoh_img_data.Bry__cls__anch__image);
}
public Xoh_gly_itm_wtr Clear() {
this.mode = 0;
this.xnde_w_orig = xnde_h_orig = xnde_per_row = li_idx = li_nth = -1;
this.div_1_w = div_2_w = div_3_margin = 0;
for (Bfr_arg_clearable arg : arg_ary)
arg.Bfr_arg__clear();
// img_wtr.Clear(); // TOMBSTONE: do not clear; clear will be called by Xoh_hzip_img.Decode1
@@ -46,20 +58,62 @@ public class Xoh_gly_itm_wtr implements Bfr_arg {
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return false;}
public void Bfr_arg__add(Bry_bfr bfr) {
fmtr.Bld_bfr_many(bfr, li_id, div_1_id, div_2_id, div_3_id, li_w, div_1_w, div_2_margin, img_wtr, itm_caption_fmtr);
fmtr.Bld_bfr_many(bfr, li_id, div_1_id, div_2_id, div_3_id, div_1_w, div_2_w, div_3_margin, img_wtr, itm_caption_fmtr);
}
public void Js_wkr__update_hdoc(Xoa_page page, Xog_js_wkr js_wkr, int html_uid, int html_w, int html_h, Io_url html_view_url, int orig_w, int orig_h, Xof_ext orig_ext, Io_url html_orig_url, byte[] lnki_ttl) {
Bry_bfr bfr = Bry_bfr_.New();
// get mgr
Gallery_mgr_base mgr = Gallery_mgr_base_.New(mode);
int xnde_w_actl = xnde_w_orig == -1 ? Gallery_xnde.Default : xnde_w_orig;
int xnde_h_actl = xnde_h_orig == -1 ? Gallery_xnde.Default : xnde_h_orig;
mgr.Init(xnde_w_actl, xnde_h_actl, xnde_per_row);
// get lnki and calculate expanded dimensions; note that packed will generate large widths; EX: 220 -> 2200+
gplx.xowa.parsers.lnkis.Xop_lnki_tkn lnki = new gplx.xowa.parsers.lnkis.Xop_lnki_tkn();
lnki.Ttl_(page.Wiki().Ttl_parse(lnki_ttl)).W_(html_w).H_(html_h); // NOTE: gallery_parser also does ad-hoc creation of lnki_tkn
mgr.Get_thumb_size(lnki, orig_ext); // noop if traditional; expand by 1.5 if packed
Xof_img_size img_size = new Xof_img_size();
img_size.Html_size_calc(Xof_exec_tid.Tid_wiki_page, lnki.W(), lnki.H(), lnki.Lnki_type(), Xof_patch_upright_tid_.Tid_all, lnki.Upright(), orig_ext.Id(), orig_w, orig_h, Xof_img_size.Thumb_width_img);
int html_w_expand = img_size.Html_w();
int html_h_expand = img_size.Html_h();
Xof_fsdb_itm fsdb_itm = img_wtr.Fsdb_itm();
fsdb_itm.Html_size_(html_w_expand, html_h_expand);
// update div_1, div_2, div_3 vars
div_1_w = mgr.Get_gb_width(html_w_expand, html_h_expand);
div_2_w = mgr.Get_thumb_div_width(html_w_expand);
div_3_margin = mgr.Get_vpad(xnde_h_actl, html_h_expand);
// adjust params
mgr.Adjust_image_parameters(fsdb_itm); // noop if traditional; reduce by 1.5 if packed
int html_w_normal = fsdb_itm.Html_w();
int html_h_normal = fsdb_itm.Html_h();
// fsdb_itm.Init_at_gallery_bgn(html_w_normal, html_h_normal, html_w_expand); // NOTE: gallery_htmlr updates fsdb_itm, but only need to update img_wtr; NOTE: file_w should be set to expanded width so js can resize if gallery
img_wtr.Init_html(html_w_normal, html_h_normal, html_view_url.To_http_file_bry()); // NOTE: html_view_url uses url generated by Xof_file_wkr; theoretically, packed could generate different file, but for now ignore
// generate html; call json
fmtr.Bld_bfr_many(bfr, li_id, div_1_id, div_2_id, div_3_id, div_1_w, div_2_w, div_3_margin, img_wtr, itm_caption_fmtr);
js_wkr.Html_elem_replace_html(String_.new_u8(li_id.Get_id_val()), bfr.To_str_and_clear());
if ( Gallery_mgr_base_.Mode_is_packed(mode) // packed gallery
&& li_idx == li_nth) { // last itm
js_wkr.Html_gallery_packed_exec(); // call packed js
}
}
public static final Xoh_gly_itm_wtr[] Ary_empty = new Xoh_gly_itm_wtr[0];
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, "<li~{li_id} class=\"gallerybox\" style=\"width:~{li_w}px;\">"
, "<div~{div_1_id} style=\"width:~{li_w}px;\">"
, "<div~{div_2_id} class=\"thumb\" style=\"width:~{div_1_w}px;\">"
, "<div~{div_3_id} style=\"margin:~{div_2_margin}px auto;\">~{img_itm}</div>"
, "<li~{li_id} class=\"gallerybox\" style=\"width:~{div_1_w}px;\">"
, "<div~{div_1_id} style=\"width:~{div_1_w}px;\">"
, "<div~{div_2_id} class=\"thumb\" style=\"width:~{div_2_w}px;\">"
, "<div~{div_3_id} style=\"margin:~{div_3_margin}px auto;\">~{img_itm}</div>"
, "</div>"
, "<div class=\"gallerytext\">~{itm_caption}</div>"
, "</div>"
, "</li>"
), "li_id", "div_1_id", "div_2_id", "div_3_id", "li_w", "div_1_w", "div_2_margin", "img_itm", "itm_caption");
), "li_id", "div_1_id", "div_2_id", "div_3_id", "div_1_w", "div_2_w", "div_3_margin", "img_itm", "itm_caption");
}
class Bfr_arg__itm_caption implements Bfr_arg {
private byte capt_tid;

View File

@@ -16,11 +16,11 @@ 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.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.htmls.core.hzips.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.xtns.gallery.*;
public class Xoh_gly_itm_wtr_tst {
private final Xoh_gly_itm_wtr_fxt fxt = new Xoh_gly_itm_wtr_fxt();
@Test public void Basic() {
fxt.Init__gly(0, 155, 150, 5, "caption");
fxt.Init__gly(Gallery_mgr_base_.Tid__traditional, -1, -1, -1, 0, 155, 150, 5, "caption");
fxt.Init__img("/wiki/File:A.png", "A.png", "0|120|120|-1|-1|-1");
fxt.Test__write(String_.Concat_lines_nl_skip_last
( ""
@@ -40,8 +40,8 @@ public class Xoh_gly_itm_wtr_tst {
class Xoh_gly_itm_wtr_fxt {
private final Xoh_gly_itm_wtr wtr = new Xoh_gly_itm_wtr();
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
public void Init__gly(int id, int itm_w, int file_div_w, int file_div_margin, String caption) {
wtr.Init(Bool_.N, id, itm_w, file_div_w, file_div_margin, Xoh_gly_itm_data.Capt_tid__p, Bry_.new_a7(caption));
public void Init__gly(byte mode, int xnde_w, int xnde_h, int xnde_per_row, int id, int itm_w, int div_1_w, int div_3_margin, String caption) {
wtr.Init(Bool_.N, mode, xnde_w, xnde_h, xnde_per_row, id, 0, 0, itm_w, div_1_w, div_3_margin, Xoh_gly_itm_data.Capt_tid__p, Bry_.new_a7(caption));
}
public void Init__img(String href, String xowa_title, String xoimg) {
wtr.Img_wtr().Init_by_gly(gplx.core.brys.args.Bfr_arg__bry.New(Bry_.new_u8(href)), Bry_.new_u8(xowa_title), gplx.core.brys.args.Bfr_arg__bry.New(Bry_.new_u8(xoimg)));

View File

@@ -39,7 +39,9 @@ public class Xoh_hdr_data implements Xoh_data_itm {
public boolean Init_by_parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag hdr_head, Gfh_tag span_head) {
this.Clear();
this.src_bgn = hdr_head.Src_bgn(); this.hdr_level = hdr_head.Name_id();
Gfh_atr anch_atr = span_head.Atrs__get_by_or_fail(Gfh_atr_.Bry__id);
if (hdr_head.Atrs__len() > 0) return false; // skip manual <h2> with atrs; PAGE:fr.w:Wikipédia:LiveRC/ToDo; DATE:2016-07-02
Gfh_atr anch_atr = span_head.Atrs__get_by_or_empty(Gfh_atr_.Bry__id);
if (anch_atr.Val_dat_missing()) return false; // skip manual <h2> without id; PAGE:fr.w:Portail:Nord-Amérindiens/Image_sélectionnée; DATE:2016-07-01
this.anch_bgn = anch_atr.Val_bgn(); this.anch_end = anch_atr.Val_end();
this.capt_bgn = span_head.Src_end();
Gfh_tag hdr_tail = tag_rdr.Tag__move_fwd_tail(hdr_level); // find </h2> not </span> since <span> can be nested, but <h2> cannot
@@ -59,7 +61,7 @@ public class Xoh_hdr_data implements Xoh_data_itm {
this.anch_bgn = anch_bgn; this.anch_end = anch_end; this.capt_bgn = capt_bgn; this.capt_end = capt_end;
this.capt_rhs_bgn = capt_rhs_bgn; this.capt_rhs_end = capt_rhs_end;
}
public static final byte[] Bry__class__mw_headline = Bry_.new_a7("mw-headline");
public static final byte[] Bry__class__mw_headline = Bry_.new_a7("mw-headline");
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_hdr_data rv = new Xoh_hdr_data(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
public class Xoh_hdr_hzip_tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
@Test public void Same() {
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
( "~\"'A~"
@@ -91,4 +91,16 @@ public class Xoh_hdr_hzip_tst {
, "</div>"
));
}
@Test public void Manual__no_id() {// PURPOSE: ignore manual "<h2>" with no id; PAGE:fr.w:Portail:Nord-Am<41>rindiens/Image_s<5F>lectionn<6E>e; DATE:2016-07-01
fxt.Test__bicode
( "<h6><span class=\"mw-headline\">A</span></h6>"
, "<h6><span class='mw-headline'>A</span></h6>"
);
}
@Test public void Manual__h_has_atrs() {// PURPOSE: ignore manual "<h2>" with atrs; PAGE:fr.w:Wikip<69>dia:LiveRC/ToDo; DATE:2016-07-02
fxt.Test__bicode
( "<h6 style=\"color:red\"><span class=\"mw-headline\" id=\"A\">B</span></h6>"
, "<h6 style=\"color:red\"><span class=\"mw-headline\" id=\"A\">B</span></h6>"
);
}
}

View File

@@ -59,6 +59,13 @@ public class Xoh_img_wtr implements Bfr_arg, Xoh_wtr_itm {
this.Bfr_arg__add(bfr);
}
private static final byte[] Bry__qarg__esc = Bry_.new_a7("%3F");
public void Init_html(int html_w, int html_h, byte[] src_bry) {
img_w.Set_by_int(html_w);
img_h.Set_by_int(html_h);
if (gplx.core.envs.Op_sys.Cur().Tid_is_drd())
src_bry = Bry_.Replace(src_bry, Byte_ascii.Question_bry, Bry__qarg__esc); // NOTE: if drd, always escape "?" as "%3F" PAGE:en.w:Cleopatra en.w:Cave_painting; DATE:2016-01-31
img_src.Set_by_bry(src_bry);
}
public boolean Init_by_decode(Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_data_itm data_itm) {
Xoh_img_data data = (Xoh_img_data)data_itm;
this.Clear();
@@ -72,17 +79,13 @@ public class Xoh_img_wtr implements Bfr_arg, Xoh_wtr_itm {
fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, hpg.Wiki().Domain_itm().Abrv_xo(), lnki_ttl, gplx.xowa.parsers.lnkis.Xop_lnki_type.To_flag(img_xowa_image.Lnki_type()), img_xowa_image.Lnki_upright(), img_xowa_image.Lnki_w(), img_xowa_image.Lnki_h(), img_xowa_image.Lnki_time(), img_xowa_image.Lnki_page(), Xof_patch_upright_tid_.Tid_all);
hctx.File__mgr().Find(hpg.Wiki(), hpg.Url_bry_safe(), fsdb_itm);
this.img_xowa_image.Set_by_arg(img_xowa_image.Clone()); // NOTE: must clone b/c img_xowa_image is member of Xoh_img_data which is poolable (and cleared); PAGE:en.w:Almagest; DATE:2016-01-05
img_w.Set_by_int(fsdb_itm.Html_w());
img_h.Set_by_int(fsdb_itm.Html_h());
byte[] src_bry = fsdb_itm.Html_view_url().To_http_file_bry();
if (gplx.core.envs.Op_sys.Cur().Tid_is_drd()) src_bry = Bry_.Replace(src_bry, Byte_ascii.Question_bry, Bry__qarg__esc); // NOTE: if drd, always escape "?" as "%3F" PAGE:en.w:Cleopatra en.w:Cave_painting; DATE:2016-01-31
this.img_src.Set_by_bry(src_bry);
this.Init_html(fsdb_itm.Html_w(), fsdb_itm.Html_h(), fsdb_itm.Html_view_url().To_http_file_bry());
}
else if (data.Img_w() != -1) {
img_w.Set_by_int(data.Img_w());
img_h.Set_by_int(data.Img_h());
this.img_src.Set_by_arg(data.Img_src());
}
}
if (data.Anch_rel_nofollow_exists()) anch_rel.Set_by_bry(gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_dict_.Html__rel__nofollow);
if (!hctx.Mode_is_diff()) {
this.Img_id_(fsdb_itm.Html_uid());

View File

@@ -23,11 +23,11 @@ import gplx.xowa.parsers.*;
import gplx.xowa.wikis.tdbs.metas.*;
import gplx.xowa.htmls.core.htmls.*;
public class Xoh_file_mgr {
private final Xowe_wiki wiki;
private final Xowe_wiki wiki;
public Xoh_file_mgr(Xowe_wiki wiki, Xow_html_mgr html_mgr, Xoh_html_wtr html_wtr) {
this.wiki = wiki; this.file_wtr = new Xoh_file_wtr__basic(wiki, html_mgr, html_wtr);
}
public Xoh_file_wtr__basic File_wtr() {return file_wtr;} private final Xoh_file_wtr__basic file_wtr;
public Xoh_file_wtr__basic File_wtr() {return file_wtr;} private final Xoh_file_wtr__basic file_wtr;
public void Init_by_page(Xoh_wtr_ctx hctx, Xoae_page page) {file_wtr.Init_by_page(hctx, page);}
public void Write_or_queue(Bry_bfr bfr, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki) {Write_or_queue(bfr, page, ctx, hctx, src, lnki, file_wtr.Arg_alt_text(ctx, src, lnki));}
public void Write_or_queue(Bry_bfr bfr, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, byte[] alt_text) {

View File

@@ -0,0 +1,91 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import gplx.langs.htmls.*;
class Xoh_toc_htmlr implements gplx.core.brys.Bfr_arg {
private final Bry_bfr bfr = Bry_bfr_.New();
private final Bry_bfr numbering_bfr = Bry_bfr_.New();
private Ordered_hash itms;
private int prv_lvl;
public void Clear() {
prv_lvl = 0;
}
public byte[] To_html(Ordered_hash itms, byte[] toc_title, boolean page_banner) {
this.itms = itms;
fmtr_div.Bld_many(bfr, page_banner ? Bry_.Empty : Bry_toc_cls, toc_title, this);
return bfr.To_bry_and_clear();
}
public byte[] Test__to_html(Ordered_hash itms) {
this.itms = itms;
Bfr_arg__add(bfr);
return bfr.To_bry_and_clear();
}
public void Bfr_arg__add(Bry_bfr bfr) {
int len = itms.Len();
prv_lvl = 0;
for (int i = 0; i < len; ++i) {
Xoh_toc_itm itm = (Xoh_toc_itm)itms.Get_at(i);
Write(bfr, itm);
}
// close all open levels
for (int i = prv_lvl; i > 0; --i) {
int indent = i * 2;
bfr.Add_byte_repeat(Byte_ascii.Space, indent + 2).Add(Gfh_tag_.Li_rhs).Add_byte_nl(); // EX: " </li>\n"
bfr.Add_byte_repeat(Byte_ascii.Space, indent ).Add(Gfh_tag_.Ul_rhs).Add_byte_nl(); // EX: " </ul>\n"
}
}
private void Write(Bry_bfr bfr, Xoh_toc_itm itm) {
int cur_lvl = itm.Lvl();
int indent = cur_lvl * 2;
switch (CompareAble_.Compare(cur_lvl, prv_lvl)) {
case CompareAble_.More: // start new "<ul>"
bfr.Add_byte_repeat(Byte_ascii.Space, indent).Add(Gfh_tag_.Ul_lhs).Add_byte_nl(); // EX: " <ul>\n"
break;
case CompareAble_.Same: // close old "</li>"; NOTE: Comparable_.Same will never be 1st item (so won't ever get </li><li>)
bfr.Add_byte_repeat(Byte_ascii.Space, indent + 2).Add(Gfh_tag_.Li_rhs).Add_byte_nl(); // EX: " </li>\n"
break;
case CompareAble_.Less: // close old "</ul>" and "</li>"
for (int j = prv_lvl; j > cur_lvl; --j) {
bfr.Add_byte_repeat(Byte_ascii.Space, (j * 2) + 2).Add(Gfh_tag_.Li_rhs).Add_byte_nl(); // EX: " </li>\n"
bfr.Add_byte_repeat(Byte_ascii.Space, (j * 2) ).Add(Gfh_tag_.Ul_rhs).Add_byte_nl(); // EX: " </ul>\n"
}
bfr.Add_byte_repeat(Byte_ascii.Space, indent + 2).Add(Gfh_tag_.Li_rhs).Add_byte_nl(); // EX: " </li>\n"
break;
default: throw Err_.new_unhandled_default(CompareAble_.Compare(cur_lvl, prv_lvl));
}
// write "<li ..."
bfr.Add_byte_repeat(Byte_ascii.Space, indent); // indent
fmtr_itm.Bld_many(bfr, itm.Lvl(), itm.Uid(), itm.Anch(), itm.Path_to_bry(numbering_bfr), itm.Text());
prv_lvl = cur_lvl;
}
private static final byte[] Bry_toc_cls = Bry_.new_a7(" id=\"toc\" class=\"toc\"");
private final Bry_fmt
fmtr_div = Bry_fmt.Auto(String_.Concat_lines_nl_skip_last
( "<div~{toc}>"
, " <div id=\"toctitle\">"
, " <h2>~{contents_title}</h2>"
, " </div>"
, "~{itms}</div>"
, ""
))
, fmtr_itm = Bry_fmt.Auto
( " <li class=\"toclevel-~{level} tocsection-~{toc_idx}\"><a href=\"#~{anchor}\"><span class=\"tocnumber\">~{heading}</span> <span class=\"toctext\">~{text}</span></a>\n"
);
}

View File

@@ -0,0 +1,175 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_htmlr__basic__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_htmlr__basic__fxt fxt = new Xoh_toc_htmlr__basic__fxt();
@Test public void D1_S0_S0() {
fxt.Init__add(2, "a");
fxt.Init__add(2, "b");
fxt.Init__add(2, "c");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c</span></a>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D1_D1() {
fxt.Init__add(2, "a");
fxt.Init__add(3, "a_a");
fxt.Init__add(4, "a_a_a");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
, " <ul>"
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#a_a_a\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">a_a_a</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D1_S0_U1() {
fxt.Init__add(2, "a");
fxt.Init__add(3, "a_a");
fxt.Init__add(3, "a_b");
fxt.Init__add(2, "b");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
, " </li>"
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#a_b\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">a_b</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D1_U1_D1() {
fxt.Init__add(2, "a");
fxt.Init__add(3, "a_a");
fxt.Init__add(2, "b");
fxt.Init__add(3, "b_a");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-4\"><a href=\"#b_a\"><span class=\"tocnumber\">2.1</span> <span class=\"toctext\">b_a</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D1_D1_U2() {
fxt.Init__add(2, "a");
fxt.Init__add(3, "a_a");
fxt.Init__add(4, "a_a_a");
fxt.Init__add(2, "b");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
, " <ul>"
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#a_a_a\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">a_a_a</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D2_U1_D1() {
fxt.Init__add(2, "a");
fxt.Init__add(4, "a_a_a_a");
fxt.Init__add(3, "a_a_a");
fxt.Init__add(4, "a_a_a_b");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a_a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a_a_a</span></a>"
, " </li>"
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#a_a_a\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">a_a_a</span></a>"
, " <ul>"
, " <li class=\"toclevel-3 tocsection-4\"><a href=\"#a_a_a_b\"><span class=\"tocnumber\">1.2.1</span> <span class=\"toctext\">a_a_a_b</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
);
}
@Test public void Div() {
fxt.Init__init_page("Table of contents", false);
fxt.Init__add(2, "a");
fxt.Init__add(2, "b");
fxt.Init__add(2, "c");
fxt.Test__html_div
( "<div id=\"toc\" class=\"toc\">"
, " <div id=\"toctitle\">"
, " <h2>Table of contents</h2>"
, " </div>"
, " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c</span></a>"
, " </li>"
, " </ul>"
, "</div>"
);
}
}
class Xoh_toc_htmlr__basic__fxt {
private final Xoh_toc_wtr wtr = new Xoh_toc_wtr();
public void Clear() {wtr.Clear();}
public void Init__add(int hdr_num, String hdr_txt) {wtr.Add(hdr_num, Bry_.new_u8(hdr_txt));}
public void Init__init_page(String toc_title, boolean page_banner) {wtr.Init(Bry_.new_u8(toc_title), page_banner);}
public void Test__html_itms(String... expd_ary) {
Gftest.Eq__ary(expd_ary, String_.Ary(Bry_split_.Split_lines(wtr.Test__to_html())));
}
public void Test__html_div(String... expd_ary) {
Gftest.Eq__ary(expd_ary, String_.Ary(Bry_split_.Split_lines(wtr.To_html())));
}
}

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
class Xoh_toc_itm {// EX: <li class="toclevel-3 tocsection-3"><a href="#aaa"><span class="tocnumber">1.1.1</span> <span class="toctext">aaa</span></a></li>
public int Uid() {return uid;} private int uid; // uid of itm; HTML: "tocsection-3"
public int Lvl() {return lvl;} private int lvl; // indent level; HTML: "toclevel-3"
public int[] Path() {return path;} private int[] path; // path of itm; HTML: "1.1.1"
public byte[] Anch() {return anch;} private byte[] anch; // HTML: "#aaa"
public byte[] Text() {return text;} private byte[] text; // HTML: "aaa"
public byte[] Path_to_bry(Bry_bfr bfr) {
int len = path.length;
for (int i = 0; i < len; ++i) {
if (i != 0) bfr.Add_byte_dot();
bfr.Add_int_variable(path[i]);
}
return bfr.To_bry_and_clear();
}
public void Set__lvl(int uid, int lvl, int[] path) {this.uid = uid; this.lvl = lvl; this.path = path;}
public void Set__txt(byte[] anch, byte[] text) {this.anch = anch; this.text = text;}
}

View File

@@ -0,0 +1,75 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
class Xoh_toc_wkr__lvl {
private static final int Toc_lvls_max = 7;
private final int[] sub_lvl_count = new int[Toc_lvls_max], lvl_count = new int[Toc_lvls_max];
private int prv_lvl, toc_lvl, prv_toc_lvl;
private int uid = 0;
public void Clear() {
uid = prv_lvl = toc_lvl = prv_toc_lvl = 0;
}
public void Calc_level(Xoh_toc_itm rv, int lvl) { // REF.MW:Parser.php!formatHeadings
if (lvl > prv_lvl) { // Increase TOC lvl
toc_lvl++;
sub_lvl_count[toc_lvl - List_adp_.Base1] = 0;
if (toc_lvl < Toc_lvls_max) {
prv_toc_lvl = toc_lvl;
// $toc .= Linker::tocIndent();
}
}
else if (lvl < prv_lvl && toc_lvl > 1) {// Decrease TOC lvl, find lvl to jump to
int i = toc_lvl;
for (; i > 0; i--) {
int cur_lvl_count = lvl_count[i];
if (cur_lvl_count == lvl) { // Found last matching lvl
toc_lvl = i;
break;
}
else if (cur_lvl_count < lvl) { // Found first matching lvl below current lvl
toc_lvl = i + 1;
break;
}
}
if (i == 0)
toc_lvl = 1;
if (toc_lvl < Toc_lvls_max) {
if (prv_toc_lvl < Toc_lvls_max) {
// Unindent only if the previous toc lvl was shown :p
// $toc .= Linker::tocUnindent( $prv_toc_lvl - $toc_lvl );
prv_toc_lvl = toc_lvl;
} else {
// $toc .= Linker::tocLineEnd();
}
}
}
else { // No change in lvl, end TOC line
if (toc_lvl < Toc_lvls_max) {
// $toc .= Linker::tocLineEnd();
}
}
lvl_count[toc_lvl] = lvl;
sub_lvl_count[toc_lvl - List_adp_.Base1] = sub_lvl_count[toc_lvl - List_adp_.Base1] + 1;
prv_lvl = lvl; // NOTE: same as "if ( $toclevel ) $prevlevel = $level;" but at end of block
// Tfds.Write(lvl, prv_lvl, lvl, toc_lvl, Int_.Ary_concat(",", lvl_count), Int_.Ary_concat(",", sub_lvl_count));
int[] copy = new int[toc_lvl];
Int_.Ary_copy_to(sub_lvl_count, toc_lvl, copy);
rv.Set__lvl(++uid, toc_lvl, copy);
}
}

View File

@@ -0,0 +1,66 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wkr__lvl__basic__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__lvl__fxt fxt = new Xoh_toc_wkr__lvl__fxt();
@Test public void D1_S0_S0() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(2, fxt.Make(2, 1, Int_.Ary(2)));
fxt.Test__calc(2, fxt.Make(3, 1, Int_.Ary(3)));
}
@Test public void D1_D1_D1() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(3, fxt.Make(2, 2, Int_.Ary(1, 1)));
fxt.Test__calc(4, fxt.Make(3, 3, Int_.Ary(1, 1, 1)));
}
@Test public void D1_D1_S0_U1() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(3, fxt.Make(2, 2, Int_.Ary(1, 1)));
fxt.Test__calc(3, fxt.Make(3, 2, Int_.Ary(1, 2)));
fxt.Test__calc(2, fxt.Make(4, 1, Int_.Ary(2)));
}
@Test public void D1_D1_U1_D1() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(3, fxt.Make(2, 2, Int_.Ary(1, 1)));
fxt.Test__calc(2, fxt.Make(3, 1, Int_.Ary(2)));
fxt.Test__calc(3, fxt.Make(4, 2, Int_.Ary(2, 1)));
}
@Test public void D1_D1_D1_U2() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(3, fxt.Make(2, 2, Int_.Ary(1, 1)));
fxt.Test__calc(4, fxt.Make(3, 3, Int_.Ary(1, 1, 1)));
fxt.Test__calc(2, fxt.Make(4, 1, Int_.Ary(2)));
}
}
class Xoh_toc_wkr__lvl__fxt {
private final Xoh_toc_wkr__lvl wkr = new Xoh_toc_wkr__lvl();
private final Xoh_toc_itm actl = new Xoh_toc_itm();
public void Clear() {wkr.Clear();}
public Xoh_toc_itm Make(int uid, int lvl, int[] path) {
Xoh_toc_itm rv = new Xoh_toc_itm();
rv.Set__lvl(uid, lvl, path);
return rv;
}
public void Test__calc(int lvl, Xoh_toc_itm expd) {
wkr.Calc_level(actl, lvl);
Gftest.Eq__int(expd.Uid(), actl.Uid(), "uid");
Gftest.Eq__int(expd.Lvl(), actl.Lvl(), "lvl");
Gftest.Eq__ary(expd.Path(), actl.Path(), "path");
}
}

View File

@@ -0,0 +1,152 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; import gplx.langs.htmls.encoders.*;
import gplx.xowa.parsers.amps.*; import gplx.core.primitives.*;
class Xoh_toc_wkr__txt {
private final Gfh_tag_rdr tag_rdr = Gfh_tag_rdr.New__html();
private final Bry_bfr anch_bfr = Bry_bfr_.New(), text_bfr = Bry_bfr_.New();
private final Gfo_url_encoder anch_encoder = Gfo_url_encoder_.New__id();
private final Xop_amp_mgr amp_mgr = Xop_amp_mgr.Instance;
private final Hash_adp anch_hash = Hash_adp_bry.ci_u8(gplx.xowa.langs.cases.Xol_case_mgr_.U8());
private byte[] page_name = Bry_.Empty;
public void Clear() {
anch_bfr.Clear();
text_bfr.Clear();
anch_hash.Clear();
}
public void Calc_anch_text(Xoh_toc_itm rv, byte[] src) { // text within hdr; EX: <h2>Abc</h2> -> Abc
int end = src.length;
src = Remove_comment(text_bfr, src, 0, end);
end = src.length;
tag_rdr.Init(page_name, src, 0, end);
Calc_anch_text_recurse(src, 0, end);
byte[] anch_bry = anch_bfr.To_bry_and_clear_and_trim(Bool_.Y, Bool_.Y, id_trim_ary);
Int_obj_ref anch_idx_ref = (Int_obj_ref)anch_hash.Get_by(anch_bry);
if (anch_idx_ref == null) {
anch_hash.Add(anch_bry, Int_obj_ref.New(2));
}
else {
int anch_idx = anch_idx_ref.Val();
anch_bry = Bry_.Add(anch_bry, Byte_ascii.Underline_bry, Int_.To_bry(anch_idx));
anch_idx_ref.Val_(anch_idx + 1);
}
rv.Set__txt
( anch_bry
, text_bfr.To_bry_and_clear_and_trim()); // NOTE: both id and text trim ends
}
private void Calc_anch_text_recurse(byte[] src, int pos, int end) {
tag_rdr.Src_rng_(pos, end);
while (pos < end) {
Gfh_tag lhs = tag_rdr.Tag__move_fwd_head();
int tag_id = lhs.Name_id();
byte[] span_dir = null;
// add any text before lhs;
int txt_end = lhs.Src_bgn();
switch (tag_id) {
case Gfh_tag_.Id__eos: txt_end = end; break; // eos; print everything until end
}
// add any text before tag
if (pos < txt_end) {
byte[] anch_bry = amp_mgr.Decode_as_bry(Bry_.Mid(src, pos, txt_end));
anch_encoder.Encode(anch_bfr, anch_bry);
text_bfr.Add_mid(src, pos, txt_end);
}
// set print_tag tag; REF.MW:Parser.php!formatHeadings
boolean print_tag = false;
switch (tag_id) {
case Gfh_tag_.Id__eos: // eos; return;
return;
case Gfh_tag_.Id__sup: // always print tag; REF.MW:Parser.php!formatHeadings!"Allowed tags are"
case Gfh_tag_.Id__sub:
case Gfh_tag_.Id__i:
case Gfh_tag_.Id__b:
case Gfh_tag_.Id__bdi:
print_tag = true;
break;
case Gfh_tag_.Id__span: // print span only if it has a dir attribute
span_dir = lhs.Atrs__get_as_bry(Gfh_atr_.Bry__dir);
print_tag = Bry_.Len_gt_0(span_dir);
break;
case Gfh_tag_.Id__comment: // never print tag
case Gfh_tag_.Id__any: // all other tags never print
default:
print_tag = false;
break;
}
// get lhs / rhs vars
byte[] lhs_bry = lhs.Name_bry();
int lhs_end = lhs.Src_end();
boolean lhs_is_pair = !lhs.Tag_is_inline();
int rhs_bgn = -1, rhs_end = -1, new_pos = lhs_end;
if (lhs_is_pair) { // get rhs unless inline
Gfh_tag rhs = tag_rdr.Tag__move_fwd_tail(tag_id);
rhs_bgn = rhs.Src_bgn(); rhs_end = rhs.Src_end();
new_pos = rhs_end;
}
// print "<tag></tag>"; also, recurse
if (print_tag) {
text_bfr.Add_byte(Byte_ascii.Angle_bgn).Add(lhs_bry);
if (span_dir != null) // if span has dir, add it; EX: <span id='1' dir='rtl'> -> <span dir='rtl'>
Gfh_atr_.Add(text_bfr, Gfh_atr_.Bry__dir, span_dir);
text_bfr.Add_byte(Byte_ascii.Angle_end); // only add name; do not add atrs; EX: <i id='1'> -> <i>
}
Calc_anch_text_recurse(src, lhs_end, rhs_bgn);
if (print_tag && lhs_is_pair)
text_bfr.Add_mid(src, rhs_bgn, rhs_end);
// set new_pos
pos = new_pos;
tag_rdr.Src_rng_(new_pos, end); // NOTE: must reinit pos and especially end
}
}
public static byte[] Remove_comment(Bry_bfr tmp, byte[] src, int bgn, int end) {
boolean dirty = false, append_to_eos = true;
int pos = bgn;
while (true) {
int comm_bgn = Bry_find_.Find_fwd(src, Gfh_tag_.Comm_bgn, pos, end);
if (comm_bgn != -1) { // comment found
int tmp_pos = comm_bgn + Gfh_tag_.Comm_bgn_len;
int comm_end = Bry_find_.Find_fwd(src, Gfh_tag_.Comm_end, tmp_pos, end);
if (comm_end == -1) { // dangling
tmp.Add_mid(src, pos, comm_bgn);
append_to_eos = false;
}
else {
dirty = true;
tmp.Add_mid(src, pos, comm_bgn);
pos = comm_end + Gfh_tag_.Comm_end_len;
continue;
}
}
break;
}
if (dirty && append_to_eos) {
tmp.Add_mid(src, pos, end);
}
return dirty ? tmp.To_bry_and_clear() : src;
}
private static final byte[] id_trim_ary = Bry_.mask_(256, Byte_ascii.Underline_bry);
}

View File

@@ -0,0 +1,69 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wkr__txt__basic__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__txt__fxt fxt = new Xoh_toc_wkr__txt__fxt();
@Test public void Basic() {
fxt.Test__both("a b c", "a_b_c", "a b c");
}
@Test public void Ws() {
fxt.Test__both(" a b ", "a_b", "a b");
}
@Test public void Amp__ncr() {
fxt.Test__both("&#91;a&#93;", ".5Ba.5D", "&#91;a&#93;");
}
@Test public void Encode() {
fxt.Test__both("a+b", "a.2Bb", "a+b");
}
@Test public void Dupe() {
fxt.Test__both("a", "a", "a");
fxt.Test__both("a", "a_2", "a");
fxt.Test__both("A", "A_3", "A");
}
@Test public void Comment() {
fxt.Test__text("a<!--b-->c", "ac");
}
@Test public void Remove_comment__one() {
fxt.Test__remove_comment("a<!--b-->c", "ac");
}
@Test public void Remove_comment__many() {
fxt.Test__remove_comment("1<!--2-->3<!--4-->5", "135");
}
@Test public void Remove_comment__dangling() {
fxt.Test__remove_comment("1<!--2-->3<!--4->5", "13");
}
}
class Xoh_toc_wkr__txt__fxt {
private final Xoh_toc_wkr__txt wkr = new Xoh_toc_wkr__txt();
private final Xoh_toc_itm itm = new Xoh_toc_itm();
private final Bry_bfr tmp = Bry_bfr_.New();
public void Clear() {wkr.Clear();}
public void Test__id (String html, String expd_id) {Test__both(html, expd_id, null);}
public void Test__text(String html, String expd_text) {Test__both(html, null, expd_text);}
public void Test__both(String html, String expd) {Test__both(html, expd, expd);}
public void Test__both(String html, String expd_anch, String expd_text) {
wkr.Calc_anch_text(itm, Bry_.new_u8(html));
if (expd_anch != null) Gftest.Eq__str(expd_anch, itm.Anch(), "anch");
if (expd_text != null) Gftest.Eq__str(expd_text, itm.Text(), "text");
}
public void Test__remove_comment(String html, String expd) {
byte[] html_bry = Bry_.new_u8(html);
Gftest.Eq__str(expd, Xoh_toc_wkr__txt.Remove_comment(tmp, html_bry, 0, html_bry.length));
}
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wkr__txt__xnde__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__txt__fxt fxt = new Xoh_toc_wkr__txt__fxt();
@Test public void I() {fxt.Test__both("<i>a</i>" , "a", "<i>a</i>");}
@Test public void I__id() {fxt.Test__both("<i id='1'>a</i>" , "a", "<i>a</i>");}
@Test public void B() {fxt.Test__both("<b>a</b>" , "a", "<b>a</b>");}
@Test public void Sup() {fxt.Test__both("<sup>a</sup>" , "a", "<sup>a</sup>");}
@Test public void Sub() {fxt.Test__both("<sub>a</sub>" , "a", "<sub>a</sub>");}
@Test public void Bdi() {fxt.Test__both("<bdi>a</bdi>" , "a", "<bdi>a</bdi>");}
@Test public void Span() {fxt.Test__both("<span>a</span>" , "a", "a");}
@Test public void Span__id() {fxt.Test__both("<span id='1'>a</span>" , "a", "a");}
@Test public void Span__dir() {fxt.Test__both("<span dir=\"ltr\">a</span>" , "a", "<span dir=\"ltr\">a</span>");}
@Test public void Span__dir_id() {fxt.Test__both("<span id='1' dir=\"ltr\">a</span>" , "a", "<span dir=\"ltr\">a</span>");}
@Test public void Small() {fxt.Test__text("<small>a</small>" , "a");}
@Test public void A() {fxt.Test__both("<a href=\"/wiki/A\">b</a>" , "b");}
@Test public void A__nest() {fxt.Test__both("<a href=\"/wiki/A\">b<i>c</i>d</a>" , "bcd", "b<i>c</i>d");}
@Test public void Br() {fxt.Test__both("a<br/>b" , "ab");}
@Test public void H2() {fxt.Test__both("a<h2>b</h2>c" , "abc");} // NOTE: not a valid test; MW actually generates "ab" b/c of tidy; see corresponding edit test; DATE:2016-06-28
@Test public void Li() {fxt.Test__text("a<ul><li>b</li></ul>c" , "abc");}
@Test public void Table() {fxt.Test__text("a<table><tr><td>b</td></tr></table>c" , "abc");}
}

View File

@@ -16,108 +16,32 @@ 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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
class Xoh_toc_wtr {
private final Gfh_tag_rdr tag_rdr = Gfh_tag_rdr.New__html();
private byte[] page_name = Bry_.Empty;
private final Bry_bfr bfr = Bry_bfr_.New();
private final Ordered_hash itms = Ordered_hash_.New_bry();
private final Xoh_toc_wkr__lvl lvl_wkr = new Xoh_toc_wkr__lvl();
private final Xoh_toc_wkr__txt txt_wkr = new Xoh_toc_wkr__txt();
private final Xoh_toc_htmlr htmlr = new Xoh_toc_htmlr();
private byte[] toc_title; private boolean page_banner;
public void Clear() {
bfr.Clear();
itms.Clear();
lvl_wkr.Clear();
txt_wkr.Clear();
htmlr.Clear();
}
public void Page_name_(byte[] page_name) {this.page_name = page_name;}
public byte[] Convert(byte[] src) { // text within hdr; EX: <h2>Abc</h2> -> Abc
int end = src.length;
tag_rdr.Init(page_name, src, 0, end);
Convert_recurse(0, src, 0, end);
return bfr.To_bry_and_clear_and_trim();
public void Init(byte[] toc_title, boolean page_banner) {
this.toc_title = toc_title;
this.page_banner = page_banner;
}
private static void Add_wo_comment(Bry_bfr bfr, byte[] src, int bgn, int end) {
int pos = bgn;
while (true) {
int comm_bgn = Bry_find_.Find_fwd(src, Gfh_tag_.Comm_bgn, pos, end);
if (comm_bgn != -1) {
int tmp_pos = comm_bgn + Gfh_tag_.Comm_bgn_len;
int comm_end = Bry_find_.Find_fwd(src, Gfh_tag_.Comm_end, tmp_pos, end);
if (comm_end != -1) {
bfr.Add_mid(src, pos, comm_bgn);
pos = comm_end + Gfh_tag_.Comm_end_len;
continue;
}
}
bfr.Add_mid(src, pos, end);
break;
}
public void Add(int hdr_num, byte[] hdr_txt) {
Xoh_toc_itm itm = new Xoh_toc_itm();
lvl_wkr.Calc_level(itm, hdr_num);
txt_wkr.Calc_anch_text(itm, hdr_txt);
itms.Add(itm.Anch(), itm);
}
private void Convert_recurse(int depth, byte[] src, int pos, int end) {
tag_rdr.Src_rng_(pos, end);
while (pos < end) {
Gfh_tag lhs = tag_rdr.Tag__move_fwd_head();
int tag_id = lhs.Name_id();
// add any text before lhs;
int txt_end = lhs.Src_bgn();
switch (tag_id) {
case Gfh_tag_.Id__eos: txt_end = end; break; // eos; print everything until end
}
if (pos < txt_end) Add_wo_comment(bfr, src, pos, txt_end);
// set print_tag / recurse based on tag
boolean print_tag = false, recurse = true;
switch (tag_id) {
case Gfh_tag_.Id__eos: // eos; return;
return;
case Gfh_tag_.Id__comment: // never print tag
case Gfh_tag_.Id__img:
case Gfh_tag_.Id__br: case Gfh_tag_.Id__hr: // always ignore in TOC text; EX: en.wikipedia.org/wiki/Magnetic_resonance_imaging; ====''T''<span style="display:inline-block; margin-bottom:-0.3em; vertical-align:-0.4em; line-height:1.2em; font-size:85%; text-align:left;">*<br />2</span>-weighted MRI====
case Gfh_tag_.Id__h1: case Gfh_tag_.Id__h2: case Gfh_tag_.Id__h3: case Gfh_tag_.Id__h4: case Gfh_tag_.Id__h5: case Gfh_tag_.Id__h6:
case Gfh_tag_.Id__ul: case Gfh_tag_.Id__ol: case Gfh_tag_.Id__dd: case Gfh_tag_.Id__dt: case Gfh_tag_.Id__li:
case Gfh_tag_.Id__table: case Gfh_tag_.Id__tr: case Gfh_tag_.Id__td: case Gfh_tag_.Id__th: case Gfh_tag_.Id__thead: case Gfh_tag_.Id__tbody: case Gfh_tag_.Id__caption:
// case Gfh_tag_.Id__ref: // NOTE: don't bother printing references; NOTE: should never show up
print_tag = false;
recurse = false;
break;
case Gfh_tag_.Id__b: // always print tag
case Gfh_tag_.Id__i:
print_tag = true;
break;
case Gfh_tag_.Id__small: // only print tag if not nested
case Gfh_tag_.Id__sup:
case Gfh_tag_.Id__any:
default: {
if (depth > 0)
print_tag = true;
break;
}
case Gfh_tag_.Id__a: // a never prints tag; also, also, do not recurse if ref
print_tag = false;
byte[] href_val = lhs.Atrs__get_as_bry(Gfh_atr_.Bry__href);
if (Bry_.Has_at_bgn(href_val, gplx.xowa.xtns.cites.Ref_html_wtr_cfg.Note_href_bgn)) // do not print if href='#cite_note-...'; EX: <a href=\"#cite_note-0\">[1]</a>
recurse = false;
break;
}
// get lhs / rhs vars
int lhs_bgn = lhs.Src_bgn(), lhs_end = lhs.Src_end();
boolean lhs_is_pair = !lhs.Tag_is_inline();
int rhs_bgn = -1, rhs_end = -1, new_pos = lhs_end;
if (lhs_is_pair) { // get rhs unless inline
Gfh_tag rhs = tag_rdr.Tag__move_fwd_tail(tag_id);
rhs_bgn = rhs.Src_bgn(); rhs_end = rhs.Src_end();
new_pos = rhs_end;
}
// print "<tag></tag>"; also, recurse
if (print_tag) bfr.Add_mid(src, lhs_bgn, lhs_end);
if (recurse) {
Convert_recurse(depth + 1, src, lhs_end, rhs_bgn);
}
if (print_tag && lhs_is_pair)
bfr.Add_mid(src, rhs_bgn, rhs_end);
// set new_pos
pos = new_pos;
tag_rdr.Src_rng_(new_pos, end); // NOTE: must reinit pos and especially end
}
public byte[] To_html() {
return htmlr.To_html(itms, toc_title, page_banner);
}
public byte[] Test__to_html() {
return htmlr.Test__to_html(itms);
}
}

View File

@@ -1,36 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wtr__anch__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wtr_fxt fxt = new Xoh_toc_wtr_fxt();
@Test public void Caption() {
fxt.Test__convert("<a href=\"/wiki/A\">b</a>", "b");
}
@Test public void Ref() { // PURPOSE: ref contents should not print in TOC; DATE:2013-07-23
fxt.Test__convert("a<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>", "a");
}
@Test public void Category() { // PURPOSE: literal Category should show in in TOC; EX: de.w:1234; DATE:2014-01-21
fxt.Test__convert("A<a href=\"/wiki/Category:B\">Category:B</a>", "ACategory:B");
}
@Test public void File() { // PURPOSE: file should not show in in TOC; EX: tr.w:D<>nya_Miraslari; DATE:2014-06-06
fxt.Test__convert
( "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a> b"
, "b");
}
}

View File

@@ -1,55 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wtr__keep__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wtr_fxt fxt = new Xoh_toc_wtr_fxt();
@Test public void Basic() {
fxt.Test__convert("a b c", "a b c");
}
@Test public void Ws() {
fxt.Test__convert(" a b ", "a b");
}
@Test public void Amp__ncr() {
fxt.Test__convert("&#91;a&#93;", "&#91;a&#93;");
}
@Test public void Italic() {
fxt.Test__convert("<i>a</i>", "<i>a</i>");
}
@Test public void Caption() {
fxt.Test__convert("<a href=\"/wiki/A\">b</a>", "b");
}
@Test public void Ref() { // PURPOSE: ref contents should not print in TOC; DATE:2013-07-23
fxt.Test__convert("a<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>", "a");
}
@Test public void Category__literal() { // PURPOSE: literal Category should show in in TOC; EX: de.w:1234; DATE:2014-01-21
fxt.Test__convert("A<a href=\"/wiki/Category:B\">Category:B</a>", "ACategory:B");
}
@Test public void File() { // PURPOSE: file should show in in TOC; EX: tr.w:D<>nya_Miraslari; DATE:2014-06-06
fxt.Test__convert
( "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a> b"
, "b");
}
}
class Xoh_toc_wtr_fxt {
private final Xoh_toc_wtr wtr = new Xoh_toc_wtr();
public void Clear() {wtr.Clear();}
public void Test__convert(String html, String expd) {
Gftest.Eq__str(expd, wtr.Convert(Bry_.new_u8(html)));
}
}

View File

@@ -1,34 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wtr__nest__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wtr_fxt fxt = new Xoh_toc_wtr_fxt();
@Test public void Xnde__xnde() { // <sup> removed but not <small>
fxt.Test__convert("a <sup>b<small>c</small>d</sup> e", "a b<small>c</small>d e");
}
@Test public void Xnde__inline() { // PURPOSE: do not render inline xndes; EX: Magnetic_resonance_imaging
fxt.Test__convert("a<span id='b'>b<br/></span>", "ab");
}
@Test public void Xnde__lnki() { // <small> and <a> removed
fxt.Test__convert("<small><a href=\"/wiki/A\">b</a></small>", "b");
}
@Test public void Lnki__xnde() {
fxt.Test__convert("<a href=\"/wiki/A\">b<i>c</i>d</a>", "b<i>c</i>d");
}
}

View File

@@ -1,52 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wtr__skip__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wtr_fxt fxt = new Xoh_toc_wtr_fxt();
@Test public void Comment() {
fxt.Test__convert("<!--a-->", "");
}
@Test public void Comment__many() {
fxt.Test__convert("1<!--2-->3<!--4-->5", "135");
}
@Test public void Comment__dangling() {
fxt.Test__convert("1<!--2-->3<!--4->5", "13<!--4->5");
}
@Test public void Br() {
fxt.Test__convert("a<br/>b", "ab");
}
@Test public void H2() {
fxt.Test__convert("a<h2>b</h2>c", "ac");
}
@Test public void Li() {
fxt.Test__convert("a<ul><li>b</li></ul>c", "ac");
}
@Test public void Table() {
fxt.Test__convert("a<table><tr><td>b</td></tr></table>c", "ac");
}
@Test public void Xnde__small() {
fxt.Test__convert("<small>a</small>", "a");
}
@Test public void Xnde__sup() {
fxt.Test__convert("<sup>a</sup>", "a");
}
@Test public void Translate() { // PURPOSE: <translate> is an xtn and parses its innerText separately; meanwhile, toc_mgr defaults to using the innerText to build toc; EX:Wikidata:Introduction; DATE:2013-07-16
fxt.Test__convert("<translate><!--b-->ac</translate>", "ac");
}
}

View File

@@ -180,7 +180,7 @@ public class Xow_toc_mgr implements gplx.core.brys.Bfr_arg {
break;
case Xop_tkn_itm_.Tid_apos: html_wtr.Apos (ctx, html_wtr_opts, bfr, src, (Xop_apos_tkn)sub); break;
case Xop_tkn_itm_.Tid_html_ncr: html_wtr.Html_ncr (ctx, html_wtr_opts, bfr, src, (Xop_amp_tkn_num)sub); break;
case Xop_tkn_itm_.Tid_html_ref: html_wtr.Html_ref (ctx, html_wtr_opts, bfr, src, (Xop_amp_tkn_txt)sub); break;
case Xop_tkn_itm_.Tid_html_ref: html_wtr.Html_ref (ctx, html_wtr_opts, bfr, src, (Xop_amp_tkn_ent)sub); break;
default:
if (sub.Subs_len() == 0) // NOTE: never call html_wtr directly unless leaf elem; DATE:2014-06-22
html_wtr.Write_tkn(bfr, ctx, html_wtr_opts, src, tkn, Xoh_html_wtr.Sub_idx_null, sub);
@@ -190,7 +190,7 @@ public class Xow_toc_mgr implements gplx.core.brys.Bfr_arg {
}
}
}
public void Html(Xoae_page page, Xoh_wtr_ctx hctx, byte[] src, Bry_bfr bfr, boolean write_toc_cls) {
public void Html(Xoae_page page, Xoh_wtr_ctx hctx, byte[] src, Bry_bfr bfr, boolean write_toc_cls) { // write_toc_cls needed for Page_banner
if (!page.Hdr_mgr().Toc_enabled()) return; // REF.MW: Parser.php|formatHeadings
if (hctx.Mode_is_hdump()) return;
this.page = page;

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.xowa.parsers.*; import gplx.xowa.htmls.core.htmls.*;
public class Xow_toc_mgr_tst {
public class Xow_toc_mgr_tst {
@Before public void init() {fxt.Clear();} private final Xow_toc_mgr_fxt fxt = new Xow_toc_mgr_fxt();
@Test public void Basic() {
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
@@ -173,7 +173,7 @@ public class Xow_toc_mgr_tst {
, " </ul>"
));
}
@Test public void Encode() {
@Test public void Id__encode() {
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a+b=="
@@ -215,7 +215,7 @@ public class Xow_toc_mgr_tst {
, ""
));
}
@Test public void Xnde_italic() {
@Test public void Xnde__italic() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==<i>a</i>=="
@@ -230,7 +230,7 @@ public class Xow_toc_mgr_tst {
, "<h2><span class='mw-headline' id='a'><i>a</i></span></h2>"
));
}
@Test public void Xnde_small() {
@Test public void Xnde__small() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==<small>a</small>=="
@@ -245,7 +245,61 @@ public class Xow_toc_mgr_tst {
, "<h2><span class='mw-headline' id='a'><small>a</small></span></h2>"
));
}
@Test public void Xnde_dangling() { // PURPOSE: do not render dangling xndes; EX: Casualties_of_the_Iraq_War; ===<small>Iraqi Health Ministry<small>===
@Test public void Xnde__li() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a<ul><li>b</li></ul>c=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#abc\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ac</span></a>" // NOTE: toctext should be "abc", not "ab"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='abc'>a<ul>"
, "<li>b</li></ul>c</span></h2>"
));
}
@Test public void Xnde__table() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a<table><tr><td>b</td></tr></table>c=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a.3Ctable.3E.3Ctr.3E.3Ctd.3Eb.3C.2Ftd.3E.3C.2Ftr.3E.3C.2Ftable.3Ec\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">abc</span></a>" // NOTE: toc id should be "abc"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='a.3Ctable.3E.3Ctr.3E.3Ctd.3Eb.3C.2Ftd.3E.3C.2Ftr.3E.3C.2Ftable.3Ec'>a"
, "<table>"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, "</table>"
, "c</span></h2>"
));
}
// TOMBSTONE: on MW, shows up as 'href="#ab"; <span class="toctext">ab</span>; '; TIDY doing strange things; ignore for now; DATE:2016-06-28
//@Test public void Xnde__h2() {
// fxt.Test_html_all(String_.Concat_lines_nl_skip_last
// ( "__FORCETOC__"
// , "==a<h2>b</h2>c=="
// )
// , String_.Concat_lines_nl
// ( fxt.toc_tbl_nl_n
// ( " <ul>"
// , " <li class=\"toclevel-1 tocsection-1\"><a href=\"#abc\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ac</span></a>"
// , " </li>"
// , " </ul>"
// )
// , "<h2><span class='mw-headline' id='abc'>a<h2>b</h2>c</span></h2>"
// ));
//}
@Test public void Xnde__dangling() { // PURPOSE: do not render dangling xndes; EX: Casualties_of_the_Iraq_War; ===<small>Iraqi Health Ministry<small>===
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==<small>a<small>=="
@@ -260,7 +314,7 @@ public class Xow_toc_mgr_tst {
, "<h2><span class='mw-headline' id='a'><small>a<small></small></small></span></h2>"
));
}
@Test public void Xnde_nest_xnde() {
@Test public void Nest__xnde__small() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a <sup>b<small>c</small>d</sup> e=="
@@ -275,7 +329,7 @@ public class Xow_toc_mgr_tst {
, "<h2><span class='mw-headline' id='a_bcd_e'>a <sup>b<small>c</small>d</sup> e</span></h2>"
));
}
@Test public void Xnde_nest_lnki() {
@Test public void Nest__lnki() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==<small>[[a|b]]</small>=="
@@ -290,7 +344,7 @@ public class Xow_toc_mgr_tst {
, "<h2><span class='mw-headline' id='b'><small><a href=\"/wiki/A\">b</a></small></span></h2>"
));
}
@Test public void Xnde_nest_inline() { // PURPOSE: do not render inline xndes; EX: Magnetic_resonance_imaging
@Test public void Nest__br() { // PURPOSE: do not render inline xndes; EX: Magnetic_resonance_imaging
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a<span id=\"b\">b<br/></span>=="