diff --git a/400_xowa/src/gplx/xowa/xtns/syntax_highlights/Synh_xtn_nde.java b/400_xowa/src/gplx/xowa/xtns/syntax_highlights/Synh_xtn_nde.java index 8dc8c8e5a..493e78bcd 100644 --- a/400_xowa/src/gplx/xowa/xtns/syntax_highlights/Synh_xtn_nde.java +++ b/400_xowa/src/gplx/xowa/xtns/syntax_highlights/Synh_xtn_nde.java @@ -1,6 +1,6 @@ /* XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012-2017 gnosygnu@gmail.com +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. @@ -13,43 +13,65 @@ 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.syntax_highlights; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import gplx.core.primitives.*; -import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*; -import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*; -public class Synh_xtn_nde implements Xox_xnde, Mwh_atr_itm_owner1 { - private byte[] lang = Bry_.Empty; private byte[] style = null; private byte[] enclose = Bry_.Empty; - private boolean line_enabled = false; private int start = 1; private Int_rng_mgr highlight_idxs = Int_rng_mgr_null.Instance; - public Xop_xnde_tkn Xnde() {throw Err_.new_unimplemented();} - public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) { - if (xatr_id_obj == null) return; - Byte_obj_val xatr_id = (Byte_obj_val)xatr_id_obj; - switch (xatr_id.Val()) { - case Xatr_line: line_enabled = true; break; - case Xatr_enclose: enclose = xatr.Val_as_bry(); break; - case Xatr_lang: lang = xatr.Val_as_bry(); break; - case Xatr_style: style = xatr.Val_as_bry(); break; - case Xatr_start: start = xatr.Val_as_int_or(1); break; - case Xatr_highlight: highlight_idxs = new Int_rng_mgr_base(); highlight_idxs.Parse(xatr.Val_as_bry()); break; - } - } - public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) { - Xop_xnde_tag tag = xnde.Tag(); - ctx.Para().Process_block__xnde(tag, tag.Block_open()); // deactivate pre; pre; PAGE:en.w:Comment_(computer_programming); DATE:2014-06-24 - Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde); - ctx.Para().Process_block__xnde(tag, tag.Block_close()); // deactivate pre; pre; PAGE:en.w:Comment_(computer_programming); DATE:2014-06-24 - } - public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) { - Synh_xtn_nde_.Make(bfr, app, src, xnde.Tag_open_end(), xnde.Tag_close_bgn(), lang, enclose, style, line_enabled, start, highlight_idxs); - } - private static final byte Xatr_enclose = 1, Xatr_lang = 2, Xatr_style = 3, Xatr_line = 4, Xatr_start = 5, Xatr_highlight = 6; - private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7() - .Add_str_byte("enclose" , Xatr_enclose) - .Add_str_byte("inline" , Xatr_enclose) - .Add_str_byte("lang" , Xatr_lang) - .Add_str_byte("style" , Xatr_style) - .Add_str_byte("line" , Xatr_line) - .Add_str_byte("start" , Xatr_start) - .Add_str_byte("highlight" , Xatr_highlight) - ; -} +package gplx.xowa.xtns.syntax_highlights; + +import gplx.Bry_; +import gplx.Bry_bfr; +import gplx.Err_; +import gplx.Hash_adp_bry; +import gplx.core.primitives.Byte_obj_val; +import gplx.xowa.Xoae_app; +import gplx.xowa.Xoae_page; +import gplx.xowa.Xowe_wiki; +import gplx.xowa.htmls.core.htmls.Xoh_html_wtr; +import gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx; +import gplx.xowa.parsers.Xop_ctx; +import gplx.xowa.parsers.Xop_root_tkn; +import gplx.xowa.parsers.htmls.Mwh_atr_itm; +import gplx.xowa.parsers.htmls.Mwh_atr_itm_owner1; +import gplx.xowa.parsers.xndes.Xop_xnde_tag; +import gplx.xowa.parsers.xndes.Xop_xnde_tkn; +import gplx.xowa.xtns.Xox_xnde; +import gplx.xowa.xtns.Xox_xnde_; + +public class Synh_xtn_nde implements Xox_xnde, Mwh_atr_itm_owner1 { + private byte[] lang = Bry_.Empty; + private byte[] style = null; + private byte[] enclose = Bry_.Empty; + private boolean line_enabled = false; + private int start = 1; + private Int_rng_mgr highlight_idxs = Int_rng_mgr_null.Instance; + public Xop_xnde_tkn Xnde() {throw Err_.new_unimplemented();} + public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) { + if (xatr_id_obj == null) return; + Byte_obj_val xatr_id = (Byte_obj_val)xatr_id_obj; + switch (xatr_id.Val()) { + case Xatr_line: line_enabled = true; break; + case Xatr_enclose: enclose = xatr.Val_as_bry(); break; + case Xatr_inline: enclose = Bry_.new_a7("none"); break; // 2020-08-27|ISSUE#:794|inline should be enclose=none + case Xatr_lang: lang = xatr.Val_as_bry(); break; + case Xatr_style: style = xatr.Val_as_bry(); break; + case Xatr_start: start = xatr.Val_as_int_or(1); break; + case Xatr_highlight: highlight_idxs = new Int_rng_mgr_base(); highlight_idxs.Parse(xatr.Val_as_bry()); break; + } + } + public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) { + Xop_xnde_tag tag = xnde.Tag(); + ctx.Para().Process_block__xnde(tag, tag.Block_open()); // deactivate pre; pre; PAGE:en.w:Comment_(computer_programming); DATE:2014-06-24 + Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde); + ctx.Para().Process_block__xnde(tag, tag.Block_close()); // deactivate pre; pre; PAGE:en.w:Comment_(computer_programming); DATE:2014-06-24 + } + public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) { + Synh_xtn_nde_.Make(bfr, app, src, xnde.Tag_open_end(), xnde.Tag_close_bgn(), lang, enclose, style, line_enabled, start, highlight_idxs); + } + private static final byte Xatr_enclose = 1, Xatr_lang = 2, Xatr_style = 3, Xatr_line = 4, Xatr_start = 5, Xatr_highlight = 6, Xatr_inline = 7; + private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7() + .Add_str_byte("enclose" , Xatr_enclose) + .Add_str_byte("inline" , Xatr_inline) + .Add_str_byte("lang" , Xatr_lang) + .Add_str_byte("style" , Xatr_style) + .Add_str_byte("line" , Xatr_line) + .Add_str_byte("start" , Xatr_start) + .Add_str_byte("highlight" , Xatr_highlight) + ; +} diff --git a/400_xowa/src/gplx/xowa/xtns/syntax_highlights/Synh_xtn_nde_tst.java b/400_xowa/src/gplx/xowa/xtns/syntax_highlights/Synh_xtn_nde_tst.java index c13302d86..43cecad8c 100644 --- a/400_xowa/src/gplx/xowa/xtns/syntax_highlights/Synh_xtn_nde_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/syntax_highlights/Synh_xtn_nde_tst.java @@ -1,6 +1,6 @@ /* XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012-2017 gnosygnu@gmail.com +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. @@ -13,175 +13,202 @@ 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.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(); - @Test public void Basic() { - fxt.Test_parse_page_all_str("abc", "
abc
"); - } - @Test public void Text() { - fxt.Test_parse_page_all_str("abc", "
abc
"); - } - @Test public void Style_pre() { - fxt.Test_parse_page_all_str("abc", "
abc
"); - } - @Test public void Style_code() { - fxt.Test_parse_page_all_str("abc", "
abc
"); - } - @Test public void Trim_ws() { - fxt.Test_parse_page_all_str(String_.Concat_lines_nl - ( "" - , "abc" - , "" - ), String_.Concat_lines_nl - ( "
"
-		,	"abc"
-		,	"
" - )); - } - @Test public void Line() { - fxt.Test_parse_page_all_str(String_.Concat_lines_nl - ( "" - , "a" - , "b" - , "" - ), String_.Concat_lines_nl - ( "
"
-		,	"1 a"
-		,	"2 b"
-		,	"
" - )); - } - @Test public void Start() { - fxt.Test_parse_page_all_str(String_.Concat_lines_nl - ( "" - , "a" - , "b" - , "" - ), String_.Concat_lines_nl - ( "
"
-		,	"3 a"
-		,	"4 b"
-		,	"
" - )); - } - @Test public void Highlight() { - fxt.Test_parse_page_all_str(String_.Concat_lines_nl - ( "" - , "a" - , "b" - , "c" - , "" - ), String_.Concat_lines_nl - ( "
"
-		,	"1 a"
-		,	"2 b"
-		,	"3 c"
-		,	"
" - )); - } - @Test public void Highlight_wo_line_arg() { - fxt.Test_parse_page_all_str(String_.Concat_lines_nl - ( "" - , "a" - , "b" - , "c" - , "" - ), String_.Concat_lines_nl - ( "
"
-		,	"a"
-		,	"b"
-		,	"c"
-		,	"
" - )); - } - @Test public void Enclose_none() { - fxt.Test_parse_page_all_str(String_.Concat_lines_nl - ( "" - , "a" - , "b" - , "c" - , "" - ), String_.Concat_lines_nl - ( "" - , "a" - , "b" - , "c" - , "" - )); - } - @Test public void Line_padded() { - fxt.Test_parse_page_all_str(String_.Concat_lines_nl - ( "" - , "a" - , "b" - , "" - ), String_.Concat_lines_nl - ( "
"
-		,	" 9 a"
-		,	"10 b"
-		,	"
" - )); - } - @Test public void EndTag_has_ws() { // PURPOSE: not being closed correctly; PAGE:en.w:Mergesort; updated; DATE:2014-06-24 - fxt.Init_para_y_(); - fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last - ( "a" - , "" - , "b" - , "" - , "c" - , "" - , "d" - , "" - ), String_.Concat_lines_nl_skip_last - ( "

a" - , "

" - , "
"
-		,	"b"
-		,	"
" - , "" - , "

c" - , "

" - , "
"
-		,	"d"
-		,	"
" - , "" - )); - fxt.Init_para_n_(); - } - @Test public void Trim_ws_from_end_tab() {// PURPOSE: trim ws between "abc" and "" - , "abc" - , " " // trim ws here - ), String_.Concat_lines_nl - ( "
"
-		,	"abc"
-		,	"
" - )); - } - @Test public void Pre() {// PURPOSE: handle pre; PAGE:en.w:Comment_(computer_programming); DATE:2014-06-23 - fxt.Init_para_y_(); - fxt.Test_parse_page_all_str(String_.Concat_lines_nl - ( "a" - , "" - , " " - , " b" - , " " // trim ws here - , "" - , "c" - ), String_.Concat_lines_nl - ( "

a" - , "

" - , "
"
-		,	" b"
-		,	"
" - , "" - , "

c" - , "

" - )); - fxt.Init_para_n_(); - } -} +package gplx.xowa.xtns.syntax_highlights; + +import gplx.String_; +import gplx.xowa.Xop_fxt; +import org.junit.Test; + +public class Synh_xtn_nde_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Basic() { + fxt.Test_parse_page_all_str("abc", "
abc
"); + } + @Test public void Text() { + fxt.Test_parse_page_all_str("abc", "
abc
"); + } + @Test public void Style_pre() { + fxt.Test_parse_page_all_str("abc", "
abc
"); + } + @Test public void Style_code() { + fxt.Test_parse_page_all_str("abc", "
abc
"); + } + @Test public void Trim_ws() { + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "" + , "abc" + , "" + ), String_.Concat_lines_nl + ( "
"
+		,	"abc"
+		,	"
" + )); + } + @Test public void Line() { + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "" + , "a" + , "b" + , "" + ), String_.Concat_lines_nl + ( "
"
+		,	"1 a"
+		,	"2 b"
+		,	"
" + )); + } + @Test public void Start() { + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "" + , "a" + , "b" + , "" + ), String_.Concat_lines_nl + ( "
"
+		,	"3 a"
+		,	"4 b"
+		,	"
" + )); + } + @Test public void Highlight() { + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "" + , "a" + , "b" + , "c" + , "" + ), String_.Concat_lines_nl + ( "
"
+		,	"1 a"
+		,	"2 b"
+		,	"3 c"
+		,	"
" + )); + } + @Test public void Highlight_wo_line_arg() { + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "" + , "a" + , "b" + , "c" + , "" + ), String_.Concat_lines_nl + ( "
"
+		,	"a"
+		,	"b"
+		,	"c"
+		,	"
" + )); + } + @Test public void Enclose_none() { + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "" + , "a" + , "b" + , "c" + , "" + ), String_.Concat_lines_nl + ( "" + , "a" + , "b" + , "c" + , "" + )); + } + @Test public void Line_padded() { + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "" + , "a" + , "b" + , "" + ), String_.Concat_lines_nl + ( "
"
+		,	" 9 a"
+		,	"10 b"
+		,	"
" + )); + } + @Test public void EndTag_has_ws() { // PURPOSE: not being closed correctly; PAGE:en.w:Mergesort; updated; DATE:2014-06-24 + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "b" + , "" + , "c" + , "" + , "d" + , "" + ), String_.Concat_lines_nl_skip_last + ( "

a" + , "

" + , "
"
+		,	"b"
+		,	"
" + , "" + , "

c" + , "

" + , "
"
+		,	"d"
+		,	"
" + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Trim_ws_from_end_tab() {// PURPOSE: trim ws between "abc" and "" + , "abc" + , " " // trim ws here + ), String_.Concat_lines_nl + ( "
"
+		,	"abc"
+		,	"
" + )); + } + @Test public void Pre() {// PURPOSE: handle pre; PAGE:en.w:Comment_(computer_programming); DATE:2014-06-23 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "a" + , "" + , " " + , " b" + , " " // trim ws here + , "" + , "c" + ), String_.Concat_lines_nl + ( "

a" + , "

" + , "
"
+		,	" b"
+		,	"
" + , "" + , "

c" + , "

" + )); + fxt.Init_para_n_(); + } + @Test public void Inline() { + // 2020-08-27|ISSUE#:794|inline should be enclose=none + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "a" + , "" + , " " + , " b" + , " " // trim ws here + , "" + , "c" + ), String_.Concat_lines_nl + ( "

a" + , "

" + , " " // fails with
+		,	" b"
+		,	""
+		,	""
+		,	"

c" + , "

" + )); + fxt.Init_para_n_(); + } +}