mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.10.3.1
This commit is contained in:
130
400_xowa/src/gplx/xowa/htmls/tocs/Xow_hdr_mgr.java
Normal file
130
400_xowa/src/gplx/xowa/htmls/tocs/Xow_hdr_mgr.java
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
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.core.primitives.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xow_hdr_mgr {
|
||||
private final Url_encoder_mgr encoder_mgr; private final Xoae_page page;
|
||||
private final Hash_adp hdrs_hash = Hash_adp_.new_(); private final Bry_bfr hdrs_bfr = Bry_bfr.reset_(255); private final Bry_obj_ref hdrs_ref = Bry_obj_ref.null_();
|
||||
private Xop_hdr_tkn[] hdrs_ary = new Xop_hdr_tkn[0]; private int hdrs_max, hdrs_len;
|
||||
public Xow_hdr_mgr(Xoae_page page, Url_encoder_mgr encoder_mgr) {this.page = page; this.encoder_mgr = encoder_mgr;}
|
||||
public boolean Toc_enabled() {
|
||||
return !toc_hide // check for __NOTOC__
|
||||
&& hdrs_len != 0 // never show TOC if 0 headers, even when __FORCETOC__
|
||||
&& ( hdrs_len > Toc_min // show TOC automatically if 4 or more headers
|
||||
|| toc_manual // or when __TOC__ specified (EX: 2 headers)
|
||||
|| toc_force // or when __FORCETOC__ specified; presumably to (a) show TOC when < 4 headers and (b) let TOC show at default position; __TOC__ would force TOC to show at __TOC__; __FORCETOC__ can be placed at bottom of page
|
||||
)
|
||||
;
|
||||
}
|
||||
public boolean Toc_manual() {return toc_manual;}
|
||||
public void Toc_manual_() {toc_manual = true;} private boolean toc_manual; // __TOC__
|
||||
public void Toc_force_() {toc_force = true;} private boolean toc_force; // __FORCETOC__
|
||||
public void Toc_hide_() {toc_hide = true;} private boolean toc_hide; // __NOTOC__
|
||||
public int Len() {return hdrs_len;}
|
||||
public Xop_hdr_tkn Get_at(int i) {return hdrs_ary[i];}
|
||||
public void Add(Xop_ctx ctx, Xop_hdr_tkn hdr, byte[] src) {
|
||||
int new_len = hdrs_len + 1;
|
||||
if (new_len > hdrs_max) {
|
||||
hdrs_max = (new_len * 2) + 1;
|
||||
hdrs_ary = (Xop_hdr_tkn[])Array_.Resize(hdrs_ary, hdrs_max);
|
||||
}
|
||||
Reg(ctx, hdr, src);
|
||||
hdrs_ary[hdrs_len] = hdr;
|
||||
hdrs_len = new_len;
|
||||
}
|
||||
public void Clear() {
|
||||
hdrs_len = 0;
|
||||
if (hdrs_max > 32) {
|
||||
hdrs_ary = new Xop_hdr_tkn[32];
|
||||
hdrs_max = 32;
|
||||
}
|
||||
hdrs_hash.Clear();
|
||||
toc_manual = toc_force = toc_hide = false;
|
||||
}
|
||||
private void Reg(Xop_ctx ctx, Xop_hdr_tkn hdr, byte[] src) {
|
||||
if (hdrs_len == 0) hdr.Hdr_html_first_y_();
|
||||
Bry_bfr_mkr bfr_mkr = Xoa_app_.Utl__bfr_mkr();
|
||||
Bry_bfr raw_bfr = bfr_mkr.Get_b128(), enc_bfr = bfr_mkr.Get_b128();
|
||||
Id_bld_recurse(raw_bfr, src, hdr);
|
||||
Url_encoder encoder = encoder_mgr.Id();
|
||||
encoder.Encode(enc_bfr, raw_bfr.Bfr(), 0, raw_bfr.Len());
|
||||
byte[] hdrs_id = enc_bfr.To_bry();
|
||||
Object o = hdrs_hash.Get_by(hdrs_ref.Val_(hdrs_id));
|
||||
if (o != null) {
|
||||
Xop_hdr_tkn hdr_0 = (Xop_hdr_tkn)o;
|
||||
enc_bfr.Add_byte(Byte_ascii.Underline).Add_int_variable(hdr_0.Hdr_html_dupe_idx_next());
|
||||
hdrs_id = enc_bfr.To_bry_and_clear();
|
||||
}
|
||||
else {
|
||||
hdrs_bfr.Clear();
|
||||
hdrs_hash.Add(Bry_obj_ref.new_(hdrs_id), hdr);
|
||||
}
|
||||
hdr.Hdr_html_id_(hdrs_id);
|
||||
hdr.Hdr_toc_text_(gplx.xowa.htmls.tocs.Xow_toc_mgr.Toc_text(ctx, page, src, hdr));
|
||||
raw_bfr.Mkr_rls(); enc_bfr.Mkr_rls();
|
||||
}
|
||||
private void Id_bld_recurse(Bry_bfr raw_bfr, byte[] src, Xop_tkn_itm tkn) {
|
||||
boolean txt_seen = false; int ws_pending = 0;
|
||||
int subs_len = tkn.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
Xop_tkn_itm sub = tkn.Subs_get(i);
|
||||
byte sub_tid = sub.Tkn_tid();
|
||||
if ( sub_tid != Xop_tkn_itm_.Tid_space
|
||||
&& sub_tid != Xop_tkn_itm_.Tid_para) {
|
||||
if (ws_pending > 0) {
|
||||
raw_bfr.Add_byte_repeat(Byte_ascii.Underline, ws_pending);
|
||||
ws_pending = 0;
|
||||
}
|
||||
txt_seen = true;
|
||||
}
|
||||
switch (sub.Tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_space:
|
||||
if (txt_seen) ws_pending = sub.Src_end() - sub.Src_bgn();
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_apos: break; // noop; ignore apos in id
|
||||
case Xop_tkn_itm_.Tid_txt:
|
||||
raw_bfr.Add_mid(src, sub.Src_bgn(), sub.Src_end());
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_xnde:
|
||||
Xop_xnde_tkn xnde = (Xop_xnde_tkn)sub;
|
||||
Id_bld_recurse(raw_bfr, src, xnde);
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_lnki:
|
||||
Xop_lnki_tkn lnki = (Xop_lnki_tkn)sub;
|
||||
if (lnki.Ns_id() == Xow_ns_.Id_category) {} // Category text should not print; DATE:2013-12-09
|
||||
else {
|
||||
if (lnki.Caption_exists())
|
||||
Id_bld_recurse(raw_bfr, src, lnki.Caption_val_tkn());
|
||||
else
|
||||
raw_bfr.Add(lnki.Ttl_ary());
|
||||
}
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_html_ncr:
|
||||
Xop_amp_tkn_num html_ncr = (Xop_amp_tkn_num)sub;
|
||||
raw_bfr.Add(html_ncr.Str_as_bry());
|
||||
break;
|
||||
default:
|
||||
raw_bfr.Add_mid(src, sub.Src_bgn(), sub.Src_end());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static final int Toc_min = 3;
|
||||
}
|
||||
222
400_xowa/src/gplx/xowa/htmls/tocs/Xow_toc_mgr.java
Normal file
222
400_xowa/src/gplx/xowa/htmls/tocs/Xow_toc_mgr.java
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
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.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xow_toc_mgr implements Bry_fmtr_arg {
|
||||
private static final int Toc_levels = 32; // assume 6 max levels * 5 max heading (9999.); add 2 for good measure
|
||||
private Xoae_page page; private Xop_toc_itm[] path_ary; private Bry_bfr path_bfr = Bry_bfr.reset_(Toc_levels);
|
||||
public Xow_toc_mgr() {
|
||||
path_ary = new Xop_toc_itm[Toc_levels];
|
||||
for (int i = 0; i < Toc_levels; i++)
|
||||
path_ary[i] = new Xop_toc_itm();
|
||||
}
|
||||
public void Clear() {
|
||||
for (int i = 0; i < Toc_levels; i++)
|
||||
path_ary[i].Lvl_idx_(0);
|
||||
}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
int path_idx = 0, toc_idx = 0, lvl_idx = 1, eq_prv = 0;
|
||||
path_bfr.Clear();
|
||||
Xow_hdr_mgr hdr_mgr = page.Hdr_mgr();
|
||||
int hdrs_len = hdr_mgr.Len();
|
||||
for (int i = 0; i < hdrs_len; i++) {
|
||||
Xop_hdr_tkn hdr = hdr_mgr.Get_at(i);
|
||||
int eq_cur = hdr.Hdr_len();
|
||||
switch (CompareAble_.Compare(eq_cur, eq_prv)) {
|
||||
case CompareAble_.More: // always increase slot
|
||||
if (eq_prv != 0) { // add to path_bfr, unless 1st
|
||||
path_bfr.Add_int_variable(lvl_idx).Add_byte(Byte_ascii.Dot); // build path; EX: 1.2.3
|
||||
}
|
||||
if (path_idx >= Toc_levels) return; // HACK:invalid <div><h2>a</h2></div> sequence causes invalid toc level generation; for now, exit; WHEN:removing dangling <div> logic; DATE:2014-06-08
|
||||
path_ary[path_idx].Lvl_idx_(lvl_idx).Eq_len_((byte)eq_cur); // store cur value in path ary; EX: path_ary[1] = 2
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, path_idx * 2).Add(Bry_list_bgn); // <ul>
|
||||
++path_idx;
|
||||
lvl_idx = 1;
|
||||
eq_prv = eq_cur;
|
||||
break;
|
||||
case CompareAble_.Less: // decrease slot, only if <= last slot
|
||||
int path_new = 0;
|
||||
for (int j = path_idx - 1; j > -1; j--) {
|
||||
if (eq_cur == path_ary[j].Eq_len()) {
|
||||
path_new = j;
|
||||
break;
|
||||
}
|
||||
else if (eq_cur > path_ary[j].Eq_len()) {
|
||||
path_new = j + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (path_new == path_idx) {
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, path_idx * 2).Add(Bry_item_end); // add "</li>"
|
||||
++lvl_idx;
|
||||
}
|
||||
else {
|
||||
for (int j = path_idx; j > path_new + 1; j--) {
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, path_idx * 2).Add(Bry_item_end); // </li>
|
||||
--path_idx;
|
||||
if (path_idx == -1) path_idx = 0;
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, path_idx * 2).Add(Bry_list_end); // </ul>
|
||||
lvl_idx = path_ary[path_idx].Lvl_idx();
|
||||
path_bfr.Del_by(Int_.DigitCount(lvl_idx) + 1); // + 1 for dot
|
||||
}
|
||||
++lvl_idx;
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, path_idx * 2).Add(Bry_item_end); // <li>
|
||||
}
|
||||
eq_prv = eq_cur;
|
||||
break;
|
||||
case CompareAble_.Same: // keep slot the same
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, path_idx * 2).Add(Bry_item_end); // add "</li>"
|
||||
++lvl_idx;
|
||||
break;
|
||||
}
|
||||
byte[] text = hdr.Hdr_toc_text();
|
||||
int lvl_idx_digits = Int_.DigitCount(lvl_idx);
|
||||
path_bfr.Add_int_fixed(lvl_idx, lvl_idx_digits); // add current level
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, (path_idx - 1) * 2); // indent
|
||||
bfmtr_line.Bld_bfr_many(bfr, path_idx, ++toc_idx, hdr.Hdr_html_id(), path_bfr, text);
|
||||
path_bfr.Del_by(lvl_idx_digits);
|
||||
}
|
||||
for (int i = path_idx - 1; i > -1; i--) {
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, (i + 1) * 2);
|
||||
bfr.Add(Bry_item_end);
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, i * 2);
|
||||
bfr.Add(Bry_list_end);
|
||||
}
|
||||
}
|
||||
public static byte[] Toc_text(Xop_ctx ctx, Xoae_page page, byte[] src, Xop_tkn_itm hdr) {
|
||||
try {
|
||||
Xowe_wiki wiki = page.Wikie();
|
||||
Bry_bfr bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Basic;
|
||||
Xoh_html_wtr html_wtr = wiki.Html_mgr().Html_wtr(); html_wtr.Init_by_page(ctx, hctx, src, page);
|
||||
Toc_text_recurse(ctx, bfr, src, html_wtr, hctx, hdr, 0);
|
||||
bfr.Mkr_rls();
|
||||
return bfr.To_bry_and_clear();
|
||||
} catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to write toc: url=~{0} err=~{1}", page.Url().To_str(), Err_.Message_gplx_full(e));
|
||||
return Bry_.Empty;
|
||||
}
|
||||
}
|
||||
private static void Toc_text_recurse(Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xoh_html_wtr html_wtr, Xoh_wtr_ctx html_wtr_opts, Xop_tkn_itm tkn, int depth) {
|
||||
int subs_len = tkn.Subs_len();
|
||||
boolean txt_seen = false; int ws_pending = 0;
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
Xop_tkn_itm sub = tkn.Subs_get(i);
|
||||
byte sub_tid = sub.Tkn_tid();
|
||||
if (sub_tid != Xop_tkn_itm_.Tid_space) {
|
||||
if (ws_pending > 0) {
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, ws_pending);
|
||||
ws_pending = 0;
|
||||
}
|
||||
txt_seen = true;
|
||||
}
|
||||
switch (sub.Tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_space:
|
||||
if (txt_seen) ws_pending = sub.Src_end() - sub.Src_bgn();
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_lnki:
|
||||
Xop_lnki_tkn lnki = (Xop_lnki_tkn)sub;
|
||||
if (lnki.Ns_id() == Xow_ns_.Id_category
|
||||
&& !lnki.Ttl().ForceLiteralLink()) {} // Category text should not print; DATE:2013-12-09
|
||||
else {
|
||||
if (lnki.Caption_exists())
|
||||
Toc_text_recurse(ctx, bfr, src, html_wtr, html_wtr_opts, lnki.Caption_val_tkn(), depth);
|
||||
else {
|
||||
if (lnki.Ns_id() == Xow_ns_.Id_file) {} // do not print lnk_ttl in TOC; if file; tr.w:Dünya_Mirasları; DATE:2014-06-06
|
||||
else
|
||||
bfr.Add(lnki.Ttl_ary());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_xnde:
|
||||
Xop_xnde_tkn xnde = (Xop_xnde_tkn)sub;
|
||||
switch (xnde.Tag().Id()) {
|
||||
case Xop_xnde_tag_.Tid_br: // 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 Xop_xnde_tag_.Tid_hr: // assumed, based on above
|
||||
case Xop_xnde_tag_.Tid_h1: case Xop_xnde_tag_.Tid_h2: case Xop_xnde_tag_.Tid_h3: case Xop_xnde_tag_.Tid_h4: case Xop_xnde_tag_.Tid_h5: case Xop_xnde_tag_.Tid_h6:
|
||||
case Xop_xnde_tag_.Tid_ul: case Xop_xnde_tag_.Tid_ol: case Xop_xnde_tag_.Tid_dd: case Xop_xnde_tag_.Tid_dt: case Xop_xnde_tag_.Tid_li:
|
||||
case Xop_xnde_tag_.Tid_table: case Xop_xnde_tag_.Tid_tr: case Xop_xnde_tag_.Tid_td: case Xop_xnde_tag_.Tid_th: case Xop_xnde_tag_.Tid_thead: case Xop_xnde_tag_.Tid_tbody: case Xop_xnde_tag_.Tid_caption:
|
||||
case Xop_xnde_tag_.Tid_ref: // NOTE: don't bother printing references
|
||||
// case Xop_xnde_tag_.Tid_pre: case Xop_xnde_tag_.Tid_blockquote:
|
||||
break;
|
||||
case Xop_xnde_tag_.Tid_b:
|
||||
case Xop_xnde_tag_.Tid_i:
|
||||
html_wtr.Write_tkn(bfr, ctx, html_wtr_opts, src, tkn, Xoh_html_wtr.Sub_idx_null, sub);
|
||||
break;
|
||||
case Xop_xnde_tag_.Tid_translate:
|
||||
gplx.xowa.xtns.translates.Xop_translate_xnde translate_xnde = (gplx.xowa.xtns.translates.Xop_translate_xnde)xnde.Xnde_xtn();
|
||||
html_wtr.Write_tkn(bfr, ctx, html_wtr_opts, translate_xnde.Xtn_root().Data_mid(), tkn, Xoh_html_wtr.Sub_idx_null, translate_xnde.Xtn_root());
|
||||
break;
|
||||
default:
|
||||
if (depth > 0 && (xnde.CloseMode() == Xop_xnde_tkn.CloseMode_pair || xnde.CloseMode() == Xop_xnde_tkn.CloseMode_inline)) // do not render dangling xndes; EX: Casualties_of_the_Iraq_War; ===<small>Iraqi Health Ministry<small>===
|
||||
bfr.Add_mid(src, xnde.Tag_open_bgn(), xnde.Tag_open_end());
|
||||
Toc_text_recurse(ctx, bfr, src, html_wtr, html_wtr_opts, xnde, depth + 1);
|
||||
if (depth > 0 && xnde.CloseMode() == Xop_xnde_tkn.CloseMode_pair) // do not render (a) dangling xndes or (b) inline (which will have negative bgn)
|
||||
bfr.Add_mid(src, xnde.Tag_close_bgn(), xnde.Tag_close_end());
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_txt:
|
||||
html_wtr.Write_tkn(bfr, ctx, html_wtr_opts, src, tkn, Xoh_html_wtr.Sub_idx_null, sub);
|
||||
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;
|
||||
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);
|
||||
else
|
||||
Toc_text_recurse(ctx, bfr, src, html_wtr, html_wtr_opts, sub, depth + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Html(Xoae_page page, Xoh_wtr_ctx hctx, byte[] src, Bry_bfr bfr) {
|
||||
if (!page.Hdr_mgr().Toc_enabled()) return; // REF.MW: Parser.php|formatHeadings
|
||||
if (hctx.Mode_is_hdump()) return;
|
||||
this.page = page;
|
||||
byte[] bry_contents = page.Wikie().Msg_mgr().Val_by_id(Xol_msg_itm_.Id_toc);
|
||||
bfmtr_main.Bld_bfr_many(bfr, Bry_fmtr_arg_.bry_(bry_contents), this);
|
||||
}
|
||||
private static final byte[]
|
||||
Bry_list_bgn = Bry_.new_a7(" <ul>\n")
|
||||
, Bry_list_end = Bry_.new_a7(" </ul>\n")
|
||||
, Bry_item_end = Bry_.new_a7(" </li>\n")
|
||||
;
|
||||
private Bry_fmtr
|
||||
bfmtr_main = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"toc\" class=\"toc\">"
|
||||
, " <div id=\"toctitle\">"
|
||||
, " <h2>~{contents_title}</h2>"
|
||||
, " </div>"
|
||||
, "~{toc_list}</div>"
|
||||
, ""
|
||||
)
|
||||
, "contents_title", "toc_list"
|
||||
)
|
||||
, bfmtr_line = Bry_fmtr.new_
|
||||
( " <li class=\"toclevel-~{level} tocsection-~{toc_idx}\"><a href=\"#~{anchor}\"><span class=\"tocnumber\">~{heading}</span> <span class=\"toctext\">~{text}</span></a>\n"
|
||||
, "level", "toc_idx", "anchor", "heading", "text"
|
||||
);
|
||||
}
|
||||
class Xop_toc_itm {
|
||||
public int Eq_len() {return eq_len;} public Xop_toc_itm Eq_len_(int v) {eq_len = v; return this;} private int eq_len;
|
||||
public int Lvl_idx() {return lvl_idx;} public Xop_toc_itm Lvl_idx_(int v) {lvl_idx = v; return this;} private int lvl_idx;
|
||||
}
|
||||
545
400_xowa/src/gplx/xowa/htmls/tocs/Xow_toc_mgr_tst.java
Normal file
545
400_xowa/src/gplx/xowa/htmls/tocs/Xow_toc_mgr_tst.java
Normal file
@@ -0,0 +1,545 @@
|
||||
/*
|
||||
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.xowa.parsers.*;
|
||||
public class Xow_toc_mgr_tst {
|
||||
private Xow_toc_mgr_fxt fxt = new Xow_toc_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "==b=="
|
||||
, "==c=="
|
||||
, "==d=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <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>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">4</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Hier_down() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "===b==="
|
||||
, "====c===="
|
||||
, "=====d====="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <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=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">c</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-4 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">1.1.1.1</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Hier_up() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "===b==="
|
||||
, "===c==="
|
||||
, "==d=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <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=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">c</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Down_up() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "===b==="
|
||||
, "==c=="
|
||||
, "===d==="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <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=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">c</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">2.1</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void D1_D1_D1_U2() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "===b==="
|
||||
, "====c===="
|
||||
, "==d=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <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=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">c</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Err() { // PURPOSE: models strange case wherein jumping down does not work
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "====b===="
|
||||
, "===c==="
|
||||
, "====d===="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <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=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">c</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-3 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">1.2.1</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Repeat_name() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "==a=="
|
||||
, "==a=="
|
||||
, "==a=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <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=\"#a_2\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#a_3\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#a_4\"><span class=\"tocnumber\">4</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Encode() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==a+b=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a.2Bb\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a+b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Ws() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "== a b =="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a_b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='a_b'> a b </span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Apos_italic() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==''a''=="
|
||||
)
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\"><i>a</i></span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='a'><i>a</i></span></h2>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Xnde_italic() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==<i>a</i>=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\"><i>a</i></span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='a'><i>a</i></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Xnde_small() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==<small>a</small>=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<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>===
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==<small>a<small>=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='a'><small>a<small></small></small></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Xnde_nest_xnde() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==a <sup>b<small>c</small>d</sup> e=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a_bcd_e\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a b<small>c</small>d e</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<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() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==<small>[[a|b]]</small>=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<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
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==a<span id='b'>b<br/></span>=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#ab\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ab</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='ab'>a<span id='b'>b<br/></span></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Lnki_link() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==[[a]]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='a'><a href=\"/wiki/A\">a</a></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Lnki_caption() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==[[a|b]]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='b'><a href=\"/wiki/A\">b</a></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Lnki_caption_nest() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==[[a|b<i>c</i>d]]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#bcd\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">b<i>c</i>d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='bcd'><a href=\"/wiki/A\">b<i>c</i>d</a></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Html_ncr() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==[a]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#.5Ba.5D\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">[a]</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='.5Ba.5D'>[a]</span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Fix_large_before_small() { // PURPOSE.fix: "===a===\n===b===\n" followed by "==c==" causes improper formatting; DATE:2013-05-16
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "===a==="
|
||||
, "===b==="
|
||||
, "==c=="
|
||||
, "==d=="
|
||||
), fxt.toc_tbl_nl_y // NOTE: should all be level 2
|
||||
( " <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>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">4</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Fix_large_before_small_2() { // PURPOSE.fix: similar to above, but has h3 after h2; PAGE:https://en.wikipedia.org/wiki/Wikipedia:Articles_for_creation/2006-08-27 DATE:2014-06-09
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "===a_0==="
|
||||
, "==b_0=="
|
||||
, "===b_1==="
|
||||
, "==c_0=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a_0\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a_0</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b_0\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b_0</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#b_1\"><span class=\"tocnumber\">2.1</span> <span class=\"toctext\">b_1</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#c_0\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c_0</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Translate_and_comment() { // 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_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==<translate><!--b-->ac</translate>=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#.3C.21--b--.3Eac\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ac</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Ref() { // PURPOSE: ref contents should not print in TOC; DATE:2013-07-23
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==a<ref>b</ref>=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#ab\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='ab'>a<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Category() { // PURPOSE: Category should not show in in TOC; DATE:2013-12-09
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==A[[Category:B]]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#A\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">A</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='A'>A</span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Category_literal() { // PURPOSE: literal Category should show in in TOC; EX: de.w:1234; DATE:2014-01-21
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==A[[:Category:B]]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#A\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ACategory:B</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='A'>A<a href=\"/wiki/Category:B\">Category:B</a></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void File() { // PURPOSE: file should show in in TOC; EX: tr.w:D<>nya_Miraslari; DATE:2014-06-06
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==[[File:A.png]] b=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#File:A.png_b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\"> b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='File:A.png_b'><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a> b</span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Lnki_invalid() { // PURPOSE: invalid lnki was causing null ref; DATE:2014-02-07
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==[[]]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#.5B.5B.5D.5D\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">[[]]</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='.5B.5B.5D.5D'>[[]]</span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void File_in_tbl() { // PURPOSE: two issues (a) don't show file if in tbl; (b) if v2, file inside tbl fails; PAGE:en.w:Holmes County,_Mississippi; DATE:2014-06-22
|
||||
fxt.Test_html_frag(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==a <table><tr><td>[[File:A.png]]b</td></tr></table> c=="
|
||||
)
|
||||
, "<span class=\"toctext\">a b c</span>" // note that "b" inside tbl shows
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xow_toc_mgr_fxt {
|
||||
private Xow_toc_mgr toc_mgr = new Xow_toc_mgr();
|
||||
private Bry_bfr tmp = Bry_bfr.new_();
|
||||
public Xop_fxt Fxt() {return fxt;} private Xop_fxt fxt = new Xop_fxt();
|
||||
public void Clear() {
|
||||
fxt.Reset();
|
||||
toc_mgr.Clear();
|
||||
tmp.Clear();
|
||||
}
|
||||
public void Test_html_toc(String raw, String expd) {
|
||||
toc_mgr.Clear();
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = fxt.Ctx().Tkn_mkr().Root(raw_bry);
|
||||
fxt.Parser().Parse_page_all_clear(root, fxt.Ctx(), fxt.Ctx().Tkn_mkr(), raw_bry);
|
||||
toc_mgr.Html(fxt.Page(), Xoh_wtr_ctx.Basic, raw_bry, tmp);
|
||||
Tfds.Eq_ary(String_.SplitLines_nl(expd), String_.SplitLines_nl(tmp.To_str_and_clear()), raw);
|
||||
}
|
||||
public void Test_html_all(String raw, String expd) {
|
||||
fxt.Wtr_cfg().Toc__show_(Bool_.Y);
|
||||
toc_mgr.Clear();
|
||||
fxt.Test_parse_page_all_str(raw, expd);
|
||||
fxt.Wtr_cfg().Toc__show_(Bool_.N);
|
||||
}
|
||||
public void Test_html_frag(String raw, String frag) {
|
||||
fxt.Wtr_cfg().Toc__show_(Bool_.Y);
|
||||
toc_mgr.Clear();
|
||||
fxt.Test_html_full_frag(raw, frag);
|
||||
fxt.Wtr_cfg().Toc__show_(Bool_.N);
|
||||
}
|
||||
public String toc_tbl_nl_y(String... ary) {return toc_tbl(Bool_.Y, ary);}
|
||||
public String toc_tbl_nl_n(String... ary) {return toc_tbl(Bool_.N, ary);}
|
||||
public String toc_tbl(boolean nl, String... ary) {
|
||||
return String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"toc\" class=\"toc\">"
|
||||
, " <div id=\"toctitle\">"
|
||||
, " <h2>Contents</h2>"
|
||||
, " </div>"
|
||||
, String_.Concat_lines_nl_skip_last(ary)
|
||||
, "</div>" + (nl ? "\n" : "")
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user