1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2025-06-02 07:24:19 +00:00

Parser.Lnki: Treat keywords as caption if not File namespace or if keyless [#303]

This commit is contained in:
gnosygnu 2019-03-24 10:23:22 -04:00
parent ef0300dfeb
commit 2dfa751958
2 changed files with 36 additions and 9 deletions

View File

@ -102,15 +102,26 @@ public class Xop_lnki_wkr implements Xop_ctx_wkr, Xop_arg_wkr {
arg_tid = Xop_lnki_arg_parser.Tid_target;
}
// if just "class" or "alt", treat as caption; EX:[[A|alt]] -> caption=alt x> caption=A ISSUE#:303 DATE:2018-12-16
switch (arg_tid) {
case Xop_lnki_arg_parser.Tid_class:
case Xop_lnki_arg_parser.Tid_alt:
if (!arg.KeyTkn_exists()){
arg_tid = Xop_lnki_arg_parser.Tid_caption;
}
break;
// if not File / Media ns, then treat as caption; ISSUE#:303; DATE:2019-03-24
if (lnki.Ttl() != null && !lnki.Ttl().Ns().Id_is_file_or_media()) {
arg_tid = Xop_lnki_arg_parser.Tid_caption;
}
// if key-less keyword, treat as caption; EX:[[File:A.png|alt]] -> caption=alt x> caption=A.png ISSUE#:303 DATE:2018-12-16
else {
switch (arg_tid) {
case Xop_lnki_arg_parser.Tid_class:
case Xop_lnki_arg_parser.Tid_alt:
case Xop_lnki_arg_parser.Tid_link:
case Xop_lnki_arg_parser.Tid_page:
case Xop_lnki_arg_parser.Tid_thumbtime:
// case Xop_lnki_arg_parser.Tid_noicon: TODO: uncomment b/c keyword is deprecated; WHEN: when integrating TimedMediaHandler; REF.MW:https://www.mediawiki.org/wiki/Extension:TimedMediaHandler; DATE:2019-03-24
if (!arg.KeyTkn_exists()){
arg_tid = Xop_lnki_arg_parser.Tid_caption;
}
break;
}
}
switch (arg_tid) {
case Xop_lnki_arg_parser.Tid_none: lnki.Align_h_(Xop_lnki_type.Id_none); break;
case Xop_lnki_arg_parser.Tid_border: lnki.Border_(Bool_.Y_byte); break;

View File

@ -312,9 +312,25 @@ public class Xop_lnki_wkr__basic_tst {
fxt.Test_parse_page_all_str("[[Src]]" , "<a href=\"/wiki/Src\" class=\"xowa-visited\">Src</a>"); // show [[Src]] as visited since it exists in history
fxt.Test_parse_page_all_str("[[Other]]" , "<a href=\"/wiki/Other\">Other</a>"); // show other pages as not visited
}
@Test public void Caption__outlier() {
@Test public void File_keywords__ignore_if_not_file_ns() { // ISSUE#:303 DATE:2019-03-24
fxt.Test_parse_page_all_str("[[A|class]]", "<a href=\"/wiki/A\">class</a>");
fxt.Test_parse_page_all_str("[[A|alt]]", "<a href=\"/wiki/A\">alt</a>");
fxt.Test_parse_page_all_str("[[A|sub]]", "<a href=\"/wiki/A\">sub</a>");
fxt.Test_parse_page_all_str("[[A|sup]]", "<a href=\"/wiki/A\">sup</a>");
fxt.Test_parse_page_all_str("[[A|alt|a|b]]", "<a href=\"/wiki/A\">alt|a|b</a>");
}
@Test public void File_keywords__ignore_if_no_key() { // ISSUE#:303; DATE:2019-03-24
// assert treated as captions if no key
Test__File_keywords__ignore_if_no_key("class", "alt", "link", "page", "thumbtime");
// assert not treated as captions if no key
fxt.Test_parse_page_all_str("[[File:A.png|top]]", "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>");
}
private void Test__File_keywords__ignore_if_no_key(String... keywords) {
for (String keyword : keywords) {
String wtxt = "[[File:A.png|" + keyword + "]]";
String html = "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"" + keyword + "\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>";
fxt.Test_parse_page_all_str(wtxt, html);
}
}
}