1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00

Html: Change self-link pages from <b> to <a class='mw-selflink selflink'> [#478]

This commit is contained in:
gnosygnu 2019-06-02 21:11:51 -04:00
parent 3852d4762b
commit c7f54287af
3 changed files with 18 additions and 13 deletions

View File

@ -37,7 +37,7 @@ public class Xoh_html_wtr_tst {
} }
@Test public void Lnki_category() {fxt.Test_parse_page_wiki_str("[[Category:A]]" , "");} // NOTE: Category does not get written in main page bfr @Test public void Lnki_category() {fxt.Test_parse_page_wiki_str("[[Category:A]]" , "");} // NOTE: Category does not get written in main page bfr
@Test public void Lnki_category_force() {fxt.Test_parse_page_wiki_str("[[:Category:A]]" , "<a href=\"/wiki/Category:A\">Category:A</a>");} @Test public void Lnki_category_force() {fxt.Test_parse_page_wiki_str("[[:Category:A]]" , "<a href=\"/wiki/Category:A\">Category:A</a>");}
@Test public void Lnki_matches_page() {fxt.Test_parse_page_wiki_str("[[test page|t1]]", "<b>t1</b>");} // NOTE: "Test page" is hardcoded to be the test page name @Test public void Lnki_matches_page() {fxt.Test_parse_page_wiki_str("[[test page|t1]]", "<a class=\"mw-selflink selflink\">t1</a>");} // NOTE: "Test page" is hardcoded to be the test page name
@Test public void Lnki_matches_page_but_has_anchor() {fxt.Test_parse_page_wiki_str("[[Test page#a|test 1]]", "<a href=\"/wiki/Test_page#a\">test 1</a>");} // NOTE: "Test page" is hardcoded to be the test page name @Test public void Lnki_matches_page_but_has_anchor() {fxt.Test_parse_page_wiki_str("[[Test page#a|test 1]]", "<a href=\"/wiki/Test_page#a\">test 1</a>");} // NOTE: "Test page" is hardcoded to be the test page name
@Test public void Lnki_anchor() {fxt.Test_parse_page_wiki_str("[[A#b]]" , "<a href=\"/wiki/A#b\">A#b</a>");} @Test public void Lnki_anchor() {fxt.Test_parse_page_wiki_str("[[A#b]]" , "<a href=\"/wiki/A#b\">A#b</a>");}
// @Test public void Img_invalid_wnt_char() { // @Test public void Img_invalid_wnt_char() {

View File

