mirror of https://github.com/gnosygnu/xowa
parent
1a4ca00c0b
commit
36584a0cc2
@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.core.btries; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.threads.poolables.*;
|
||||
public class Btrie_rv implements Gfo_poolable_itm {
|
||||
public Object Obj() {return obj;} private Object obj;
|
||||
public int Pos() {return pos;} private int pos;
|
||||
public Btrie_rv Init(int pos, Object obj) {
|
||||
this.obj = obj;
|
||||
this.pos = pos;
|
||||
return this;
|
||||
}
|
||||
|
||||
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) {Btrie_rv rv = new Btrie_rv(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.core.memorys; import gplx.*; import gplx.core.*;
|
||||
public class Gfo_memory_mgr {
|
||||
private final List_adp list = List_adp_.New();
|
||||
public void Reg_safe(Gfo_memory_itm itm) {synchronized (list) {Reg_fast(itm);}}
|
||||
public void Reg_fast(Gfo_memory_itm itm) {list.Add(itm);}
|
||||
public void Rls_safe() {synchronized (list) {Rls_fast();}}
|
||||
public void Rls_fast() {
|
||||
int len = list.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Gfo_memory_itm itm = (Gfo_memory_itm)list.Get_at(i);
|
||||
itm.Rls_mem();
|
||||
}
|
||||
list.Clear();
|
||||
}
|
||||
public static final Gfo_memory_mgr Instance = new Gfo_memory_mgr(); Gfo_memory_mgr() {}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/100_core"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/140_dbs"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/150_gfui"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="lib" path="lib/jtidy_xowa.jar"/>
|
||||
<classpathentry kind="lib" path="lib/luaj_xowa.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -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>'
|
||||
}
|
||||
}
|
@ -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;")
|
||||
;
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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"
|
||||
);
|
||||
}
|
@ -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())));
|
||||
}
|
||||
}
|
@ -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;}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
@ -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("[a]", ".5Ba.5D", "[a]");
|
||||
}
|
||||
@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));
|
||||
}
|
||||
}
|
@ -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");}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue