mirror of
https://github.com/gnosygnu/xowa.git
synced 2025-06-02 07:24:19 +00:00
References: Ignore follow items when writing primary reference [#555]
This commit is contained in:
parent
1873c7c5f8
commit
d61fd33a87
@ -75,16 +75,20 @@ public class Ref_html_wtr {
|
||||
Bry_bfr tmp = Bry_bfr_.New();
|
||||
int list_len = List_len(head_itm);
|
||||
grp_list_fmtr.Init(ctx.Wiki(), cfg, head_itm);
|
||||
Ref_nde text_itm = grp_list_fmtr.IdentifyTxt(); // find the item that has the text (there should only be 0 or 1)
|
||||
if (text_itm.Body() != null)
|
||||
Ref_nde text_itm = grp_list_fmtr.Identify_main_ref();// find the item that has the text (there should only be 0 or 1)
|
||||
if (text_itm.Body() != null) {
|
||||
wtr.Write_tkn_to_html(tmp, ctx, opts, text_itm.Body().Root_src(), null, Xoh_html_wtr.Sub_idx_null, text_itm.Body());
|
||||
}
|
||||
|
||||
// add follows
|
||||
int related_len = head_itm.Related_len();
|
||||
for (int k = 0; k < related_len; k++) {
|
||||
Ref_nde related_itm = head_itm.Related_get(k);
|
||||
if (related_itm.Follow_y()) { // NOTE: both follow and related are in the related list; only add follow
|
||||
tmp.Add_byte_space(); // always add space; REF.MW:Cite_body.php;$this->mRefs[$group][$follow]['text'] = $this->mRefs[$group][$follow]['text'] . ' ' . $str;
|
||||
if (related_itm.Follow_y()) { // NOTE: both follow and related are in the related list; only add follow
|
||||
// add a space if...
|
||||
if (tmp.Len_gt_0() // tmp has text; (ignores 0th)
|
||||
&& related_itm.Body() != null && related_itm.Body().Subs_len() > 0) // this item has text (ignore blank items)
|
||||
tmp.Add_byte_space();// add space; REF.MW:Cite_body.php;$this->mRefs[$group][$follow]['text'] = $this->mRefs[$group][$follow]['text'] . ' ' . $str;
|
||||
wtr.Write_tkn_to_html(tmp, ctx, opts, related_itm.Body().Root_src(), null, Xoh_html_wtr.Sub_idx_null, related_itm.Body());
|
||||
}
|
||||
}
|
||||
|
@ -40,17 +40,21 @@ public class Ref_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
}
|
||||
}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
if (ctx.Tid_is_popup()) return;
|
||||
if (ctx.Tid_is_popup()) return; // popups don't show <ref>
|
||||
Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde);
|
||||
if (xnde.CloseMode() == Xop_xnde_tkn.CloseMode_pair)
|
||||
body = wiki.Parser_mgr().Main().Parse_text_to_wdom_old_ctx(ctx, Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn()), false);
|
||||
byte[] references_group = ctx.References_group(); // set by <references>
|
||||
|
||||
// override "group" if inside "<references>"
|
||||
byte[] references_group = ctx.References_group();
|
||||
if (references_group != null) {
|
||||
group = references_group; // override <ref group> with <references group>; note that MW throws an error if nested <ref> has different group than outer <references>; Cite error: <ref> tag in <references> has conflicting group attribute "a".
|
||||
group = references_group; // override <ref group> with <references group>; note that MW throws an error if nested <ref> has different group than outer <references>; Cite error: <ref> tag in <references> has conflicting group attribute "a".
|
||||
head = true;
|
||||
nested = true; // refs nested in references don't show <a> entry in <references>
|
||||
nested = true; // refs nested in references don't show <a> entry in <references>
|
||||
}
|
||||
if (!ctx.Ref_ignore()) // sub_ctx may be marked to ignore <ref>; EX: <pages>,{{#lst}}; DATE:2014-04-24
|
||||
|
||||
// register <ref>
|
||||
if (!ctx.Ref_ignore()) // sub_ctx may be marked to ignore <ref>; EX: <pages>,{{#lst}}; DATE:2014-04-24
|
||||
ctx.Page().Ref_mgr().Grps_add(group, name, follow, this);
|
||||
this.xnde = xnde;
|
||||
}
|
||||
|
@ -28,14 +28,20 @@ public class References_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
}
|
||||
}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
if (ctx.Tid_is_popup()) return;
|
||||
if (ctx.Tid_is_popup()) return; // popups don't show <references>
|
||||
|
||||
// handle <references> inside <references>
|
||||
Ref_itm_mgr ref_mgr = ctx.Page().Ref_mgr();
|
||||
if (ref_mgr.References__recursing()) {
|
||||
xnde.Tag_visible_(false); // NOTE:do not print empty <references/> tag; especially necessary for recursing references; PAGE:cs.s:Page:Hejčl,_Jan_-_Pentateuch.pdf/128 DATE:2016-09-01
|
||||
return; // skip nested <references> else refs will be lost; EX:"<references><references/></references>"; PAGE:en.w:Hwair; DATE:2014-06-27
|
||||
}
|
||||
|
||||
// complete parsing
|
||||
ctx.Para().Process_block__bgn_n__end_y(Xop_xnde_tag_.Tag__div); // xnde generates <block_node>; <references> -> <ol>; close any blocks; PAGE:fr.w:Heidi_(roman); DATE:2014-02-17
|
||||
Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde);
|
||||
|
||||
// <references></references>: kick off another parsing with the inner text
|
||||
if (xnde.CloseMode() == Xop_xnde_tkn.CloseMode_pair) { // "<references>", "</references>"; parse anything in between but only to pick up <ref> tags; discard everything else; DATE:2014-06-27
|
||||
int itm_bgn = xnde.Tag_open_end(), itm_end = xnde.Tag_close_bgn();
|
||||
Xop_ctx references_ctx = Xop_ctx.New__sub__reuse_lst(wiki, ctx, ctx.Lst_page_regy()).References_group_(group); // changed from following: "Xop_ctx references_ctx = Xop_ctx.New__sub(wiki).References_group_(group);"; DATE:2015-05-16;
|
||||
|
@ -181,7 +181,7 @@ public class References_nde_basic_tst {
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Follow() {
|
||||
@Test public void Follow__main_and_follow_have_text() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref name='ref_a'>x</ref>"
|
||||
, "<ref>y</ref>"
|
||||
@ -197,4 +197,30 @@ public class References_nde_basic_tst {
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Follow__follow_only_has_text() {// ISSUE#:555; DATE:2019-09-01
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref name='ref1'/>"
|
||||
, "<ref follow='ref1'>abc</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-ref1_0-0\" class=\"reference\"><a href=\"#cite_note-ref1-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-ref1-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-ref1_0-0\">a</a></sup></span> <span class=\"reference-text\">abc</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Follow__main_only_has_text() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref name='ref1'>abc</ref>"
|
||||
, "<ref follow='ref1'></ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-ref1_0-0\" class=\"reference\"><a href=\"#cite_note-ref1-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-ref1-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-ref1_0-0\">a</a></sup></span> <span class=\"reference-text\">abc</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,12 @@ class Xoh_ref_list_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
public void Init(Xowe_wiki wiki, Ref_html_wtr_cfg cfg, Ref_nde itm) {
|
||||
this.wiki = wiki; this.cfg = cfg; this.itm = itm;
|
||||
}
|
||||
public Ref_nde IdentifyTxt() {
|
||||
public Ref_nde Identify_main_ref() {
|
||||
if (HasTxt(itm)) return itm;
|
||||
int itm_related_len = itm.Related_len();
|
||||
for (int i = 0; i < itm_related_len; i++) {
|
||||
Ref_nde rel = itm.Related_get(i);
|
||||
if (rel.Follow_y()) continue; // follow should not be the main item; will be picked up in separate loop later; ISSUE#:555; DATE:2019-09-01
|
||||
if (HasTxt(rel)) return rel;
|
||||
}
|
||||
return itm; // no itm has text; TODO_OLD:WARN
|
||||
|
Loading…
Reference in New Issue
Block a user