1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

TemplateStyles: Add templatestyles to html.head [#314]

This commit is contained in:
gnosygnu
2018-12-30 23:25:29 -05:00
parent e65d9268d6
commit cc502c872f
15 changed files with 211 additions and 57 deletions

View File

@@ -48,19 +48,11 @@ public class Xoh_page_wtr_wkr {
}
Bry_bfr page_bfr = wiki.Utl__bfr_mkr().Get_m001(); // NOTE: get separate page rv to output page; do not reuse tmp_bfr b/c it will be used inside Fmt_do
Xoh_wtr_ctx hctx = null;
if (page_mode == Xopg_page_.Tid_html && wiki.Html__hdump_mgr().Load_mgr().Html_mode().Tid_is_custom()) {
byte[] html_bry = null;
// get html from html dump
if (wiki.Html__hdump_mgr().Load_mgr().Html_mode().Tid() == Xow_hdump_mode.Hdump_save.Tid()) {
hctx = Xoh_wtr_ctx.Hdump;
Write_body(page_bfr, ctx, hctx, page);
html_bry = page_bfr.To_bry_and_clear();
}
// get from swt browser
else {
html_bry = page_html_source.Get_page_html();
}
if (page_mode == Xopg_page_.Tid_html
&& wiki.Html__hdump_mgr().Load_mgr().Html_mode().Tid() == Xow_hdump_mode.Hdump_save.Tid()) {
hctx = Xoh_wtr_ctx.Hdump;
Write_body(page_bfr, ctx, hctx, page);
byte[] html_bry = page_bfr.To_bry_and_clear();
Write_page_by_tid(ctx, hctx, page_mode, rv, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(html_bry));
}
else {

View File

@@ -59,7 +59,7 @@ public class Xow_tidy_mgr implements Gfo_invk, Xow_tidy_mgr_interface {
find = Bry_find_.Find_bwd(bfr_bry, Gfh_tag_.Body_rhs, bfr.Len()); if (find == Bry_find_.Not_found) return false;
bfr.Delete_rng_to_end(find);
return true;
}
}
private static final byte[] // MW:includes/parser/Tidy.php|getWrapped
Wrap_bgn = Bry_.new_a7
( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"

View File

@@ -15,10 +15,10 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.core.htmls.tidy; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*;
import org.junit.*;
public class Xoh_tidy_mgr_tst {
@Before public void init() {fxt.Clear();} private Xoh_tidy_mgr_fxt fxt = new Xoh_tidy_mgr_fxt();
public class Xow_tidy_mgr_tst {
@Before public void init() {fxt.Clear();} private final Xoh_tidy_mgr_fxt fxt = new Xoh_tidy_mgr_fxt();
@Test public void Wrap() {
fxt.Test_wrap("<b>a</b>"
fxt.Test__wrap("<b>a</b>"
, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
+ "<html>"
+ "<head>"
@@ -30,7 +30,7 @@ public class Xoh_tidy_mgr_tst {
);
}
@Test public void Unwrap_pass() {
fxt.Test_unwrap
fxt.Test__unwrap
( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
+ "<html>"
+ "<head>"
@@ -43,7 +43,7 @@ public class Xoh_tidy_mgr_tst {
);
}
@Test public void Unwrap_fail_bgn() {
fxt.Test_unwrap
fxt.Test__unwrap
( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
+ "<html>"
+ "<head>"
@@ -56,7 +56,7 @@ public class Xoh_tidy_mgr_tst {
);
}
@Test public void Unwrap_fail_end() {
fxt.Test_unwrap
fxt.Test__unwrap
( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
+ "<html>"
+ "<head>"
@@ -70,16 +70,16 @@ public class Xoh_tidy_mgr_tst {
}
}
class Xoh_tidy_mgr_fxt {
private Bry_bfr bfr = Bry_bfr_.Reset(255);
private final Bry_bfr bfr = Bry_bfr_.Reset(255);
public void Clear() {
bfr.Clear();
}
public void Test_wrap(String val, String expd) {
public void Test__wrap(String val, String expd) {
bfr.Add_str_u8(val);
Xow_tidy_mgr.Tidy_wrap(bfr);
Tfds.Eq(expd, bfr.To_str_and_clear());
}
public void Test_unwrap(String val, boolean expd_pass, String expd) {
public void Test__unwrap(String val, boolean expd_pass, String expd) {
bfr.Add_str_u8(val);
boolean actl_pass = Xow_tidy_mgr.Tidy_unwrap(bfr);
if (actl_pass != expd_pass) Tfds.Fail("expd={0} actl={1}", expd_pass, actl_pass);

View File

@@ -38,5 +38,6 @@ public class Xoh_head_itm_ {
, Key__tabber = Bry_.new_a7("tabber")
, Key__xo_elem = Bry_.new_a7("xo.elem")
, Key__page_cfg = Bry_.new_a7("page_cfg")
, Key__css_dynamic = Bry_.new_a7("css_dynamic")
;
}

View File

@@ -0,0 +1,28 @@
/*
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.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import gplx.xowa.guis.*;
import gplx.xowa.apps.apis.xowa.html.modules.*;
public class Xoh_head_itm__css_dynamic extends Xoh_head_itm__base {
private final Bry_bfr bfr = Bry_bfr_.New();
@Override public byte[] Key() {return Xoh_head_itm_.Key__css_dynamic;}
@Override public int Flags() {return Flag__css_text;}
public byte[] Get_and_clear() {return bfr.To_bry_and_clear();} // TEST:
public void Add(byte[] v) {bfr.Add(v);}
@Override public void Write_css_text(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
wtr.Write(bfr.To_bry_and_clear());
}
}

View File

@@ -32,7 +32,7 @@ public class Xoh_head_mgr implements gplx.core.brys.Bfr_arg {
public Xoh_head_mgr() {
Itms_add(itm__css, itm__globals, itm__xo_elem, itm__server, itm__popups, itm__toc, itm__collapsible, itm__navframe, itm__gallery, itm__gallery_styles
, itm__mathjax, itm__graph, itm__hiero, itm__top_icon, itm__title_rewrite, itm__search_suggest, itm__timeline
, itm__dbui, itm__pgbnr, itm__tabber, itm__page_cfg
, itm__dbui, itm__pgbnr, itm__tabber, itm__page_cfg, itm__css_dynamic
);
}
public Xoh_head_itm__css Itm__css() {return itm__css;} private final Xoh_head_itm__css itm__css = new Xoh_head_itm__css();
@@ -56,6 +56,7 @@ public class Xoh_head_mgr implements gplx.core.brys.Bfr_arg {
public Xoh_head_itm__pgbnr Itm__pgbnr() {return itm__pgbnr;} private final Xoh_head_itm__pgbnr itm__pgbnr = new Xoh_head_itm__pgbnr();
public Xoh_head_itm__tabber Itm__tabber() {return itm__tabber;} private final Xoh_head_itm__tabber itm__tabber = new Xoh_head_itm__tabber();
public Xoh_head_itm__page_cfg Itm__page_cfg() {return itm__page_cfg;} private final Xoh_head_itm__page_cfg itm__page_cfg = new Xoh_head_itm__page_cfg();
public Xoh_head_itm__css_dynamic Itm__css_dynamic() {return itm__css_dynamic;} private final Xoh_head_itm__css_dynamic itm__css_dynamic = new Xoh_head_itm__css_dynamic();
public Xoh_head_mgr Init(Xoae_app app, Xowe_wiki wiki, Xoae_page page) {
this.app = app; this.wiki = wiki; this.page = page;
return this;