mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Xtn.SyntaxHighlight: Highlight lines if 'highlight' is passed but 'line' is not [#498]
This commit is contained in:
parent
a01e7409eb
commit
cbae5d55bb
@ -31,7 +31,7 @@ class Synh_xtn_nde_ {
|
||||
}
|
||||
int text_bgn = src_bgn;
|
||||
int text_end = Bry_find_.Find_bwd_while(src, src_end, -1, Byte_ascii.Space) + 1; // trim space from end; PAGE:en.w:Comment_(computer_programming) DATE:2014-06-23
|
||||
if (line_enabled) {
|
||||
if (line_enabled || highlight_idxs != Int_rng_mgr_null.Instance) { // NOTE: if "highlight" specified without "line" highlight_idxs will not be null instance; add '<span style="background-color: #FFFFCC;">' below; ISSUE#:498; DATE:2019-06-22
|
||||
bfr.Add_byte_nl();
|
||||
byte[][] lines = Bry_split_.Split_lines(Bry_.Mid(src, text_bgn, text_end));
|
||||
int lines_len = lines.length;
|
||||
@ -40,7 +40,7 @@ class Synh_xtn_nde_ {
|
||||
int digits_max = Int_.DigitCount(line_end);
|
||||
for (int i = 0; i < lines_len; i++) {
|
||||
byte[] line = lines[i]; if (i == 0 && Bry_.Len_eq_0(line)) continue;
|
||||
if (line_enabled) {
|
||||
if (line_enabled) { // add '<span style="-moz-user-select:none;">1 </span>' if "line" is enabled
|
||||
bfr.Add(Xoh_consts.Span_bgn_open).Add(Xoh_consts.Style_atr).Add(Style_line).Add(Xoh_consts.__end_quote);
|
||||
int pad = digits_max - Int_.DigitCount(line_idx);
|
||||
if (pad > 0) bfr.Add_byte_repeat(Byte_ascii.Space, pad);
|
||||
@ -67,7 +67,7 @@ class Synh_xtn_nde_ {
|
||||
bfr.Add(Gfh_bldr_.Bry__div_rhs);
|
||||
}
|
||||
}
|
||||
private static final byte[]
|
||||
private static final byte[]
|
||||
Enclose_none = Bry_.new_a7("none")
|
||||
, Style_line = Bry_.new_a7("-moz-user-select:none;"), Style_highlight = Bry_.new_a7("background-color: #FFFFCC;")
|
||||
, Bry__div_bgn = Bry_.new_a7("<div class=\"mw-highlight\"")
|
||||
|
@ -16,7 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.xowa.xtns.syntax_highlights; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Synh_xtn_nde_tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_parse_page_all_str("<syntaxHighlight>abc</syntaxHighlight>", "<div class=\"mw-highlight\"><pre style=\"overflow:auto\">abc</pre></div>");
|
||||
}
|
||||
@ -81,6 +81,21 @@ public class Synh_xtn_nde_tst {
|
||||
, "</pre></div>"
|
||||
));
|
||||
}
|
||||
@Test public void Highlight_wo_line_arg() {
|
||||
fxt.Test_parse_page_all_str(String_.Concat_lines_nl
|
||||
( "<syntaxHighlight highlight='1,3'>"
|
||||
, "a"
|
||||
, "b"
|
||||
, "c"
|
||||
, "</syntaxHighlight>"
|
||||
), String_.Concat_lines_nl
|
||||
( "<div class=\"mw-highlight\"><pre style=\"overflow:auto\">"
|
||||
, "<span style=\"background-color: #FFFFCC;\">a</span>"
|
||||
, "<span>b</span>"
|
||||
, "<span style=\"background-color: #FFFFCC;\">c</span>"
|
||||
, "</pre></div>"
|
||||
));
|
||||
}
|
||||
@Test public void Enclose_none() {
|
||||
fxt.Test_parse_page_all_str(String_.Concat_lines_nl
|
||||
( "<syntaxHighlight enclose=none style='color:red'>"
|
||||
|
Loading…
Reference in New Issue
Block a user