1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-29 23:10:52 +00:00

Htxt: Register gallery images [#370]

This commit is contained in:
gnosygnu 2019-03-10 20:30:23 -04:00
parent bafa4e31dd
commit 7d747b6d28
5 changed files with 90 additions and 5 deletions

View File

@ -180,6 +180,7 @@ public class Xof_fsdb_itm implements Xof_file_itm {
bfr .Add_int_variable(html_uid); bfr .Add_int_variable(html_uid);
bfr.Add_byte_pipe().Add_int_variable(lnki_exec_tid); bfr.Add_byte_pipe().Add_int_variable(lnki_exec_tid);
bfr.Add_byte_pipe().Add(lnki_wiki_abrv); bfr.Add_byte_pipe().Add(lnki_wiki_abrv);
bfr.Add_byte_pipe().Add(lnki_ttl);
bfr.Add_byte_pipe().Add_int_variable(lnki_type); bfr.Add_byte_pipe().Add_int_variable(lnki_type);
bfr.Add_byte_pipe().Add_double(lnki_upright); bfr.Add_byte_pipe().Add_double(lnki_upright);
bfr.Add_byte_pipe().Add_int_variable(lnki_upright_patch); bfr.Add_byte_pipe().Add_int_variable(lnki_upright_patch);

View File

@ -72,8 +72,16 @@ public class Xoh_hdoc_wkr__make implements Xoh_hdoc_wkr {
bfr.Add_mid(src, img_data.Src_end(), data.Src_end()); bfr.Add_mid(src, img_data.Src_end(), data.Src_end());
} }
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_data data) { public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_data data) {
// <gallery> section; add entire src, and enable gallery flage // <gallery> section; loop itms and call wkr__img on each image while concatenating anything inbetween
bfr.Add_mid(src, data.Src_bgn(), data.Src_end()); int prv = data.Src_bgn();
int len = data.Itms__len();
for (int i = 0; i < len; i++) {
gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_itm_data itm = data.Itms__get_at(i);
bfr.Add_mid(src, prv, itm.Img_data().Src_bgn());
prv = itm.Img_data().Src_end();
wkr__img.Init_by_parse(bfr, hpg, hctx, src, (Xoh_img_data)itm.Img_data());
}
bfr.Add_mid(src, prv, data.Src_end());
hpg.Xtn__gallery_exists_y_(); hpg.Xtn__gallery_exists_y_();
} }
public boolean Process_parse(Xoh_data_itm data) { public boolean Process_parse(Xoh_data_itm data) {

View File

@ -0,0 +1,73 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*; import gplx.xowa.parsers.lnkis.*;
public class Xoh_gly_make__basic__tst {
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
@Before public void Init() {fxt.Clear();}
@Test public void Media_div() {
String orig = String_.Concat_lines_nl_skip_last
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xowa-title='A.png' data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>A1</p>"
, "</div>"
, "</div>"
, "</li>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:B.png' class='image' xowa_title='B.png'><img data-xowa-title='B.png' data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>B1</p>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>abc");
String expd = String_.Concat_lines_nl_skip_last
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img id='xoimg_0' data-xowa-title='A.png' data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>A1</p>"
, "</div>"
, "</div>"
, "</li>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:B.png' class='image' xowa_title='B.png'><img id='xoimg_1' data-xowa-title='B.png' data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>B1</p>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>abc");
fxt.Test__make(orig, fxt.Page_chkr().Body_(expd)
.Imgs__add("en.w", "A.png", Xop_lnki_type.Id_null, -1, 120, 120, -1, -1)
.Imgs__add("en.w", "B.png", Xop_lnki_type.Id_null, -1, 120, 120, -1, -1)
);
}
}

View File

@ -33,7 +33,7 @@ public class Xoh_img_make__dump__tst {
, expd = "<a href='/wiki/File:A%C3%A9_b.png' class='image' title='abc' xowa_title='Aé_b.png'><img id='xoimg_0' data-xowa-title='Aé_b.png' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>" , expd = "<a href='/wiki/File:A%C3%A9_b.png' class='image' title='abc' xowa_title='Aé_b.png'><img id='xoimg_0' data-xowa-title='Aé_b.png' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>"
; ;
fxt.Test__make(orig, fxt.Page_chkr().Body_(expd) fxt.Test__make(orig, fxt.Page_chkr().Body_(expd)
.Imgs__add("en.w", "A.png", Xop_lnki_type.Id_null, 0.5, 220, 110, -1, -1) .Imgs__add("en.w", "Aé_b.png", Xop_lnki_type.Id_null, 0.5, 220, 110, -1, -1)
); );
} }
@Test public void Media_div() { @Test public void Media_div() {
@ -60,7 +60,7 @@ public class Xoh_img_make__dump__tst {
, "</div>" , "</div>"
, "</div>"); , "</div>");
fxt.Test__make(orig, fxt.Page_chkr().Body_(expd) fxt.Test__make(orig, fxt.Page_chkr().Body_(expd)
.Imgs__add("c", "A.png", Xop_lnki_type.Tid_orig_known, -1, 220, -1, -1, -1) .Imgs__add("c", "A.ogv", Xop_lnki_type.Tid_orig_known, -1, 220, -1, -1, -1)
); );
} }
// @Test public void Html_exists__y__cache() { // @Test public void Html_exists__y__cache() {

View File

@ -84,7 +84,10 @@ public class Xoh_img_wtr implements Bfr_arg, Xoh_wtr_itm {
this.fsdb_itm = hpg.Img_mgr().Make_img(data.Img_is_gallery()); this.fsdb_itm = hpg.Img_mgr().Make_img(data.Img_is_gallery());
byte[] file_ttl_bry = data.Anch_xo_ttl().Val(); byte[] file_ttl_bry = data.Anch_xo_ttl().Val();
byte[] lnki_ttl = Xoa_ttl.Replace_spaces(Gfo_url_encoder_.Href_quotes.Decode(data.Img_src().File_ttl_bry())); // NOTE: must decode for fsdb.lnki_ttl as well as xowa_title; EX: A%C3%A9b -> A<EFBFBD>b byte[] img_src_bry_temp = data.Img_src().File_ttl_bry();
byte[] lnki_ttl = img_src_bry_temp == null // img_src will be empty for htxt; use file_ttl_bry instead; EX: '<img src="">' DATE:2019-03-10
? file_ttl_bry
: Xoa_ttl.Replace_spaces(Gfo_url_encoder_.Href_quotes.Decode(img_src_bry_temp)); // NOTE: must decode for fsdb.lnki_ttl as well as xowa_title; EX: A%C3%A9b -> A<EFBFBD>b
boolean write_xowa_file_title = true; boolean write_xowa_file_title = true;
if (data.Img_pgbnr().Exists()) { if (data.Img_pgbnr().Exists()) {