mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Css: Do not preprend selector for body [#815]
This commit is contained in:
parent
067e62dd03
commit
541f5f6524
@ -1,8 +1,22 @@
|
|||||||
|
/*
|
||||||
|
XOWA: the XOWA Offline Wiki Application
|
||||||
|
Copyright (C) 2012-2020 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.xtns.template_styles;
|
package gplx.xowa.xtns.template_styles;
|
||||||
|
|
||||||
import gplx.Bry_;
|
import gplx.Bry_;
|
||||||
import gplx.String_;
|
import gplx.String_;
|
||||||
import gplx.langs.javascripts.JsString_;
|
|
||||||
import gplx.langs.javascripts.util.regex.JsPattern_;
|
import gplx.langs.javascripts.util.regex.JsPattern_;
|
||||||
import gplx.xowa.htmls.minifys.XoCssMin;
|
import gplx.xowa.htmls.minifys.XoCssMin;
|
||||||
|
|
||||||
@ -65,19 +79,19 @@ public class XoCssTransformer {
|
|||||||
if (i > 0)
|
if (i > 0)
|
||||||
sb.append(",");
|
sb.append(",");
|
||||||
|
|
||||||
// prepend the selector
|
String item = items[i].trim();
|
||||||
sb.append(selector);
|
if (item.length() > 0) { // ignore empty items
|
||||||
|
// prepend the selector, except if it starts with 'body'
|
||||||
|
if (!String_.MidByLenSafe(item, 0, 4).equals("body")) {
|
||||||
|
sb.append(selector);
|
||||||
|
sb.append(' ');
|
||||||
|
}
|
||||||
|
|
||||||
// for pretty-printing, only add `\s` if item doesn't start with space
|
// put back the item
|
||||||
String item = items[i];
|
sb.append(item);
|
||||||
if (item.length() > 0 && !Character.isWhitespace(item.charAt(0))) {
|
|
||||||
sb.append(' ');
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// put back the item
|
}
|
||||||
sb.append(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
// EX: `@media`
|
// EX: `@media`
|
||||||
sb.append(match);
|
sb.append(match);
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
/*
|
||||||
|
XOWA: the XOWA Offline Wiki Application
|
||||||
|
Copyright (C) 2012-2020 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.xtns.template_styles;
|
package gplx.xowa.xtns.template_styles;
|
||||||
|
|
||||||
import gplx.core.tests.Gftest;
|
import gplx.core.tests.Gftest;
|
||||||
@ -13,32 +28,37 @@ public class XoCssTransformerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void PrependBasic() {
|
public void PrependBasic() {
|
||||||
tstr.Test_Prepend("x {}", "a", "a x {}");
|
tstr.Test_Prepend(".x {}", ".a", ".a .x{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void PrependManyClasses() {
|
public void PrependManyClasses() {
|
||||||
tstr.Test_Prepend("x,y,z {}", "a", "a x,a y,a z {}");
|
tstr.Test_Prepend("x,y,z {}", ".a", ".a x,.a y,.a z{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void PrependManyNodes() {
|
public void PrependManyNodes() {
|
||||||
tstr.Test_Prepend("x {} y {} z {}", "a", "a x {}a y {}a z {}");
|
tstr.Test_Prepend("x {} y {} z {}", ".a", ".a x{}.a y{}.a z{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void PrependEmpty() {
|
public void PrependEmpty() {
|
||||||
tstr.Test_Prepend("x {}{}", "a", "a x {}{}");
|
tstr.Test_Prepend("x {}{}", ".a", ".a x{}{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void PrependMediaAtBos() {
|
public void PrependMediaAtBos() {
|
||||||
tstr.Test_Prepend("@media {} x {}", "a", "@media {}a x {}");
|
tstr.Test_Prepend("@media {} x {}", ".a", "@media {}.a x{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void PrependMediaAtMid() {
|
public void PrependMediaAtMid() {
|
||||||
tstr.Test_Prepend("x {} @media {} y {}", "a", "a x {} @media {}a y {}");
|
tstr.Test_Prepend("x {} @media {} y {}", ".a", ".a x{} @media {}.a y{}");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void PrependIgnoreBody() {
|
||||||
|
tstr.Test_Prepend("body {}", ".a", "body{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user