mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.7.3.1'
This commit is contained in:
@@ -16,19 +16,19 @@ 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.parsers.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xop_hdr_tkn extends Xop_tkn_itm_base {
|
||||
public Xop_hdr_tkn(int bgn, int end, int hdr_level) {this.Tkn_ini_pos(false, bgn, end); this.hdr_level = hdr_level;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_hdr;}
|
||||
public int Hdr_level() {return hdr_level;} public Xop_hdr_tkn Hdr_level_(int v) {hdr_level = v; return this;} private int hdr_level = -1;
|
||||
public int Hdr_bgn_manual() {return hdr_bgn_manual;} public Xop_hdr_tkn Hdr_bgn_manual_(int v) {hdr_bgn_manual = v; return this;} private int hdr_bgn_manual;
|
||||
public int Hdr_end_manual() {return hdr_end_manual;} public Xop_hdr_tkn Hdr_end_manual_(int v) {hdr_end_manual = v; return this;} private int hdr_end_manual;
|
||||
public boolean Hdr_html_first() {return hdr_html_first;} public Xop_hdr_tkn Hdr_html_first_y_() {hdr_html_first = true; return this;} private boolean hdr_html_first;
|
||||
public int Hdr_html_dupe_idx() {return hdr_html_dupe_idx;} private int hdr_html_dupe_idx;
|
||||
public byte[] Hdr_html_id() {return hdr_html_id;} public Xop_hdr_tkn Hdr_html_id_(byte[] v) {hdr_html_id = v; return this;} private byte[] hdr_html_id = Bry_.Empty;
|
||||
public byte[] Hdr_toc_text() {return hdr_toc_text;} public Xop_hdr_tkn Hdr_toc_text_(byte[] v) {hdr_toc_text = v; return this;} private byte[] hdr_toc_text;
|
||||
public int Hdr_html_dupe_idx_next() {
|
||||
hdr_html_dupe_idx = hdr_html_dupe_idx == 0 ? 2 : hdr_html_dupe_idx + 1;
|
||||
return hdr_html_dupe_idx;
|
||||
}
|
||||
public Xop_hdr_tkn(int bgn, int end, int num) {this.Tkn_ini_pos(false, bgn, end); this.num = num;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_hdr;}
|
||||
public int Num() {return num;} private int num = -1; // EX: 4 for <h2>
|
||||
public int Manual_bgn() {return manual_bgn;} private int manual_bgn; // unbalanced count; EX: === A == -> 1
|
||||
public int Manual_end() {return manual_end;} private int manual_end; // unbalanced count; EX: == A === -> 1
|
||||
public boolean First_in_doc() {return first_in_doc;} private boolean first_in_doc; // true if 1st hdr in doc
|
||||
public void First_in_doc_y_() {first_in_doc = true;}
|
||||
public void Init_by_parse(int num, int manual_bgn, int manual_end) {
|
||||
this.num = num;
|
||||
this.manual_bgn = manual_bgn;
|
||||
this.manual_end = manual_end;
|
||||
}
|
||||
|
||||
public static final Xop_hdr_tkn[] Ary_empty = new Xop_hdr_tkn[0];
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Xop_hdr_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
@Override public Class<?> TypeOf() {return Xop_hdr_tkn.class;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_hdr;}
|
||||
public int Hdr_len() {return hdr_len;} public Xop_hdr_tkn_chkr Hdr_level_(int v) {hdr_len = v; return this;} private int hdr_len = -1;
|
||||
public int Hdr_ws_bgn() {return hdr_ws_bgn;} public Xop_hdr_tkn_chkr Hdr_ws_bgn_(int v) {hdr_ws_bgn = v; return this;} private int hdr_ws_bgn = -1;
|
||||
public int Hdr_ws_end() {return hdr_ws_end;} public Xop_hdr_tkn_chkr Hdr_ws_end_(int v) {hdr_ws_end = v; return this;} private int hdr_ws_end = -1;
|
||||
public int Hdr_ws_trailing() {return hdr_ws_trailing;} public Xop_hdr_tkn_chkr Hdr_ws_trailing_(int v) {hdr_ws_trailing = v; return this;} private int hdr_ws_trailing = -1;
|
||||
public Xop_hdr_tkn_chkr Hdr_html_id_(String v) {hdr_html_id = Bry_.new_a7(v); return this;} private byte[] hdr_html_id = Bry_.Empty;
|
||||
@Override public int Chk_hook(Tst_mgr mgr, String path, Object actl_obj, int err) {
|
||||
Xop_hdr_tkn actl = (Xop_hdr_tkn)actl_obj;
|
||||
err += mgr.Tst_val(hdr_len == -1, path, "hdr_len", hdr_len, actl.Hdr_level());
|
||||
err += mgr.Tst_val(hdr_html_id == Bry_.Empty, path, "hdr_html_id", String_.new_a7(hdr_html_id), String_.new_a7(actl.Hdr_html_id()));
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,9 @@ public class Xop_hdr_wkr implements Xop_ctx_wkr {
|
||||
public void AutoClose(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos, Xop_tkn_itm tkn) {
|
||||
// bgn never closed; mark inert; EX: "==a"
|
||||
Xop_hdr_tkn bgn = (Xop_hdr_tkn)tkn;
|
||||
int bgn_hdr_len = bgn.Hdr_level();
|
||||
bgn.Hdr_bgn_manual_(bgn_hdr_len);
|
||||
bgn.Hdr_level_(0);
|
||||
if (bgn_hdr_len > 1 && ctx.Parse_tid() == Xop_parser_.Parse_tid_page_wiki) // NOTE: \n= is not uncommon for templates; ignore them;
|
||||
int bgn_hdr_len = bgn.Num();
|
||||
bgn.Init_by_parse(0, bgn_hdr_len, 0);
|
||||
if (bgn_hdr_len > 1 && ctx.Parse_tid() == Xop_parser_tid_.Tid__wtxt) // NOTE: \n= is not uncommon for templates; ignore them;
|
||||
ctx.Msg_log().Add_itm_none(Xop_hdr_log.Dangling_hdr, src, bgn.Src_bgn(), bgn_pos);
|
||||
}
|
||||
public int Make_tkn_bgn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
|
||||
@@ -51,7 +50,7 @@ public class Xop_hdr_wkr implements Xop_ctx_wkr {
|
||||
if (ctx.Cur_tkn_tid() == Xop_tkn_itm_.Tid_tmpl_curly_bgn) return ctx.Lxr_make_txt_(cur_pos);
|
||||
Xop_hdr_tkn hdr = (Xop_hdr_tkn)ctx.Stack_pop_til(root, src, stackPos, false, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_hdr);
|
||||
ctx.Apos().End_frame(ctx, root, src, bgn_pos, false); // end any apos; EX: ==''a==
|
||||
int hdr_len = hdr.Hdr_level(), bgn_manual = 0, end_manual = 0;
|
||||
int hdr_len = hdr.Num(), bgn_manual = 0, end_manual = 0;
|
||||
boolean dirty = false;
|
||||
if (end_hdr_len < hdr_len) { // mismatch: end has more; adjust hdr
|
||||
bgn_manual = hdr_len - end_hdr_len;
|
||||
@@ -65,19 +64,20 @@ public class Xop_hdr_wkr implements Xop_ctx_wkr {
|
||||
ctx.Msg_log().Add_itm_none(Xop_hdr_log.Mismatched, src, bgn_pos, cur_pos);
|
||||
dirty = true;
|
||||
}
|
||||
if (hdr_len > 6) { // <h7>+; limit to 6; NOTE: both bgn/end are equal length; EX: bgn=8,end=7 -> bgn=7,end=7;bgn_manual=1
|
||||
if (hdr_len > 6) { // <h7>+; limit to 6; NOTE: make both bgn/end are equal length; EX: bgn=8,end=7 -> bgn=7,end=7;bgn_manual=1
|
||||
bgn_manual = end_manual = hdr_len - 6;
|
||||
hdr_len = 6;
|
||||
dirty = true;
|
||||
}
|
||||
if (dirty)
|
||||
hdr.Hdr_bgn_manual_(bgn_manual).Hdr_end_manual_(end_manual).Hdr_level_(hdr_len);
|
||||
hdr.Init_by_parse(hdr_len, bgn_manual, end_manual);
|
||||
cur_pos = Find_fwd_while_ws_hdr_version(src, cur_pos, src_len); // NOTE: hdr gobbles up trailing ws; EX: "==a== \n\t \n \nb" gobbles up all 3 "\n"s; otherwise para_wkr will process <br/>
|
||||
ctx.Para().Process_block__bgn_n__end_y(Xop_xnde_tag_.Tag__h2);
|
||||
hdr.Subs_move(root);
|
||||
hdr.Src_end_(cur_pos);
|
||||
if (ctx.Parse_tid() == Xop_parser_.Parse_tid_page_wiki)
|
||||
ctx.Page().Hdr_mgr().Add(ctx, hdr, src);
|
||||
if (ctx.Parse_tid() == Xop_parser_tid_.Tid__wtxt) { // do not add if defn / tmpl mode
|
||||
ctx.Page().Wtxt().Toc().Add(hdr);
|
||||
}
|
||||
return cur_pos;
|
||||
}
|
||||
private void Close_open_itms(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.parsers.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import org.junit.*;
|
||||
public class Xop_hdr_wkr__basic_tst {
|
||||
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@After public void term() {fxt.Init_para_n_();}
|
||||
@Test public void H2() {fxt.Test_parse_page_wiki_str("==a==" , "<h2>a</h2>\n");}
|
||||
@Test public void H3() {fxt.Test_parse_page_wiki_str("===a===" , "<h3>a</h3>\n");}
|
||||
|
||||
Reference in New Issue
Block a user