@ -102,14 +102,18 @@ public class Xoh_lnki_wtr {
private void Write_plain(Bry_bfr bfr, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xoa_ttl lnki_ttl, Xop_lnki_caption_wtr caption_wkr) { private void Write_plain(Bry_bfr bfr, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xoa_ttl lnki_ttl, Xop_lnki_caption_wtr caption_wkr) {
byte[] ttl_bry = lnki.Ttl_ary(); byte[] ttl_bry = lnki.Ttl_ary();
if (Bry_.Len_eq_0(ttl_bry)) ttl_bry = lnki_ttl.Full_txt_raw(); // NOTE: handles ttls like [[fr:]] and [[:fr;]] which have an empty Page_txt, but a valued Full_txt_raw if (Bry_.Len_eq_0(ttl_bry)) ttl_bry = lnki_ttl.Full_txt_raw(); // NOTE: handles ttls like [[fr:]] and [[:fr;]] which have an empty Page_txt, but a valued Full_txt_raw
if (Bry_.Eq(lnki_ttl.Full_txt_by_orig(), page.Ttl().Full_txt_by_orig())) { // lnki is same as pagename; bold; SEE: Month widget on day pages will bold current day; PAGE:en.w:January 1
if (lnki_ttl.Anch_bgn() == -1 && Bry_.Eq(lnki_ttl.Wik_txt(), page.Ttl().Wik_txt())) { // only bold if lnki is not pointing to anchor on same page; PAGE:en.w:Comet; [[Comet#Physical characteristics|ion tail]] // lnki is same as pagename; PAGE:en.w:January 1
bfr.Add(Gfh_tag_.B_lhs); if ( Bry_.Eq(lnki_ttl.Full_txt_by_orig(), page.Ttl().Full_txt_by_orig())
Write_caption(bfr, ctx, hctx, src, lnki, ttl_bry, true, caption_wkr); && lnki_ttl.Anch_bgn() == -1 && Bry_.Eq(lnki_ttl.Wik_txt(), page.Ttl().Wik_txt())) { // only bold if lnki is not pointing to anchor on same page; PAGE:en.w:Comet; [[Comet#Physical characteristics|ion tail]]
bfr.Add(Gfh_tag_.B_rhs); bfr.Add(Gfh_bldr_.Bry__a_lhs_bgn);
return; Gfh_wtr.Write_atr_bry(bfr, Gfh_atr_.Bry__class, Bry__selflink);
} bfr.Add(Gfh_bldr_.Bry__lhs_end_head);
Write_caption(bfr, ctx, hctx, src, lnki, ttl_bry, true, caption_wkr);
bfr.Add(Gfh_bldr_.Bry__a_rhs);
return;
} }
if (lnki.Xtn_sites_link()) return; // lnki marked for relatedSites; don't write to page if (lnki.Xtn_sites_link()) return; // lnki marked for relatedSites; don't write to page
page.Stat_itm().Lnki_count++; page.Stat_itm().Lnki_count++;
if (hctx.Mode_is_alt()) if (hctx.Mode_is_alt())
@ -195,6 +199,7 @@ public class Xoh_lnki_wtr {
return history_mgr.Has(wiki_key, page_ttl) ? Lnki_cls_visited_bry : Bry_.Empty; return history_mgr.Has(wiki_key, page_ttl) ? Lnki_cls_visited_bry : Bry_.Empty;
} private static final byte[] Lnki_cls_visited_bry = Bry_.new_a7(" class=\"xowa-visited\""); } private static final byte[] Lnki_cls_visited_bry = Bry_.new_a7(" class=\"xowa-visited\"");
private static final byte[] Bry_xowa_visited = Bry_.new_a7("\" class=\"xowa-visited"); private static final byte[] Bry_xowa_visited = Bry_.new_a7("\" class=\"xowa-visited");
private static final byte[] Bry__selflink = Bry_.new_a7("mw-selflink selflink");
public static final int Lnki_id_ignore = 0, Lnki_id_min = 1; public static final int Lnki_id_ignore = 0, Lnki_id_min = 1;
} }
interface Xop_lnki_caption_wtr { interface Xop_lnki_caption_wtr {

View File

@ -74,7 +74,7 @@ public class Pp_pages_nde_hdr_tst {
// next only // next only
fxt.Page_ttl_("Page/1"); fxt.Page_ttl_("Page/1");
fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl
( "<p>value=toc;current=<b>Page/1</b>;next=<a href=\"/wiki/Page/2\">Page/2</a>;" ( "<p>value=toc;current=<a class=\"mw-selflink selflink\">Page/1</a>;next=<a href=\"/wiki/Page/2\">Page/2</a>;"
, "</p>" , "</p>"
, "" , ""
, "<p><br/>" , "<p><br/>"
@ -84,7 +84,7 @@ public class Pp_pages_nde_hdr_tst {
// next and prev // next and prev
fxt.Page_ttl_("Page/2"); fxt.Page_ttl_("Page/2");
fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl
( "<p>value=toc;current=<b>Page/2</b>;prev=<a href=\"/wiki/Page/1\">Page/1</a>;next=<a href=\"/wiki/Page/3\">Page/3</a>;" ( "<p>value=toc;current=<a class=\"mw-selflink selflink\">Page/2</a>;prev=<a href=\"/wiki/Page/1\">Page/1</a>;next=<a href=\"/wiki/Page/3\">Page/3</a>;"
, "</p>" , "</p>"
, "" , ""
, "<p><br/>" , "<p><br/>"
@ -94,7 +94,7 @@ public class Pp_pages_nde_hdr_tst {
// prev only // prev only
fxt.Page_ttl_("Page/3"); fxt.Page_ttl_("Page/3");
fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl
( "<p>value=toc;current=<b>Page/3</b>;prev=<a href=\"/wiki/Page/2\">Page/2</a>;" ( "<p>value=toc;current=<a class=\"mw-selflink selflink\">Page/3</a>;prev=<a href=\"/wiki/Page/2\">Page/2</a>;"
, "</p>" , "</p>"
, "" , ""
, "<p><br/>" , "<p><br/>"
@ -129,7 +129,7 @@ public class Pp_pages_nde_hdr_tst {
fxt.Page_ttl_("Page/2"); fxt.Page_ttl_("Page/2");
fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl
( "<p>value=toc;current=<b>Page/2</b>;prev=<a href=\"/wiki/Page/1\">Caption_1</a>;next=<a href=\"/wiki/Page/3\">Page/3</a>;" ( "<p>value=toc;current=<a class=\"mw-selflink selflink\">Page/2</a>;prev=<a href=\"/wiki/Page/1\">Caption_1</a>;next=<a href=\"/wiki/Page/3\">Page/3</a>;"
, "</p>" , "</p>"
, "" , ""
, "<p><br/>" , "<p><br/>"
@ -145,7 +145,7 @@ public class Pp_pages_nde_hdr_tst {
// next only // next only
fxt.Page_ttl_("Page/1"); fxt.Page_ttl_("Page/1");
fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl
( "<p>value=toc;current=<b>Page/1</b>;next=<a href=\"/site/commons.wikimedia.org/wiki/File:A.png\">File:A.png</a>;" ( "<p>value=toc;current=<a class=\"mw-selflink selflink\">Page/1</a>;next=<a href=\"/site/commons.wikimedia.org/wiki/File:A.png\">File:A.png</a>;"
, "</p>" , "</p>"
, "" , ""
, "<p><br/>" , "<p><br/>"