mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Section_edit: Add initial groundwork for generating html
This commit is contained in:
@@ -18,17 +18,24 @@ 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.*;
|
||||
public class Xop_hdr_tkn extends Xop_tkn_itm_base {
|
||||
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;}
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_hdr;}
|
||||
public int Num() {return num;} private int num = -1; // EX: 2 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 int Section_editable_idx() {return section_editable_idx;} private int section_editable_idx; // EX: 1 as in "section=1"
|
||||
public byte[] Section_editable_page() {return section_editable_page;} private byte[] section_editable_page; // EX: Earth as in 'href="/wiki/Earth"'
|
||||
|
||||
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 void Init_by_section_editable(int section_editable_idx, byte[] section_editable_page) {
|
||||
this.section_editable_idx = section_editable_idx;
|
||||
this.section_editable_page = section_editable_page;
|
||||
}
|
||||
|
||||
public static final Xop_hdr_tkn[] Ary_empty = new Xop_hdr_tkn[0];
|
||||
}
|
||||
|
||||
@@ -48,8 +48,12 @@ public class Xop_hdr_wkr implements Xop_ctx_wkr {
|
||||
}
|
||||
public int Make_tkn_end(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos, int stackPos, int end_hdr_len) {// REF.MW: Parser|doHeadings
|
||||
if (ctx.Cur_tkn_tid() == Xop_tkn_itm_.Tid_tmpl_curly_bgn) return ctx.Lxr_make_txt_(cur_pos);
|
||||
|
||||
// end frame
|
||||
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==
|
||||
|
||||
// handle asymmetrical "="; EX: "== A ==="
|
||||
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
|
||||
@@ -71,8 +75,12 @@ public class Xop_hdr_wkr implements Xop_ctx_wkr {
|
||||
}
|
||||
if (dirty)
|
||||
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/>
|
||||
|
||||
// gobble ws; hdr gobbles up trailing ws; EX: "==a== \n\t \n \nb" gobbles up all 3 "\n"s; otherwise para_wkr will process <br/>
|
||||
cur_pos = Find_fwd_while_ws_hdr_version(src, cur_pos, src_len);
|
||||
ctx.Para().Process_block__bgn_n__end_y(Xop_xnde_tag_.Tag__h2);
|
||||
|
||||
// add to root tkn; other post-processing
|
||||
hdr.Subs_move(root);
|
||||
hdr.Src_end_(cur_pos);
|
||||
if (ctx.Parse_tid() == Xop_parser_tid_.Tid__wtxt) { // do not add if defn / tmpl mode
|
||||
|
||||
Reference in New Issue
Block a user