1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-28 14:30:51 +00:00

Table_of_contents: Ignore NOTOC commands at template level

This commit is contained in:
gnosygnu 2017-06-17 10:34:29 -04:00
parent a439f53c1a
commit e2e68342e0
13 changed files with 121 additions and 24 deletions

View File

@ -22,6 +22,7 @@ import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.pa
import gplx.xowa.files.exts.*; import gplx.xowa.files.repos.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.tdbs.hives.*;
import gplx.xowa.wikis.pages.*;
public class Xop_fxt {
public Xop_fxt() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
@ -283,7 +284,8 @@ public class Xop_fxt {
hdom_wtr.Write_doc(actl_bfr, ctx, hctx, root.Root_src(), root);
return actl_bfr.To_str_and_clear();
}
public void Hctx_(Xoh_wtr_ctx v) {hctx = v;} private Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Basic;
public Xoh_wtr_ctx Hctx() {return hctx;} private Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Basic;
public void Hctx_(Xoh_wtr_ctx v) {hctx = v;}
public String Exec_parse_page_wiki_as_str(String raw) {
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
@ -460,6 +462,21 @@ public class Xop_fxt {
byte[] actl = wiki.Html_mgr().Page_wtr_mgr().Gen(page, gplx.xowa.wikis.pages.Xopg_page_.Tid_read);
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
}
public String Exec__parse_to_html_w_skin(String raw) {
Bry_bfr bfr = Bry_bfr_.New();
Xow_html_mgr html_mgr = wiki.Html_mgr();
this.Wiki().Html__wtr_mgr().Page_read_fmtr().Fmt_("~{page_data}");
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = this.Exec_parse_page_all_as_root(raw_bry);
this.Page().Root_(root);
html_mgr.Page_wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_page(bfr, this.Page(), this.Ctx(), Xoh_page_html_source_.Wtr);
return bfr.To_str_and_clear();
}
public void Test__parse_to_html_w_skin(String raw, String expd) {
Tfds.Eq_str_lines(expd, Exec__parse_to_html_w_skin(raw));
}
public static Xop_fxt New_app_html() {
Xop_fxt fxt = new Xop_fxt();
fxt.Wiki().Html_mgr().Page_wtr_mgr().Page_read_fmtr().Fmt_("~{page_data}");

View File

@ -59,8 +59,10 @@ public class Xowe_hdr_bldr_fxt {
);
}
public static String Bld_page_with_toc(Bry_bfr bfr, Xop_fxt fxt, String raw) {
String rv = fxt.Exec_parse_page_all_as_str(raw);
bfr.Add_str_u8(rv);
gplx.xowa.parsers.Xop_root_tkn root = fxt.Exec_parse_page_all_as_root(Bry_.new_u8(raw));
fxt.Ctx().Page_data().Copy_to(fxt.Page());
fxt.Wiki().Html_mgr().Html_wtr().Write_doc(bfr, fxt.Ctx(), fxt.Hctx(), root.Root_src(), root);
gplx.xowa.htmls.core.wkrs.tocs.Xoh_toc_wtr.Write_toc(bfr, fxt.Page(), Xoh_wtr_ctx.Basic);
return bfr.To_str_and_clear();
}

View File

@ -31,7 +31,7 @@ public class Xoctg_single_box {
private static final Bry_fmt Fmt__grp = Bry_fmt.Auto_nl_skip_last
( "<div id=\"catlinks\" class=\"catlinks\">"
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
, "~{grp_lbl}"
, "~{grp_lbl}:"
, "<ul>~{grp_itms}"
, "</ul>"
, "</div>"

View File

@ -51,6 +51,7 @@ public class Xop_ctx {
public Xop_curly_wkr Curly() {return curly;} private final Xop_curly_wkr curly = new Xop_curly_wkr();
public Xop_xnde_tag_regy Xnde_tag_regy() {return xnde_tag_regy;} private final Xop_xnde_tag_regy xnde_tag_regy; // PERF:demeter
public Xop_tmp_mgr Tmp_mgr() {return tmp_mgr;} private final Xop_tmp_mgr tmp_mgr = new Xop_tmp_mgr();
public Xop_ctx_page_data Page_data() {return page_data;} private final Xop_ctx_page_data page_data = new Xop_ctx_page_data();
public byte Xnde_names_tid() {return xnde_names_tid;} public Xop_ctx Xnde_names_tid_(byte v) {xnde_names_tid = v; return this;} private byte xnde_names_tid = Xop_parser_tid_.Tid__null;
public byte Parse_tid() {return parse_tid;} public Xop_ctx Parse_tid_(byte v) {parse_tid = v; xnde_names_tid = v; return this;} private byte parse_tid = Xop_parser_tid_.Tid__null;
@ -85,6 +86,7 @@ public class Xop_ctx {
if (lst_section_mgr != null) lst_section_mgr.Clear();
if (lst_page_regy != null) lst_page_regy.Clear();
tmpl_args_parsing = false;
page_data.Clear();
return this;
}
public String Page_url_str() {

View File

@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.parsers; import gplx.*; import gplx.xowa.*;
public class Xop_ctx_page_data {
public boolean Hdr_toc() {return toc;} public void Hdr_toc_y_() {this.toc = true;} private boolean toc;
public boolean Hdr_forcetoc() {return forcetoc;} public void Hdr_forcetoc_y_() {this.forcetoc = true;} private boolean forcetoc;
public boolean Hdr_notoc() {return notoc;} public void Hdr_notoc_y_() {this.notoc = true;} private boolean notoc;
public boolean Lang_convert_content() {return lang_convert_content;} public void Lang_convert_content_(boolean v) {this.lang_convert_content = v;} private boolean lang_convert_content = true;
public boolean Lang_convert_title() {return lang_convert_title;} public void Lang_convert_title_(boolean v) {this.lang_convert_title = v;} private boolean lang_convert_title = true;
public void Clear() {
toc = forcetoc = notoc = false;
lang_convert_content = lang_convert_title = true;
}
public void Copy_to(Xoae_page page) {
gplx.xowa.wikis.pages.wtxts.Xopg_toc_mgr hdr_mgr = page.Wtxt().Toc();
hdr_mgr.Flag__toc_(toc);
hdr_mgr.Flag__forcetoc_(forcetoc);
hdr_mgr.Flag__notoc_(notoc);
page.Html_data().Lang_convert_content_(lang_convert_content);
page.Html_data().Lang_convert_title_(lang_convert_title);
}
}

View File

@ -87,8 +87,11 @@ public class Xow_parser_mgr {
scrib.When_page_changed(page); // notify scribunto about page changed
ctx.Page_(page);
ctx.Page_data().Clear(); // DATE:2017-06-13
Xop_root_tkn root = ctx.Tkn_mkr().Root(page.Db().Text().Text_bry());
if (clear) {page.Clear_all();}
if (clear) {
page.Clear_all();
}
Xoa_ttl ttl = page.Ttl();
if ( Xow_page_tid.Identify(wiki.Domain_tid(), ttl.Ns().Id(), ttl.Page_db()) == Xow_page_tid.Tid_wikitext) { // only parse page if wikitext; skip .js, .css, Module; DATE:2013-11-10
byte[] data_raw = page.Db().Text().Text_bry();
@ -96,5 +99,7 @@ public class Xow_parser_mgr {
}
page.Root_(root);
root.Data_htm_(root.Root_src());
ctx.Page_data().Copy_to(page); // copy __TOC__ from ctx to page; needed to prevent template from affecting page output; DATE:2017-06-11
}
}

View File

@ -97,19 +97,17 @@ public class Xop_under_lxr implements Xop_lxr {
return rv;
}
public static void Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos, int kwd_id) {
Xoae_page page = ctx.Page();
Xopg_toc_mgr hdr_mgr = page.Wtxt().Toc();
switch (kwd_id) {
case Xol_kwd_grp_.Id_toc:
hdr_mgr.Flag__toc_y_();
ctx.Page_data().Hdr_toc_y_();
ctx.Para().Process_block_lnki_div(); // NOTE: __TOC__ will manually place <div toc> here; simulate div in order to close any pres; EX:\n\s__TOC__; PAGE:de.w: DATE:2014-07-05
ctx.Subs_add(root, tkn_mkr.Under(bgn_pos, cur_pos, kwd_id)); // NOTE: only save under_tkn for TOC (b/c its position is needed for insertion); DATE:2013-07-01
break;
case Xol_kwd_grp_.Id_forcetoc: hdr_mgr.Flag__forcetoc_y_(); break;
case Xol_kwd_grp_.Id_notoc: hdr_mgr.Flag__notoc_y_(); break;
case Xol_kwd_grp_.Id_forcetoc: ctx.Page_data().Hdr_forcetoc_y_(); break;
case Xol_kwd_grp_.Id_notoc: ctx.Page_data().Hdr_notoc_y_(); break;
case Xol_kwd_grp_.Id_noeditsection: break; // ignore; not handling edit sections
case Xol_kwd_grp_.Id_nocontentconvert: page.Html_data().Lang_convert_content_(false); break;
case Xol_kwd_grp_.Id_notitleconvert: page.Html_data().Lang_convert_title_(false); break;
case Xol_kwd_grp_.Id_nocontentconvert: ctx.Page_data().Lang_convert_content_(false); break;
case Xol_kwd_grp_.Id_notitleconvert: ctx.Page_data().Lang_convert_title_(false); break;
default: break; // ignore anything else
}
}

View File

@ -101,12 +101,12 @@ public class Xop_under_lxr_tst {
fxt.Test_parse_page_all_str("__DISAMBIG__", "");
}
@Test public void Nocontentconvert() { // simple test; test for flag only; DATE:2014-02-06
gplx.xowa.wikis.pages.htmls.Xopg_html_data html_data = fxt.Page().Html_data();
Tfds.Eq(html_data.Lang_convert_content(), true);
Tfds.Eq(html_data.Lang_convert_title(), true);
gplx.xowa.parsers.Xop_ctx_page_data page_data = fxt.Ctx().Page_data();
Tfds.Eq(page_data.Lang_convert_content(), true);
Tfds.Eq(page_data.Lang_convert_title(), true);
fxt.Test_parse_page_all_str("__NOCONTENTCONVERT__ __NOTITLECONVERT__", " ");
Tfds.Eq(html_data.Lang_convert_content(), false);
Tfds.Eq(html_data.Lang_convert_title(), false);
Tfds.Eq(page_data.Lang_convert_content(), false);
Tfds.Eq(page_data.Lang_convert_title(), false);
}
@Test public void Eos() { // PURPOSE: check that __ at eos doesn't fail; es.s:Luisa de Bustamante: 3; DATE:2014-02-15
fxt.Test_parse_page_all_str("__", "__");
@ -187,4 +187,40 @@ public class Xop_under_lxr_tst {
fxt.Test_parse_page_all_str("a__NOTOC__b" , "ab"); // cs.pass
fxt.Test_parse_page_all_str("a__notoc__b" , "a__notoc__b"); // cs.fail
}
@Test public void Notoc_in_tmpl() { // PURPOSE: test simultaneous cs and ci; DATE:2017-06-11
fxt.Init_page_create("Template:Notoc", "page_text\n__NOTOC__");
fxt.Wiki().Html_mgr().Html_wtr().Cfg().Toc__show_(true);
fxt.Test__parse_to_html_w_skin(String_.Concat_lines_nl
( "==A1=="
, "==A2=="
, "==A3=="
, "==A4=="
, "{{Notoc}}"
), String_.Concat_lines_nl
( "<div id=\"toc\" class=\"toc\">"
, " <div id=\"toctitle\">"
, " <h2>Contents</h2>"
, " </div>"
, " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#A1\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">A1</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#A2\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">A2</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#A3\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">A3</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#A4\"><span class=\"tocnumber\">4</span> <span class=\"toctext\">A4</span></a>"
, " </li>"
, " </ul>"
, "</div>"
, "<h2><span class=\"mw-headline\" id=\"A1\">A1</span></h2>"
, ""
, "<h2><span class=\"mw-headline\" id=\"A2\">A2</span></h2>"
, ""
, "<h2><span class=\"mw-headline\" id=\"A3\">A3</span></h2>"
, ""
, "<h2><span class=\"mw-headline\" id=\"A4\">A4</span></h2>"
, "page_text"
));
}
}

View File

@ -285,7 +285,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
bfr.Add(rslt);
}
else {
rv = defn_tmpl.Tmpl_evaluate(ctx, invk_tmpl, rslt_bfr);
rv = defn_tmpl.Tmpl_evaluate(Xop_ctx.New__sub(wiki, ctx, ctx.Page()), invk_tmpl, rslt_bfr); // DATE:2017-06-13
prepend_mgr.End(ctx, bfr, rslt_bfr.Bfr(), rslt_bfr.Len(), Bool_.Y);
if (name_had_subst) { // current invk had "subst:"; parse incoming invk again to remove effects of subst; PAGE:pt.w:Argentina DATE:2014-09-24
byte[] tmp_src = rslt_bfr.To_bry_and_clear();

View File

@ -55,7 +55,7 @@ public class Xot_invk_tkn_ {
if (tmpl_page_bry != null) {
byte old_parse_tid = ctx.Parse_tid(); // NOTE: reusing ctxs is a bad idea; will change Parse_tid and cause strange errors; however, keeping for PERF reasons
Xow_ns ns_tmpl = wiki.Ns_mgr().Ns_template();
rv = wiki.Parser_mgr().Main().Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), ns_tmpl, name_ary, tmpl_page_bry);
rv = wiki.Parser_mgr().Main().Parse_text_to_defn_obj(Xop_ctx.New__sub(wiki, ctx, ctx.Page()), ctx.Tkn_mkr(), ns_tmpl, name_ary, tmpl_page_bry); // DATE:2017-06-13
Xoa_ttl tmpl_page_ttl = tmpl_page_itm.Ttl();
byte[] frame_ttl = Bry_.Add(tmpl_page_ttl.Ns().Name_db(), Byte_ascii.Colon_bry, tmpl_page_ttl.Page_txt()); // NOTE: (1) must have ns (Full); (2) must be txt (space, not underscore); EX:Template:Location map+; DATE:2014-08-22; (3) must be local language; Russian "Шаблон" not English "Template"; PAGE:ru.w:Королевство_Нидерландов DATE:2016-11-23
rv.Frame_ttl_(frame_ttl); // set defn's frame_ttl; needed for redirect_trg; PAGE:en.w:Statutory_city; DATE:2014-08-22

View File

@ -846,6 +846,8 @@ public class Xow_domain_regy {
, "jam.wikipedia.org"
, "tcy.wikipedia.org"
, "olo.wikipedia.org"
, "dty.wikipedia.org"
, "pa.wikisource.org"
};
//, "als.wikisource.org"
//, "als.wikinews.org"

View File

@ -26,10 +26,10 @@ public class Xopg_toc_mgr {
)
;
}
public boolean Flag__toc() {return flag__toc;}
public void Flag__toc_y_() {flag__toc = true;} private boolean flag__toc; // __TOC__
public void Flag__forcetoc_y_() {flag__forcetoc = true;} private boolean flag__forcetoc; // __FORCETOC__
public void Flag__notoc_y_() {flag__notoc = true;} private boolean flag__notoc; // __NOTOC__
public boolean Flag__toc() {return flag__toc;}
public void Flag__toc_(boolean v) {flag__toc = v;} private boolean flag__toc; // __TOC__
public void Flag__forcetoc_(boolean v) {flag__forcetoc = v;} private boolean flag__forcetoc; // __FORCETOC__
public void Flag__notoc_(boolean v) {flag__notoc = v;} private boolean flag__notoc; // __NOTOC__
public int Len() {return hdrs_len;}
public Xop_hdr_tkn Get_at(int i) {return hdrs_ary[i];}

View File

@ -101,7 +101,7 @@ public class Pgbnr_func extends Pf_func_base {
itm.Init_from_wtxt(banner_ttl, banner_file_itm, tooltip, title, bottomtoc, toc, data_pos_x, data_pos_y, origin_x, icons_list == null ? Pgbnr_icon.Ary_empty : (Pgbnr_icon[])icons_list.To_ary_and_clear(Pgbnr_icon.class));
page.Html_data().Xtn_pgbnr_(itm);
page.Html_data().Head_mgr().Itm__pgbnr().Enabled_y_(); // register css / js during parse stage
page.Wtxt().Toc().Flag__toc_y_(); // NOTE: must mark toc_manual else will show 2nd TOC in edit mode; DATE:2016-07-10
page.Wtxt().Toc().Flag__toc_(true); // NOTE: must mark toc_manual else will show 2nd TOC in edit mode; DATE:2016-07-10
}
public static void Add_banner(Bry_bfr bfr, Xoae_page wpg, Xop_ctx ctx, Xoh_wtr_ctx hctx, Pgbnr_itm itm) {
Xowe_wiki wiki = ctx.Wiki(); Xoae_app app = wiki.Appe();