Mw_parse: Add more comment support

pull/620/head
gnosygnu 8 years ago
parent 75972fcff0
commit 3af333e563

@ -295,7 +295,7 @@ public class Xomw_prepro_wkr { // TS.UNSAFE:caching for repeated calls
// comments.
comments_list.Clear();
comments_list.Add(new int[] {ws_bgn, ws_end});
while (Bry_.Eq(src, ws_end + 1, ws_end + 5, Bry__comment_bgn)) {
while (ws_end + 5 < src_len && Bry_.Eq(src, ws_end + 1, ws_end + 5, Bry__comment_bgn)) {
int cur_char_pos = Bry_find_.Find_fwd(src, Bry__comment_end, ws_end + 4);
if (cur_char_pos == Bry_find_.Not_found) {
break;
@ -358,8 +358,8 @@ public class Xomw_prepro_wkr { // TS.UNSAFE:caching for repeated calls
i = end_pos + 1;
inner = Bry_.Mid(src, bgn_pos, end_pos + 1);
accum.Add_str_a7("<comment>").Add_bry_escape_html(inner).Add_str_a7("</comment>");
continue;
}
continue;
}
byte[] name = element.name;

@ -34,8 +34,27 @@ public class Xomw_prepro_wkr__tst {
@Test public void Comment() {
fxt.Test__parse("a<!--b-->c", "<root>a<comment>&lt;!--b--&gt;</comment>c</root>");
}
@Test public void Comment__nl__ws() {
fxt.Test__parse("xo\n <!--1--> \n <!--2--> \nz", "<root>xo\n<comment> &lt;!--1--&gt; \n</comment><comment> &lt;!--2--&gt; \n</comment>z</root>");
@Test public void Comment__dangling() {
fxt.Test__parse("a<!--b", "<root>a<comment>&lt;!--b</comment></root>");
}
@Test public void Comment__ws() { // NOTE: space is outside comment
fxt.Test__parse("a <!--b--> c", "<root>a <comment>&lt;!--b--&gt;</comment> c</root>");
}
@Test public void Comment__many__ws() { // NOTE: space is outside comment
fxt.Test__parse("a <!--1--> <!--2--> z", "<root>a <comment>&lt;!--1--&gt;</comment> <comment>&lt;!--2--&gt;</comment> z</root>");
}
@Test public void Comment__nl__ws() { // NOTE: space is inside comment if flanked by nl
fxt.Test__parse(String_.Concat_lines_nl_skip_last
( "a"
, " <!--1--> "
, " <!--2--> "
, "z"
), String_.Concat_lines_nl_skip_last
( "<root>a"
, "<comment> &lt;!--1--&gt; "
, "</comment><comment> &lt;!--2--&gt; "
, "</comment>z</root>"
));
}
@Test public void Ext__pre() {
fxt.Test__parse("a<pre id=\"1\">b</pre>c", "<root>a<ext><name>pre</name><attr> id=&quot;1&quot;</attr><inner>b</inner><close>&lt;/pre&gt;</close></ext>c</root>");

Loading…
Cancel
Save