From d61fd33a87f1917f60ff2417d5780b5015c6bfa1 Mon Sep 17 00:00:00 2001 From: gnosygnu Date: Sun, 1 Sep 2019 10:29:55 -0400 Subject: [PATCH] References: Ignore follow items when writing primary reference [#555] --- .../gplx/xowa/xtns/cites/Ref_html_wtr.java | 12 +++++--- .../src/gplx/xowa/xtns/cites/Ref_nde.java | 14 ++++++---- .../gplx/xowa/xtns/cites/References_nde.java | 8 +++++- .../xtns/cites/References_nde_basic_tst.java | 28 ++++++++++++++++++- .../xowa/xtns/cites/Xoh_ref_list_fmtr.java | 3 +- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/400_xowa/src/gplx/xowa/xtns/cites/Ref_html_wtr.java b/400_xowa/src/gplx/xowa/xtns/cites/Ref_html_wtr.java index 3639cd06a..3e64eef7e 100644 --- a/400_xowa/src/gplx/xowa/xtns/cites/Ref_html_wtr.java +++ b/400_xowa/src/gplx/xowa/xtns/cites/Ref_html_wtr.java @@ -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()); } } diff --git a/400_xowa/src/gplx/xowa/xtns/cites/Ref_nde.java b/400_xowa/src/gplx/xowa/xtns/cites/Ref_nde.java index 14eac94bd..9bf0e6fdf 100644 --- a/400_xowa/src/gplx/xowa/xtns/cites/Ref_nde.java +++ b/400_xowa/src/gplx/xowa/xtns/cites/Ref_nde.java @@ -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 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 + + // override "group" if inside "" + byte[] references_group = ctx.References_group(); if (references_group != null) { - group = references_group; // override with ; note that MW throws an error if nested has different group than outer ; Cite error: tag in has conflicting group attribute "a". + group = references_group; // override with ; note that MW throws an error if nested has different group than outer ; Cite error: tag in has conflicting group attribute "a". head = true; - nested = true; // refs nested in references don't show entry in + nested = true; // refs nested in references don't show entry in } - if (!ctx.Ref_ignore()) // sub_ctx may be marked to ignore ; EX: ,{{#lst}}; DATE:2014-04-24 + + // register + if (!ctx.Ref_ignore()) // sub_ctx may be marked to ignore ; EX: ,{{#lst}}; DATE:2014-04-24 ctx.Page().Ref_mgr().Grps_add(group, name, follow, this); this.xnde = xnde; } diff --git a/400_xowa/src/gplx/xowa/xtns/cites/References_nde.java b/400_xowa/src/gplx/xowa/xtns/cites/References_nde.java index d25693648..6abe2ed81 100644 --- a/400_xowa/src/gplx/xowa/xtns/cites/References_nde.java +++ b/400_xowa/src/gplx/xowa/xtns/cites/References_nde.java @@ -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 + + // handle inside Ref_itm_mgr ref_mgr = ctx.Page().Ref_mgr(); if (ref_mgr.References__recursing()) { xnde.Tag_visible_(false); // NOTE:do not print empty tag; especially necessary for recursing references; PAGE:cs.s:Page:HejĨl,_Jan_-_Pentateuch.pdf/128 DATE:2016-09-01 return; // skip nested else refs will be lost; EX:""; 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 ; ->
    ; close any blocks; PAGE:fr.w:Heidi_(roman); DATE:2014-02-17 Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde); + + // : kick off another parsing with the inner text if (xnde.CloseMode() == Xop_xnde_tkn.CloseMode_pair) { // "", ""; parse anything in between but only to pick up 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; diff --git a/400_xowa/src/gplx/xowa/xtns/cites/References_nde_basic_tst.java b/400_xowa/src/gplx/xowa/xtns/cites/References_nde_basic_tst.java index d29f67800..c10a0b8c0 100644 --- a/400_xowa/src/gplx/xowa/xtns/cites/References_nde_basic_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/cites/References_nde_basic_tst.java @@ -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 ( "x" , "y" @@ -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 + ( "" + , "abc" + , "" + ), String_.Concat_lines_nl_skip_last + ( "[1]" + , "
      " + , "
    1. ^ a abc
    2. " + , "
    " + , "" + )); + } + @Test public void Follow__main_only_has_text() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "abc" + , "" + , "" + ), String_.Concat_lines_nl_skip_last + ( "[1]" + , "
      " + , "
    1. ^ a abc
    2. " + , "
    " + , "" + )); + } } diff --git a/400_xowa/src/gplx/xowa/xtns/cites/Xoh_ref_list_fmtr.java b/400_xowa/src/gplx/xowa/xtns/cites/Xoh_ref_list_fmtr.java index b1bd79abf..bb10d0c6d 100644 --- a/400_xowa/src/gplx/xowa/xtns/cites/Xoh_ref_list_fmtr.java +++ b/400_xowa/src/gplx/xowa/xtns/cites/Xoh_ref_list_fmtr.java @@ -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