1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-30 07:20:52 +00:00

Mw_parse: Port over more code for thumb links (part 2)

This commit is contained in:
gnosygnu 2017-02-03 12:13:33 -05:00
parent 472f12e60d
commit 911be09aef
19 changed files with 520 additions and 85 deletions

View File

@ -1106,9 +1106,9 @@ public class Bry_ {
return Bry_.Replace(Bry_.Mid(src, bgn, end), Byte_ascii.Nl, Byte_ascii.Tab); return Bry_.Replace(Bry_.Mid(src, bgn, end), Byte_ascii.Nl, Byte_ascii.Tab);
} }
public static byte[] Escape_html(byte[] src) { public static byte[] Escape_html(byte[] src) {
return Escape_html(null, src, 0, src.length); return Escape_html(null, Bool_.N, src, 0, src.length);
} }
public static byte[] Escape_html(Bry_bfr bfr, byte[] src, int src_bgn, int src_end) { // uses PHP rules for htmlspecialchars; REF.PHP:http://php.net/manual/en/function.htmlspecialchars.php public static byte[] Escape_html(Bry_bfr bfr, boolean ws, byte[] src, int src_bgn, int src_end) { // uses PHP rules for htmlspecialchars; REF.PHP:http://php.net/manual/en/function.htmlspecialchars.php
boolean dirty = false; boolean dirty = false;
int cur = src_bgn; int cur = src_bgn;
int prv = cur; int prv = cur;
@ -1133,6 +1133,9 @@ public class Bry_ {
case Byte_ascii.Apos: escaped = Gfh_entity_.Apos_num_bry; break; case Byte_ascii.Apos: escaped = Gfh_entity_.Apos_num_bry; break;
case Byte_ascii.Lt: escaped = Gfh_entity_.Lt_bry; break; case Byte_ascii.Lt: escaped = Gfh_entity_.Lt_bry; break;
case Byte_ascii.Gt: escaped = Gfh_entity_.Gt_bry; break; case Byte_ascii.Gt: escaped = Gfh_entity_.Gt_bry; break;
case Byte_ascii.Nl: if (ws) escaped = Gfh_entity_.Nl_bry; break;
case Byte_ascii.Cr: if (ws) escaped = Gfh_entity_.Cr_bry; break;
case Byte_ascii.Tab: if (ws) escaped = Gfh_entity_.Tab_bry; break;
} }
// not escaped; increment and continue // not escaped; increment and continue

View File

@ -311,7 +311,11 @@ public class Bry_bfr {
return Add_bry_escape_html(val, 0, val.length); return Add_bry_escape_html(val, 0, val.length);
} }
public Bry_bfr Add_bry_escape_html(byte[] val, int bgn, int end) { public Bry_bfr Add_bry_escape_html(byte[] val, int bgn, int end) {
Bry_.Escape_html(this, val, bgn, end); Bry_.Escape_html(this, Bool_.N, val, bgn, end);
return this;
}
public Bry_bfr Add_bry_escape_xml(byte[] val, int bgn, int end) {
Bry_.Escape_html(this, Bool_.Y, val, bgn, end);
return this; return this;
} }
public Bry_bfr Add_str_u8_w_nl(String s) {Add_str_u8(s); return Add_byte_nl();} public Bry_bfr Add_str_u8_w_nl(String s) {Add_str_u8(s); return Add_byte_nl();}

View File

@ -19,6 +19,7 @@ package gplx;
public class Keyval_hash { public class Keyval_hash {
private final Ordered_hash hash = Ordered_hash_.New(); private final Ordered_hash hash = Ordered_hash_.New();
public int Count() {return hash.Count();} public int Count() {return hash.Count();}
public int Len() {return hash.Count();}
public Keyval_hash Clear() {hash.Clear(); return this;} public Keyval_hash Clear() {hash.Clear(); return this;}
public boolean Has(String key) {return hash.Has(key);} public boolean Has(String key) {return hash.Has(key);}
public Keyval Get_at(int i) {return (Keyval)hash.Get_at(i);} public Keyval Get_at(int i) {return (Keyval)hash.Get_at(i);}

View File

@ -98,7 +98,6 @@ public class Ordered_hash_base extends Hash_adp_base implements Ordered_hash, Gf
else return Gfo_invk_.Rv_unhandled; else return Gfo_invk_.Rv_unhandled;
return this; return this;
} static final String Invk_SetKeyOnly = "SetKeyOnly", Invk_Print = "Print"; } static final String Invk_SetKeyOnly = "SetKeyOnly", Invk_Print = "Print";
public int Len() {return ordered.Count();}
@Override public int Count() {return ordered.Count();} @Override public int Count() {return ordered.Count();}
public Ordered_hash_base() {} public Ordered_hash_base() {}
} }

View File

