mirror of
https://github.com/gnosygnu/xowa.git
synced 2025-05-31 14:34:15 +00:00
Htxt: Show Table of Contents [#390]
This commit is contained in:
parent
82bee2e877
commit
ca8c4ce5a4
@ -34,7 +34,8 @@ public class Xoh_hdoc_parser {
|
||||
public void Parse(Xoh_hzip_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src) {
|
||||
int src_len = src.length;
|
||||
tag_parser.Init(hctx, src, 0, src_len);
|
||||
hdoc_wkr.On_new_page(bfr, hpg, hctx, src, 0, src_len);
|
||||
hdoc_wkr.On_page_bgn(bfr, hpg, hctx, src, 0, src_len);
|
||||
hdoc_parser.Parse(hctx.Page__url(), src, 0, src_len);
|
||||
hdoc_wkr.On_page_end();
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ import gplx.langs.htmls.docs.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public interface Xoh_hdoc_wkr {
|
||||
void On_new_page(Xoh_hzip_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end);
|
||||
void On_page_bgn(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end);
|
||||
void On_page_end();
|
||||
void On_txt (int rng_bgn, int rng_end);
|
||||
void On_escape (gplx.xowa.htmls.core.wkrs.escapes.Xoh_escape_data data);
|
||||
void On_xnde (gplx.xowa.htmls.core.wkrs.xndes.Xoh_xnde_parser parser);
|
||||
|
@ -20,10 +20,11 @@ public class Xoh_hdoc_wkr__hzip implements Xoh_hdoc_wkr {
|
||||
private final Xoh_stat_itm stat_itm = new Xoh_stat_itm();
|
||||
private Xoh_hzip_bfr bfr; private Xoh_hdoc_ctx hctx; private byte[] src;
|
||||
private Xoh_page hpg;
|
||||
public void On_new_page(Xoh_hzip_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
|
||||
this.bfr = bfr; this.hpg = hpg; this.hctx = hctx; this.src = src;
|
||||
public void On_page_bgn(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
|
||||
this.bfr = (Xoh_hzip_bfr)bfr; this.hpg = hpg; this.hctx = hctx; this.src = src;
|
||||
stat_itm.Clear();
|
||||
}
|
||||
public void On_page_end() {}
|
||||
public void On_txt (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_escape (gplx.xowa.htmls.core.wkrs.escapes.Xoh_escape_data data) {hctx.Pool_mgr__hzip().Mw__escape().Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();}
|
||||
public void On_xnde (gplx.xowa.htmls.core.wkrs.xndes.Xoh_xnde_parser data) {hctx.Pool_mgr__hzip().Mw__xnde().Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();}
|
||||
|
@ -15,16 +15,25 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.docs.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*; import gplx.xowa.htmls.core.wkrs.tocs.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_hdoc_wkr__make implements Xoh_hdoc_wkr {
|
||||
private Xoh_hzip_bfr bfr; private Xoh_page hpg; private Xoh_hdoc_ctx hctx; private byte[] src;
|
||||
private Bry_bfr bfr; private Xoh_page hpg; private Xoh_hdoc_ctx hctx; private byte[] src;
|
||||
private final Xoh_hdr_wtr wkr__hdr = new Xoh_hdr_wtr();
|
||||
private final Xoh_img_wtr wkr__img = new Xoh_img_wtr();
|
||||
private final Xoh_page_bfr page_bfr = new Xoh_page_bfr();
|
||||
private boolean toc_enabled;
|
||||
private int html_uid;
|
||||
public void On_new_page(Xoh_hzip_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
|
||||
public void On_page_bgn(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
|
||||
this.bfr = bfr; this.hpg = hpg; this.hctx = hctx; this.src = src;
|
||||
this.html_uid = 0;
|
||||
this.toc_enabled = !gplx.core.envs.Op_sys.Cur().Tid_is_drd();
|
||||
if (toc_enabled)
|
||||
this.page_bfr.Init(bfr);
|
||||
}
|
||||
public void On_page_end() {
|
||||
if (toc_enabled)
|
||||
page_bfr.Commit(hpg);
|
||||
}
|
||||
public void On_txt(int rng_bgn, int rng_end) {
|
||||
// text; just add it
|
||||
@ -90,10 +99,12 @@ public class Xoh_hdoc_wkr__make implements Xoh_hdoc_wkr {
|
||||
return wkr__hdr.Init_by_parse(bfr, hpg, hctx, src, (Xoh_hdr_data)data);
|
||||
case Xoh_hzip_dict_.Tid__img:
|
||||
return wkr__img.Init_by_parse(bfr, hpg, hctx, src, (Xoh_img_data)data);
|
||||
// TODO: see toc_mode; change make_mgr to stitch together html before and after toc for pgbnr; see Xoh_page_bfr
|
||||
case Xoh_hzip_dict_.Tid__toc:
|
||||
bfr.Add_mid(src, data.Src_bgn(), data.Src_end());
|
||||
// this.toc_mode = toc_lhs.Atrs__has(Xoh_toc_wtr.Atr__data__toc__mode) ? Toc_mode__pgbnr : Toc_mode__basic;
|
||||
// process <xowa_toc> tag by splitting bfr into two: bfr-before-toc and bfr-after-toc
|
||||
if (toc_enabled) {
|
||||
Xoh_toc_data toc_data = (Xoh_toc_data)data;
|
||||
this.bfr = page_bfr.Split_by_toc(toc_data.Toc_mode());
|
||||
}
|
||||
break;
|
||||
// hzip_lnke just reconstructs html
|
||||
case Xoh_hzip_dict_.Tid__lnke:
|
||||
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.tocs; 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.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xoh_toc_make__basic__tst {
|
||||
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
|
||||
private final String orig = String_.Concat_lines_nl_skip_last
|
||||
( "abc"
|
||||
, "<div class=\"xo-toc\"></div>"
|
||||
, "def"
|
||||
, "<h2><span class='mw-headline' id='A'>A</span></h2>"
|
||||
, "a 1"
|
||||
, "<h2><span class='mw-headline' id='B'>B</span></h2>"
|
||||
, "b 1"
|
||||
);
|
||||
@Before public void Init() {fxt.Clear();}
|
||||
@Test public void Enabled() {
|
||||
String expd = String_.Concat_lines_nl_skip_last
|
||||
( "abc"
|
||||
, "<div id='toc' class='toc'>"
|
||||
, " <div id='toctitle' class='toctitle'>"
|
||||
, " <h2>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>"
|
||||
, " </ul>"
|
||||
, "</div>"
|
||||
, ""
|
||||
, "def"
|
||||
, "<h2><span class='mw-headline' id='A'>A</span></h2>"
|
||||
, "a 1"
|
||||
, "<h2><span class='mw-headline' id='B'>B</span></h2>"
|
||||
, "b 1"
|
||||
);
|
||||
fxt.Test__make(orig, fxt.Page_chkr().Body_(expd));
|
||||
}
|
||||
@Test public void Disabled_if_drd() {
|
||||
gplx.core.envs.Op_sys.Cur_(gplx.core.envs.Op_sys.Tid_drd);
|
||||
String expd = String_.Concat_lines_nl_skip_last
|
||||
( "abc"
|
||||
, ""
|
||||
, "def"
|
||||
, "<h2><span class='mw-headline' id='A'>A</span></h2>"
|
||||
, "a 1"
|
||||
, "<h2><span class='mw-headline' id='B'>B</span></h2>"
|
||||
, "b 1"
|
||||
);
|
||||
fxt.Test__make(orig, fxt.Page_chkr().Body_(expd));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user