@ -40,6 +40,7 @@ public abstract class Hash_adp_base implements Hash_adp {
// private final java.util.HashMap<Object, Object> hash = new java.util.HashMap<Object, Object>(); // private final java.util.HashMap<Object, Object> hash = new java.util.HashMap<Object, Object>();
private final java.util.Hashtable hash = new java.util.Hashtable(); private final java.util.Hashtable hash = new java.util.Hashtable();
@gplx.Virtual public int Len() {return hash.size();}
@gplx.Virtual public int Count() {return hash.size();} @gplx.Virtual public int Count() {return hash.size();}
@gplx.Virtual public void Clear() {hash.clear();} @gplx.Virtual public void Clear() {hash.clear();}
@gplx.Virtual protected void Add_base(Object key, Object val) {hash.put(key, val);} @gplx.Virtual protected void Add_base(Object key, Object val) {hash.put(key, val);}

View File

@ -26,7 +26,7 @@ public class Gfh_entity_ {
, Apos_num_bry = Bry_.new_a7("&#39;") , Apos_num_bry = Bry_.new_a7("&#39;")
, Apos_key_bry = Bry_.new_a7("&apos;") , Apos_key_bry = Bry_.new_a7("&apos;")
, Eq_bry = Bry_.new_a7("&#61;") , Eq_bry = Bry_.new_a7("&#61;")
, Nl_bry = Bry_.new_a7(Nl_str), Space_bry = Bry_.new_a7("&#32;") , Nl_bry = Bry_.new_a7(Nl_str), Cr_bry = Bry_.new_a7("&#13;"), Tab_bry = Bry_.new_a7("&#9;"), Space_bry = Bry_.new_a7("&#32;")
, Pipe_bry = Bry_.new_a7("&#124;") , Pipe_bry = Bry_.new_a7("&#124;")
, Colon_bry = Bry_.new_a7("&#58;"), Underline_bry = Bry_.new_a7("&#95;"), Asterisk_bry = Bry_.new_a7("&#42;") , Colon_bry = Bry_.new_a7("&#58;"), Underline_bry = Bry_.new_a7("&#95;"), Asterisk_bry = Bry_.new_a7("&#42;")
, Brack_bgn_bry = Bry_.new_a7("&#91;"), Brack_end_bry = Bry_.new_a7("&#93;") , Brack_bgn_bry = Bry_.new_a7("&#91;"), Brack_end_bry = Bry_.new_a7("&#93;")

View File

@ -29,6 +29,7 @@ public class Gfh_atr_ {
// <a> // <a>
, Bry__href = Bry_.new_a7("href") , Bry__href = Bry_.new_a7("href")
, Bry__rel = Bry_.new_a7("rel") , Bry__rel = Bry_.new_a7("rel")
, Bry__target = Bry_.new_a7("target")
// <img> // <img>
, Bry__alt = Bry_.new_a7("alt") , Bry__alt = Bry_.new_a7("alt")
, Bry__src = Bry_.new_a7("src") , Bry__src = Bry_.new_a7("src")

View File

@ -0,0 +1,23 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.langs.phps.utls; import gplx.*; import gplx.langs.*; import gplx.langs.phps.*;
public class Php_utl_ {
public static boolean Empty(byte[] v) {return v == null || v.length == 0;}
public static boolean Empty(boolean v) {return v == false;}
public static boolean Is_set(byte[] v) {return v != null;}
}

View File

@ -19,7 +19,8 @@ package gplx.xowa.mws; import gplx.*; import gplx.xowa.*;
import gplx.core.btries.*; import gplx.core.btries.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.*;
import gplx.xowa.mws.htmls.*; import gplx.xowa.mws.linkers.*; import gplx.xowa.mws.parsers.*; import gplx.xowa.mws.htmls.*; import gplx.xowa.mws.linkers.*; import gplx.xowa.mws.parsers.*;
import gplx.xowa.mws.filerepos.files.*; import gplx.xowa.mws.filerepos.files.*; import gplx.xowa.mws.medias.*;
import gplx.langs.phps.utls.*;
/* TODO.XO /* TODO.XO
* P8: wfMessage * P8: wfMessage
* P7: titleFormatter->getPrefixedText * P7: titleFormatter->getPrefixedText
@ -34,6 +35,8 @@ public class Xomw_linker {
private final byte[][] split_trail_rv = new byte[2][]; private final byte[][] split_trail_rv = new byte[2][];
private Btrie_slim_mgr split_trail_trie; private Btrie_slim_mgr split_trail_trie;
private final Xomw_atr_mgr tmp_attribs = new Xomw_atr_mgr(); private final Xomw_atr_mgr tmp_attribs = new Xomw_atr_mgr();
private final Xomw_img_prms params_list = new Xomw_img_prms();
private final Xomw_mto_params mto_params = new Xomw_mto_params();
private static final byte[] Atr__class = Bry_.new_a7("class"), Atr__rel = Bry_.new_a7("rel"), Atr__href = Bry_.new_a7("href"), Rel__nofollow = Bry_.new_a7("nofollow"); private static final byte[] Atr__class = Bry_.new_a7("class"), Atr__rel = Bry_.new_a7("rel"), Atr__href = Bry_.new_a7("href"), Rel__nofollow = Bry_.new_a7("nofollow");
public static final byte[] public static final byte[]
Align__frame__center = Bry_.new_a7("center") Align__frame__center = Bry_.new_a7("center")
@ -42,6 +45,8 @@ public class Xomw_linker {
, Prefix__center = Bry_.new_a7("<div class=\"center\">") , Prefix__center = Bry_.new_a7("<div class=\"center\">")
, Class__internal = Bry_.new_a7("internal") , Class__internal = Bry_.new_a7("internal")
, Class__magnify = Bry_.new_a7("magnify") , Class__magnify = Bry_.new_a7("magnify")
, Img_class__thumbborder = Bry_.new_a7("thumbborder")
, Img_class__thumbimage = Bry_.new_a7("thumbimage")
; ;
private final Xomw_link_renderer link_renderer; private final Xomw_link_renderer link_renderer;
public Xomw_linker(Xomw_link_renderer link_renderer) { public Xomw_linker(Xomw_link_renderer link_renderer) {
@ -84,7 +89,7 @@ public class Xomw_linker {
// @param int|null width_option Used by the parser to remember the user preference thumbnailsize // @param int|null width_option Used by the parser to remember the user preference thumbnailsize
// @since 1.20 // @since 1.20
// @return String HTML for an image, with links, wrappers, etc. // @return String HTML for an image, with links, wrappers, etc.
public void Make_image_link(Bry_bfr bfr, Xomw_parser parser, Xoa_ttl title, Xomw_file file, Xomw_img_prms frame_params, Xomw_mda_prms handler_params, Object time, Object query, Object widthOption) { public void Make_image_link(Bry_bfr bfr, Xomw_parser parser, Xoa_ttl title, Xomw_file file, Xomw_img_prms frame_params, Xomw_mda_prms handler_params, Object time, byte[] query, Object widthOption) {
// XO.MW.HOOK:ImageBeforeProduceHTML // XO.MW.HOOK:ImageBeforeProduceHTML
if (file != null && !file.Allow_inline_display()) { if (file != null && !file.Allow_inline_display()) {
@ -199,14 +204,14 @@ public class Xomw_linker {
} }
else { else {
// self::processResponsiveImages($file, $thumb, handler_params); // self::processResponsiveImages($file, $thumb, handler_params);
// $params = [ params_list.Clear();
// 'alt' => frame_params['alt'], params_list.alt = frame_params.alt;
// 'title' => frame_params['title'], params_list.title = frame_params.title;
// 'valign' => isset(frame_params['valign']) ? frame_params['valign'] : false, params_list.valign = frame_params.valign;
// 'img-class' => frame_params['class'] ]; params_list.img_cls = frame_params.cls;
// if (isset(frame_params['border'])) { if (frame_params.border != null) {
// $params['img-class'] .= ($params['img-class'] !== '' ? ' ' : '') . 'thumbborder'; params_list.img_cls = Xomw_img_prms.Cls_add(params_list.img_cls, Img_class__thumbborder);
// } }
// $params = self::getImageLinkMTOParams(frame_params, $query, $parser) + $params; // $params = self::getImageLinkMTOParams(frame_params, $query, $parser) + $params;
// //
// $s = $thumb->toHtml($params); // $s = $thumb->toHtml($params);
@ -222,10 +227,43 @@ public class Xomw_linker {
bfr.Add(postfix); bfr.Add(postfix);
Bry_.Replace_all_direct(bfr.Bfr(), Byte_ascii.Nl, Byte_ascii.Space, rv_bgn, bfr.Len()); Bry_.Replace_all_direct(bfr.Bfr(), Byte_ascii.Nl, Byte_ascii.Space, rv_bgn, bfr.Len());
} }
public void Make_thumb_link2(Bry_bfr bfr, Xoa_ttl title, Object file, Xomw_img_prms frame_params, Object handler_params, Object time, Object query) { // Get the link parameters for MediaTransformOutput::toHtml() from given
// frame parameters supplied by the Parser.
// @param array $frameParams The frame parameters
// @param String $query An optional query String to add to description page links
// @param Parser|null $parser
// @return array
// XO.MW:SYNC:1.29; DATE:2017-02-03
public void Get_image_link_mto_params(Xomw_mto_params mto_params, Xomw_img_prms frame_params, byte[] query, Xomw_parser parser) {
if (Php_utl_.Is_set(frame_params.link_url) && frame_params.link_url != Bry_.Empty) {
mto_params.custom_url_link = frame_params.link_url;
if (Php_utl_.Is_set(frame_params.link_target)) {
mto_params.custom_target_link = frame_params.link_target;
}
if (parser != null) {
// extLinkAttrs = parser->getExternalLinkAttribs(frame_params['link-url']);
// foreach (extLinkAttrs as name => val) {
// // Currently could include 'rel' and 'target'
// mto_params['parser-extlink-' . name] = val;
// }
}
}
else if (Php_utl_.Is_set(frame_params.link_title) && frame_params.link_title != Bry_.Empty) {
// mto_params.custom_title_link = Title::newFromLinkTarget(Normalize_speecial_page(frame_params.link_title));
}
else if (!Php_utl_.Empty(frame_params.no_link)) {
// No link
}
else {
mto_params.desc_link = true;
mto_params.desc_query = query;
}
}
public void Make_thumb_link2(Bry_bfr bfr, Xoa_ttl title, Xomw_file file, Xomw_img_prms frame_params, Xomw_mda_prms handler_params, Object time, byte[] query) {
boolean exists = false; // = $file && $file->exists(); boolean exists = false; // = $file && $file->exists();
// $page = isset(handler_params['page']) ? handler_params['page'] : false; int page = handler_params.page;
if (frame_params.align == null) { if (frame_params.align == null) {
frame_params.align = Align__frame__right; frame_params.align = Align__frame__right;
} }
@ -239,17 +277,17 @@ public class Xomw_linker {
frame_params.caption = Bry_.Empty; frame_params.caption = Bry_.Empty;
} }
// if (empty(handler_params['width'])) { if (handler_params.width == -1) {
// // Reduce width for upright images when parameter 'upright' is used // Reduce width for upright images when parameter 'upright' is used
// handler_params['width'] = isset(frame_params['upright']) ? 130 : 180; handler_params.width = frame_params.upright != -1 ? 130 : 180;
// } }
boolean thumb = false; Xomw_mto thumb = null;
boolean no_scale = false; boolean no_scale = false;
boolean manual_thumb = false; boolean manual_thumb = false;
int outer_width = 0;
int outer_width = 0;
if (!exists) { if (!exists) {
// outer_width = handler_params['width'] + 2; outer_width = handler_params.width + 2;
} }
else { else {
if (frame_params.manual_thumb != null) { if (frame_params.manual_thumb != null) {
@ -267,24 +305,25 @@ public class Xomw_linker {
} }
else if (frame_params.framed != null) { else if (frame_params.framed != null) {
// Use image dimensions, don't scale // Use image dimensions, don't scale
thumb = new Xomw_mto();
// thumb = $file->getUnscaledThumb(handler_params); // thumb = $file->getUnscaledThumb(handler_params);
no_scale = true; no_scale = true;
} }
else { else {
// Do not present an image bigger than the source, for bitmap-style images // Do not present an image bigger than the source, for bitmap-style images
// This is a hack to maintain compatibility with arbitrary pre-1.10 behavior // This is a hack to maintain compatibility with arbitrary pre-1.10 behavior
// src_width = $file->getWidth($page); int src_width = file.Get_width(page);
// if (src_width && !$file->mustRender() && handler_params['width'] > src_width) { if (src_width != -1 && !file.Must_render() && handler_params.width > src_width) {
// handler_params['width'] = src_width; handler_params.width = src_width;
// } }
// thumb = $file->transform(handler_params); // thumb = $file->transform(handler_params);
} }
if (thumb) { if (thumb != null) {
// outer_width = thumb->getWidth() + 2; // outer_width = thumb->getWidth() + 2;
} }
else { else {
// outer_width = handler_params['width'] + 2; outer_width = handler_params.width + 2;
} }
} }
@ -299,7 +338,7 @@ public class Xomw_linker {
&& frame_params.link_title != null && frame_params.link_title != null
&& frame_params.link_url != null && frame_params.link_url != null
&& frame_params.no_link != null) { && frame_params.no_link != null) {
// frame_params.link_url = url; frame_params.link_url = url;
} }
int rv_bgn = bfr.Len(); int rv_bgn = bfr.Len();
@ -308,10 +347,10 @@ public class Xomw_linker {
byte[] zoom_icon = Bry_.Empty; byte[] zoom_icon = Bry_.Empty;
if (!exists) { if (!exists) {
// $s .= self::makeBrokenImageLinkObj($title, frame_params['title'], '', '', '', $time == true); // $s .= self::makeBrokenImageLinkObj($title, frame_params.title, '', '', '', $time == true);
zoom_icon = Bry_.Empty; zoom_icon = Bry_.Empty;
} }
else if (!thumb) { else if (thumb == null) {
// $s .= wfMessage('thumbnail_error', '')->escaped(); // $s .= wfMessage('thumbnail_error', '')->escaped();
zoom_icon = Bry_.Empty; zoom_icon = Bry_.Empty;
} }
@ -319,15 +358,12 @@ public class Xomw_linker {
if (!no_scale && !manual_thumb) { if (!no_scale && !manual_thumb) {
// self::processResponsiveImages($file, thumb, handler_params); // self::processResponsiveImages($file, thumb, handler_params);
} }
// $params = [ mto_params.Clear();
// 'alt' => frame_params['alt'], mto_params.alt = frame_params.alt;
// 'title' => frame_params['title'], mto_params.title = frame_params.title;
// 'img-class' => (isset(frame_params['class']) && frame_params['class'] !== '' mto_params.img_cls = Xomw_img_prms.Cls_add(frame_params.cls, Img_class__thumbimage);
// ? frame_params['class'] . ' ' Get_image_link_mto_params(mto_params, frame_params, query, null);
// : '') . 'thumbimage' thumb.To_html(bfr, tmp, mto_params);
// ];
// $params = self::getImageLinkMTOParams(frame_params, $query) + $params;
// $s .= thumb->toHtml($params);
if (frame_params.framed != null) { if (frame_params.framed != null) {
zoom_icon = Bry_.Empty; zoom_icon = Bry_.Empty;
} }

View File

@ -224,6 +224,14 @@ public class Xomw_sanitizer {
|| (codepoint >= 0xe000 && codepoint <= 0xfffd) || (codepoint >= 0xe000 && codepoint <= 0xfffd)
|| (codepoint >= 0x10000 && codepoint <= 0x10ffff); || (codepoint >= 0x10000 && codepoint <= 0x10ffff);
} }
// Encode an attribute value for HTML output.
// XO.MW:SYNC:1.29; DATE:2017-02-03
public static void Encode_attribute(Bry_bfr bfr, byte[] text) {
// Whitespace is normalized during attribute decoding,
// so if we've been passed non-spaces we must encode them
// ahead of time or they won't be preserved.
bfr.Add_bry_escape_xml(text, 0, text.length);
}
public static Hash_adp_bry html_entities; public static Hash_adp_bry html_entities;
private static Hash_adp_bry Html_entities_new() { private static Hash_adp_bry Html_entities_new() {

View File

@ -0,0 +1,85 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.mws; import gplx.*; import gplx.xowa.*;
public class Xomw_xml {
// Format an XML element with given attributes and, optionally, text content.
// Element and attribute names are assumed to be ready for literal inclusion.
// Strings are assumed to not contain XML-illegal characters; special
// characters (<, >, &) are escaped but illegals are not touched.
// ARGS: contents defaults to ""
// XO.MW:SYNC:1.29; DATE:2017-02-03
public static void Element(Bry_bfr bfr, byte[] element, Ordered_hash attribs, byte[] contents, boolean allow_short_tag) {
bfr.Add_byte(Byte_ascii.Angle_bgn).Add(element);
if (attribs.Len() > 0) {
Expand_attributes(bfr, attribs);
}
if (contents == null) {
bfr.Add_byte(Byte_ascii.Angle_end);
}
else {
if (allow_short_tag && contents == Bry_.Empty) {
bfr.Add_str_a7(" />");
}
else {
bfr.Add_byte(Byte_ascii.Angle_end);
bfr.Add_bry_escape_html(contents);
bfr.Add_byte(Byte_ascii.Angle_bgn).Add_byte(Byte_ascii.Slash).Add(element).Add_byte(Byte_ascii.Angle_end);
}
}
}
// Given an array of ('attributename' => 'value'), it generates the code
// to set the XML attributes : attributename="value".
// The values are passed to Sanitizer::encodeAttribute.
// Return null if no attributes given.
// @param array $attribs Array of attributes for an XML element
// XO.MW:SYNC:1.29; DATE:2017-02-03
public static void Expand_attributes(Bry_bfr bfr, Ordered_hash attribs) {
int attribs_len = attribs.Len();
for (int i = 0; i < attribs_len; i += 2) {
// XO.MW: $out .= " {$name}=\"" . Sanitizer::encodeAttribute( $val ) . '"';
bfr.Add_byte_space();
bfr.Add((byte[])attribs.Get_at(i));
bfr.Add_byte_eq().Add_byte_quote();
Xomw_sanitizer.Encode_attribute(bfr, (byte[])attribs.Get_at(i + 1));
bfr.Add_byte_quote();
}
}
// This opens an XML element
// XO.MW:SYNC:1.29; DATE:2017-02-03
public static void Open_element(Bry_bfr bfr, byte[] element, Ordered_hash attribs) {
bfr.Add_byte(Byte_ascii.Angle_bgn).Add(element);
Expand_attributes(bfr, attribs);
bfr.Add_byte(Byte_ascii.Angle_end);
}
// Shortcut to close an XML element
// XO.MW:SYNC:1.29; DATE:2017-02-03
public static void Close_element(Bry_bfr bfr, byte[] element) {
bfr.Add_byte(Byte_ascii.Angle_bgn).Add_byte(Byte_ascii.Slash).Add(element).Add_byte(Byte_ascii.Angle_end);
}
// Same as Xml::element(), but does not escape contents. Handy when the
// content you have is already valid xml.
// XO.MW:SYNC:1.29; DATE:2017-02-03
public static void Tags(Bry_bfr bfr, byte[] element, Ordered_hash attribs, byte[] contents) {
Open_element(bfr, element, attribs);
bfr.Add(contents);
bfr.Add_byte(Byte_ascii.Angle_bgn).Add_byte(Byte_ascii.Slash).Add(element).Add_byte(Byte_ascii.Angle_end);
}
}

View File

@ -28,8 +28,20 @@ public class Xomw_img_prms {
public byte[] alt = null; public byte[] alt = null;
public byte[] title = null; public byte[] title = null;
public byte[] cls = null; public byte[] cls = null;
public byte[] img_cls = null;
public byte[] link_title = null; public byte[] link_title = null;
public byte[] link_url = null; public byte[] link_url = null;
public byte[] link_target = null;
public byte[] no_link = null; public byte[] no_link = null;
public byte[] border = null;
public double upright = -1; public double upright = -1;
public void Clear() {
align = valign = caption = frame = framed = frameless
= thumbnail = manual_thumb = alt = title = cls = img_cls
= link_title = link_url = link_target = no_link = null;
upright = -1;
}
public static byte[] Cls_add(byte[] lhs, byte[] rhs) {
return Bry_.Len_eq_0(lhs) ? rhs : Bry_.Add(lhs, Byte_ascii.Space_bry, rhs);
}
} }

View File

@ -15,8 +15,71 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.mws.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; package gplx.xowa.mws.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*;
public class Xomw_string_utl { import gplx.core.btries.*;
public class Xomw_string_utils {
// Explode a String, but ignore any instances of the separator inside
// the given start and end delimiters, which may optionally nest.
// The delimiters are literal strings, not regular expressions.
// @param String bgn_delim Start delimiter
// @param String end_delim End delimiter
// @param String separator Separator String for the explode.
// @param String subject Subject String to explode.
// @param boolean nested True iff the delimiters are allowed to nest.
// @return ArrayIterator
// XO.MW: hard-coding (a) nested=true; (b) bgn="-{" end="}-" sep="|"
// XO.MW:SYNC:1.29; DATE:2017-02-03
private static final byte Delimiter_explode__sep = 0, Delimiter_explode__bgn = 1, Delimiter_explode__end = 2;
private static final Btrie_slim_mgr delimiter_explode_trie = Btrie_slim_mgr.cs()
.Add_str_byte("|" , Delimiter_explode__sep)
.Add_str_byte("-{", Delimiter_explode__bgn)
.Add_str_byte("}-", Delimiter_explode__end)
;
public static byte[][] Delimiter_explode(List_adp tmp, Btrie_rv trv, byte[] src) {
int src_bgn = 0;
int src_end = src.length;
int depth = 0;
int cur = src_bgn;
int prv = cur;
while (true) {
// eos
if (cur == src_end) {
// add rest
tmp.Add(Bry_.Mid(src, prv, src_end));
break;
}
Object o = delimiter_explode_trie.Match_at(trv, src, cur, src_end);
// regular char; continue;
if (o == null) {
cur++;
continue;
}
// handle sep, bgn, end
byte tid = ((gplx.core.primitives.Byte_obj_val)o).Val();
switch (tid) {
case Delimiter_explode__sep:
if (depth == 0) {
tmp.Add(Bry_.Mid(src, prv, cur));
prv = cur + 1;
}
break;
case Delimiter_explode__bgn:
depth++;
break;
case Delimiter_explode__end:
depth--;
break;
}
cur = trv.Pos();
}
return (byte[][])tmp.To_ary_and_clear(byte[].class);
}
// More or less "markup-safe" str_replace()
// Ignores any instances of the separator inside `<...>`
public static void Replace_markup(byte[] src, int src_bgn, int src_end, byte[] find, byte[] repl) { // REF:/includes/libs/StringUtils.php|replaceMarkup public static void Replace_markup(byte[] src, int src_bgn, int src_end, byte[] find, byte[] repl) { // REF:/includes/libs/StringUtils.php|replaceMarkup
// PORTED: avoiding multiple regex calls / String creations // PORTED: avoiding multiple regex calls / String creations
// $placeholder = "\x00"; // $placeholder = "\x00";

View File

@ -15,33 +15,46 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.mws.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; package gplx.xowa.mws.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*;
import org.junit.*; import gplx.core.tests.*; import org.junit.*; import gplx.core.tests.*;
public class Xomw_string_utl__tst { public class Xomw_string_utils__tst {
private final Xomw_string_utl__fxt fxt = new Xomw_string_utl__fxt(); private final Xomw_string_utils__fxt fxt = new Xomw_string_utils__fxt();
@Test public void Basic() { @Test public void Delimiter_explode() {
// basic
fxt.Test__delimiter_explode("a|b|c" , "a", "b", "c");
// empty
fxt.Test__delimiter_explode("|a||c|" , "", "a", "", "c", "");
// nest_1
fxt.Test__delimiter_explode("a|-{b|c}-|d" , "a", "-{b|c}-", "d");
// nest_many
fxt.Test__delimiter_explode("a|-{b-{c|d}-e}-|f" , "a", "-{b-{c|d}-e}-", "f");
}
@Test public void Replace_markup() {
// basic
fxt.Test__replace_markup("a!!b" , "!!", "||", "a||b"); fxt.Test__replace_markup("a!!b" , "!!", "||", "a||b");
} // missing
@Test public void Missing() {
fxt.Test__replace_markup("abcd" , "!!", "||", "abcd"); fxt.Test__replace_markup("abcd" , "!!", "||", "abcd");
} // eos
@Test public void Eos() {
fxt.Test__replace_markup("a!!" , "!!", "||", "a||"); fxt.Test__replace_markup("a!!" , "!!", "||", "a||");
} // ignore
@Test public void Ignore() {
fxt.Test__replace_markup("a!!b<!!>!!c" , "!!", "||", "a||b<!!>||c"); fxt.Test__replace_markup("a!!b<!!>!!c" , "!!", "||", "a||b<!!>||c");
} // ignore asym_lhs
@Test public void Ignore__asym__lhs() {
fxt.Test__replace_markup("a!!b<!!<!!>!!c" , "!!", "||", "a||b<!!<!!>||c"); fxt.Test__replace_markup("a!!b<!!<!!>!!c" , "!!", "||", "a||b<!!<!!>||c");
} // ignore asym_lhs
@Test public void Ignore__asym__rhs() {
fxt.Test__replace_markup("a!!b<!!>!!>!!c" , "!!", "||", "a||b<!!>||>||c"); // NOTE: should probably be "!!>!!>", but unmatched ">" are escaped to "&gt;" fxt.Test__replace_markup("a!!b<!!>!!>!!c" , "!!", "||", "a||b<!!>||>||c"); // NOTE: should probably be "!!>!!>", but unmatched ">" are escaped to "&gt;"
} }
} }
class Xomw_string_utl__fxt { class Xomw_string_utils__fxt {
public void Test__delimiter_explode(String src_str, String... expd) {
List_adp tmp = List_adp_.New();
gplx.core.btries.Btrie_rv trv = new gplx.core.btries.Btrie_rv();
byte[][] actl = Xomw_string_utils.Delimiter_explode(tmp, trv, Bry_.new_u8(src_str));
Gftest.Eq__ary(expd, actl, "src=~{0}", src_str);
}
public void Test__replace_markup(String src_str, String find, String repl, String expd) { public void Test__replace_markup(String src_str, String find, String repl, String expd) {
byte[] src_bry = Bry_.new_u8(src_str); byte[] src_bry = Bry_.new_u8(src_str);
Xomw_string_utl.Replace_markup(src_bry, 0, src_bry.length, Bry_.new_a7(find), Bry_.new_a7(repl)); Xomw_string_utils.Replace_markup(src_bry, 0, src_bry.length, Bry_.new_a7(find), Bry_.new_a7(repl));
Gftest.Eq__str(expd, src_bry); Gftest.Eq__str(expd, src_bry);
} }
} }

View File

@ -0,0 +1,142 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.mws.medias; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*;
import gplx.langs.htmls.*;
import gplx.langs.phps.utls.*;
public class Xomw_mto {
private int width = -1, height = -1;
private byte[] url = null;
private final Ordered_hash attribs = Ordered_hash_.New_bry(), link_attribs = Ordered_hash_.New_bry();
// Return HTML <img ... /> tag for the thumbnail, will include
// width and height attributes and a blank alt text (as required).
//
// @param array options Associative array of options. Boolean options
// should be indicated with a value of true for true, and false or
// absent for false.
//
// alt HTML alt attribute
// title HTML title attribute
// desc-link Boolean, show a description link
// file-link Boolean, show a file download link
// valign vertical-align property, if the output is an inline element
// img-class Class applied to the \<img\> tag, if there is such a tag
// desc-query String, description link query params
// override-width Override width attribute. Should generally not set
// override-height Override height attribute. Should generally not set
// no-dimensions Boolean, skip width and height attributes (useful if
// set in CSS)
// custom-url-link Custom URL to link to
// custom-title-link Custom Title Object to link to
// custom target-link Value of the target attribute, for custom-target-link
// parser-extlink-* Attributes added by parser for external links:
// parser-extlink-rel: add rel="nofollow"
// parser-extlink-target: link target, but overridden by custom-target-link
//
// For images, desc-link and file-link are implemented as a click-through. For
// sounds and videos, they may be displayed in other ways.
// XO.MW:SYNC:1.29; DATE:2017-02-03
public void To_html(Bry_bfr bfr, Bry_bfr tmp, Xomw_mto_params options) {
byte[] alt = options.alt;
// byte[] query = options.desc_query;
attribs.Clear();
attribs.Add(Gfh_atr_.Bry__alt, alt);
attribs.Add(Gfh_atr_.Bry__src, url);
boolean link_attribs_is_null = false;
if (!Php_utl_.Empty(options.custom_url_link)) {
link_attribs.Clear();
link_attribs.Add(Gfh_atr_.Bry__href, options.custom_url_link);
if (!Php_utl_.Empty(options.title)) {
link_attribs.Add(Gfh_atr_.Bry__title, options.title);
}
if (Php_utl_.Empty(options.custom_target_link)) {
link_attribs.Add(Gfh_atr_.Bry__target, options.custom_target_link);
}
else if (Php_utl_.Empty(options.parser_extlink_target)) {
link_attribs.Add(Gfh_atr_.Bry__target, options.parser_extlink_target);
}
if (Php_utl_.Empty(options.parser_extlink_rel)) {
link_attribs.Add(Gfh_atr_.Bry__rel, options.parser_extlink_rel);
}
}
else if (!Php_utl_.Empty(options.custom_title_link)) {
// byte[] title = options.custom_title_link;
link_attribs.Clear();
// link_attribs.Add(Gfh_atr_.Bry__href, title.Get_link_url());
// byte[] options_title = options.title;
// link_attribs.Add(Gfh_atr_.Bry__title, Php_utl_.Empty(options_title) ? title.Get_full_text : options_title;
}
else if (!Php_utl_.Empty(options.desc_link)) {
// link_attribs = $this->getDescLinkAttribs(
// empty(options['title']) ? null : options['title'],
// $query
// );
}
else if (!Php_utl_.Empty(options.file_link)) {
link_attribs.Clear();
// link_attribs.Add(Gfh_atr_.Bry__href, file.Get_url());
}
else {
link_attribs_is_null = true;
if (!Php_utl_.Empty(options.title)) {
attribs.Add(Gfh_atr_.Bry__title, options.title);
}
}
if (!Php_utl_.Empty(options.no_dimensions)) {
attribs.Add(Gfh_atr_.Bry__width, Int_.To_bry(width));
attribs.Add(Gfh_atr_.Bry__height, Int_.To_bry(height));
}
if (!Php_utl_.Empty(options.valign)) {
attribs.Add(Gfh_atr_.Bry__style, Bry_.Add(Bry__vertical_align, options.valign));
}
if (!Php_utl_.Empty(options.img_cls)) {
attribs.Add(Gfh_atr_.Bry__class, options.img_cls);
}
if (Php_utl_.Is_set(options.override_height)) {
attribs.Add(Gfh_atr_.Bry__class, options.override_height);
}
if (Php_utl_.Is_set(options.override_width)) {
attribs.Add(Gfh_atr_.Bry__width, options.override_height);
}
// Additional densities for responsive images, if specified.
// If any of these urls is the same as src url, it'll be excluded.
// $responsiveUrls = array_diff($this->responsiveUrls, [ $this->url ]);
// if (!Php_utl_.Empty($responsiveUrls)) {
// $attribs['srcset'] = Html::srcSet($responsiveUrls);
// }
// XO.MW.HOOK:ThumbnailBeforeProduceHTML
Xomw_xml.Element(tmp, Gfh_tag_.Bry__img, attribs, Bry_.Empty, Bool_.Y);
Link_wrap(bfr, link_attribs_is_null ? null : link_attribs, tmp.To_bry_and_clear());
}
// Wrap some XHTML text in an anchor tag with the given attributes
// XO.MW:SYNC:1.29; DATE:2017-02-03
private void Link_wrap(Bry_bfr bfr, Ordered_hash link_attribs, byte[] contents) {
if (link_attribs != null) {
Xomw_xml.Tags(bfr, Gfh_tag_.Bry__a, link_attribs, contents);
}
else {
bfr.Add(contents);
}
}
private static final byte[] Bry__vertical_align = Bry_.new_a7("vertical-align: ");
}

View File

@ -0,0 +1,43 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.mws.medias; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*;
public class Xomw_mto_params {
public boolean desc_link;
public byte[] alt = null;
public byte[] title = null;
public byte[] img_cls = null;
public byte[] file_link = null;
public byte[] valign = null;
public byte[] desc_query = null;
public byte[] override_width = null;
public byte[] override_height = null;
public byte[] no_dimensions = null;
public byte[] custom_url_link = null;
public byte[] custom_title_link = null;
public byte[] custom_target_link = null;
public byte[] parser_extlink_rel = null;
public byte[] parser_extlink_target = null;
public void Clear() {
desc_link = false;
alt = title = file_link = valign
= desc_query = override_width = override_height = no_dimensions
= custom_url_link = custom_title_link
= parser_extlink_rel = parser_extlink_target
= null;
}
}

View File

@ -21,7 +21,7 @@ import gplx.langs.phps.utls.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.xwikis.*;
import gplx.xowa.mws.parsers.*; import gplx.xowa.mws.parsers.quotes.*; import gplx.xowa.mws.parsers.*; import gplx.xowa.mws.parsers.quotes.*;
import gplx.xowa.mws.htmls.*; import gplx.xowa.mws.linkers.*; import gplx.xowa.mws.htmls.*; import gplx.xowa.mws.linkers.*;
import gplx.xowa.mws.utls.*; import gplx.xowa.mws.utls.*; import gplx.xowa.mws.libs.*;
import gplx.xowa.mws.filerepos.files.*; import gplx.xowa.mws.filerepos.files.*;
import gplx.xowa.parsers.uniqs.*; import gplx.xowa.parsers.uniqs.*;
/* TODO.XO /* TODO.XO
@ -50,6 +50,8 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
private final Xomw_parser parser; private final Xomw_parser parser;
private final Xomw_atr_mgr extra_atrs = new Xomw_atr_mgr(); private final Xomw_atr_mgr extra_atrs = new Xomw_atr_mgr();
private final Xomw_qry_mgr query = new Xomw_qry_mgr(); private final Xomw_qry_mgr query = new Xomw_qry_mgr();
private final Btrie_rv trv = new Btrie_rv();
private final List_adp tmp_list = List_adp_.New();
public Xomw_lnki_wkr(Xomw_parser parser, Xomw_link_holders holders, Xomw_link_renderer link_renderer, Btrie_slim_mgr protocols_trie) { public Xomw_lnki_wkr(Xomw_parser parser, Xomw_link_holders holders, Xomw_link_renderer link_renderer, Btrie_slim_mgr protocols_trie) {
this.parser = parser; this.parser = parser;
this.holders = holders; this.holders = holders;
@ -189,7 +191,9 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
ttl_end = -1; ttl_end = -1;
if (ttl_end == -1) { // either (a) no valid title-chars ("[[<") or (b) title char, but has stray "]" ("[[a]b]]") if (ttl_end == -1) { // either (a) no valid title-chars ("[[<") or (b) title char, but has stray "]" ("[[a]b]]")
// Invalid form; output directly // Invalid form; output directly
bfr.Add_mid(src, cur, src_end); bfr.Add_mid(src, prv, lnki_bgn + 2);
bfr.Add_mid(src, cur, ttl_bgn);
prv = cur = ttl_bgn;
continue; continue;
} }
// PORTED.END: if (preg_match($e1, $line, $m)) && else if (preg_match($e1_img, $line, $m)) // PORTED.END: if (preg_match($e1, $line, $m)) && else if (preg_match($e1_img, $line, $m))
@ -265,8 +269,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
nt = wiki.Ttl_parse(unstrip); nt = wiki.Ttl_parse(unstrip);
if (nt == null) { if (nt == null) {
bfr.Add_mid(src, prv, lnki_bgn + 2); // $s .= $prefix . '[[' . $line; bfr.Add_mid(src, prv, lnki_bgn + 2); // $s .= $prefix . '[[' . $line;
cur = lnki_bgn + 2; prv = cur = lnki_bgn + 2;
prv = cur;
continue; continue;
} }
@ -431,7 +434,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
} }
} }
} }
public void Make_image(Bry_bfr bfr, Xoa_ttl title, byte[] options, boolean holders) { public void Make_image(Bry_bfr bfr, Xoa_ttl title, byte[] link_args, boolean holders) {
// Check if the options text is of the form "options|alt text" // Check if the options text is of the form "options|alt text"
// Options are: // Options are:
// * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang // * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
@ -459,9 +462,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
// * text-bottom // * text-bottom
// Protect LanguageConverter markup when splitting into parts // Protect LanguageConverter markup when splitting into parts
// $parts = StringUtils::delimiterExplode( byte[][] parts = Xomw_string_utils.Delimiter_explode(tmp_list, trv, link_args);
// '-{', '}-', '|', $options, true /* allow nesting */
// );
// Give extensions a chance to select the file revision for us // Give extensions a chance to select the file revision for us
// $options = []; // $options = [];
@ -484,16 +485,19 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
// Process the input parameters // Process the input parameters
byte[] caption = Bry_.Empty; byte[] caption = Bry_.Empty;
// XO.MW: $params = [ 'frame' => [], 'handler' => [], 'horizAlign' => [], 'vertAlign' => [] ]; // XO.MW: $params = [ 'frame' => [], 'handler' => [], 'horizAlign' => [], 'vertAlign' => [] ];
Xomw_prm_mgr param_map = new Xomw_prm_mgr();
Xomw_prm_mgr param_mgr = new Xomw_prm_mgr();
Xomw_img_prms frame = new Xomw_img_prms(); Xomw_img_prms frame = new Xomw_img_prms();
Xomw_mda_prms handler = new Xomw_mda_prms(); Xomw_mda_prms handler = new Xomw_mda_prms();
boolean seen_format = false; boolean seen_format = false;
// foreach ($parts as $part) {
Xomw_prm_mgr param_map = new Xomw_prm_mgr();
Xomw_prm_mgr param_mgr = new Xomw_prm_mgr();
byte[] part = null; int parts_len = parts.length;
for (int i = 0; i < parts_len; i++) {
byte[] part = parts[i];
part = Bry_.Trim(part); part = Bry_.Trim(part);
byte[] magic_name = null; // $mwArray->matchVariableStartToEnd($part); // byte[] magic_name = $mwArray->matchVariableStartToEnd($part);
byte[] magic_name = null;
boolean validated = false; boolean validated = false;
Xomw_prm_itm prm_itm = param_map.Get_or_null(magic_name); Xomw_prm_itm prm_itm = param_map.Get_or_null(magic_name);
@ -582,7 +586,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
if (!validated) { if (!validated) {
caption = part; caption = part;
} }
// } }
// Process alignment parameters // Process alignment parameters
Xomw_prm_itm tmp = param_mgr.Get_or_null(Xomw_prm_mgr.Name__horiz_align); Xomw_prm_itm tmp = param_mgr.Get_or_null(Xomw_prm_mgr.Name__horiz_align);

View File

@ -20,16 +20,13 @@ import org.junit.*;
public class Xomw_lnki_wkr__tst { public class Xomw_lnki_wkr__tst {
private final Xomw_lnki_wkr__fxt fxt = new Xomw_lnki_wkr__fxt(); private final Xomw_lnki_wkr__fxt fxt = new Xomw_lnki_wkr__fxt();
@Before public void init() {fxt.Clear();} @Before public void init() {fxt.Clear();}
// @Test public void Basic() {fxt.Test__parse("[[A]]" , "<!--LINK 0-->");}
@Test public void Text() {fxt.Test__parse("a [[A]] z" , "a <!--LINK 0--> z");} @Test public void Text() {fxt.Test__parse("a [[A]] z" , "a <!--LINK 0--> z");}
@Test public void Capt() {fxt.Test__parse("a [[A|a]] z" , "a <!--LINK 0--> z");} @Test public void Capt() {fxt.Test__parse("a [[A|a]] z" , "a <!--LINK 0--> z");}
// @Test public void Text() {fxt.Test__parse("a [[A]] z" , "a <a href='/wiki/A' title='A'>A</a> z");} @Test public void Invalid__char() {fxt.Test__parse("a [[<A>]] z" , "a [[<A>]] z");}
// @Test public void Capt() {fxt.Test__parse("a [[A|a]] z" , "a <a href='/wiki/A' title='A'>a</a> z");}
// @Test public void Text() {fxt.Test__parse("a [[A]] z" , "a <!--LINK 0--> z");}
// @Test public void Invalid__char() {fxt.Test__parse("[[<A>]]" , "[[<A>]]");}
@Test public void Html__self() {fxt.Test__to_html("[[Page_1]]" , "<strong class='selflink'>Page_1</strong>");} @Test public void Html__self() {fxt.Test__to_html("[[Page_1]]" , "<strong class='selflink'>Page_1</strong>");}
@Test public void Html__text() {fxt.Test__to_html("[[A]]" , "<a href='/wiki/A' title='A'>A</a>");} @Test public void Html__text() {fxt.Test__to_html("[[A]]" , "<a href='/wiki/A' title='A'>A</a>");}
@Test public void Html__capt() {fxt.Test__to_html("[[A|a]]" , "<a href='/wiki/A' title='A'>a</a>");} @Test public void Html__capt() {fxt.Test__to_html("[[A|a]]" , "<a href='/wiki/A' title='A'>a</a>");}
// @Test public void Html__file() {fxt.Test__to_html("[[File:A.png|thumb|abc]]" , "<strong class='selflink'>Page_1</strong>");}
} }
class Xomw_lnki_wkr__fxt { class Xomw_lnki_wkr__fxt {
private final Xomw_lnki_wkr wkr; private final Xomw_lnki_wkr wkr;

View File

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.mws.parsers.tables; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*; package gplx.xowa.mws.parsers.tables; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*;
import gplx.langs.phps.utls.*; import gplx.langs.phps.utls.*;
import gplx.xowa.parsers.htmls.*; import gplx.xowa.parsers.htmls.*;
import gplx.xowa.mws.utls.*; import gplx.xowa.parsers.uniqs.*; import gplx.xowa.mws.libs.*; import gplx.xowa.parsers.uniqs.*;
public class Xomw_table_wkr implements gplx.core.brys.Bry_split_wkr {// THREAD.UNSAFE: caching for repeated calls public class Xomw_table_wkr implements gplx.core.brys.Bry_split_wkr {// THREAD.UNSAFE: caching for repeated calls
private final Bry_bfr tmp; private final Bry_bfr tmp;
private Bry_bfr bfr; private Bry_bfr bfr;
@ -190,7 +190,7 @@ public class Xomw_table_wkr implements gplx.core.brys.Bry_split_wkr {// THREAD.U
// Implies both are valid for table headings. // Implies both are valid for table headings.
if (first_char == Byte_ascii.Bang) { if (first_char == Byte_ascii.Bang) {
Xomw_string_utl.Replace_markup(line, 0, line.length, Wtxt__th2, Wtxt__td2); // $line = StringUtils::replaceMarkup('!!', '||', $line); Xomw_string_utils.Replace_markup(line, 0, line.length, Wtxt__th2, Wtxt__td2); // $line = StringUtils::replaceMarkup('!!', '||', $line);
} }
// Split up multiple cells on the same line. // Split up multiple cells on the same line.