mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Xomw: Start converting XomwParser
This commit is contained in:
parent
dec8dbc713
commit
c1559077cf
@ -263,7 +263,7 @@ public class XomwLinkHolderArray {
|
||||
*
|
||||
* @param String $text
|
||||
*/
|
||||
public void Replace(Xomw_parser_ctx pctx, Xomw_parser_bfr pbfr) {
|
||||
public void replace(Xomw_parser_bfr pbfr) {
|
||||
this.replaceInternal(pbfr);
|
||||
// $this->replaceInterwiki( $text );
|
||||
}
|
||||
|
@ -18,25 +18,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.mediawiki.includes.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.xowa.mediawiki.includes.linkers.*;
|
||||
public class Xomw_link_holders__tst {
|
||||
private final Xomw_link_holders__fxt fxt = new Xomw_link_holders__fxt();
|
||||
public class XomwLinkHolderArrayTest {
|
||||
private final XomwLinkHolderArrayFxt fxt = new XomwLinkHolderArrayFxt();
|
||||
@Test public void Replace__basic() {
|
||||
fxt.Init__add("A", "a");
|
||||
fxt.Test__replace("a <!--LINK 0--> b", "a <a href='/wiki/A' title='A'>a</a> b");
|
||||
}
|
||||
}
|
||||
class Xomw_link_holders__fxt {
|
||||
class XomwLinkHolderArrayFxt {
|
||||
private final XomwLinkHolderArray holders = new XomwLinkHolderArray(new Xomw_parser());
|
||||
private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr();
|
||||
private boolean apos = true;
|
||||
public Xomw_link_holders__fxt() {
|
||||
public XomwLinkHolderArrayFxt() {
|
||||
}
|
||||
public void Init__add(String ttl, String capt) {
|
||||
holders.Test__add(XomwTitle.newFromText(Bry_.new_u8(ttl)), Bry_.new_u8(capt));
|
||||
}
|
||||
public void Test__replace(String src, String expd) {
|
||||
if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd);
|
||||
holders.Replace(new Xomw_parser_ctx(), pbfr.Init(Bry_.new_u8(src)));
|
||||
holders.replace(pbfr.Init(Bry_.new_u8(src)));
|
||||
Gftest.Eq__str(expd, pbfr.Rslt().To_str_and_clear());
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,148 +0,0 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
//namespace gplx.xowa.mediawiki.includes.parsers {
|
||||
// using gplx.langs.htmls;
|
||||
// using gplx.xowa.mediawiki.includes;
|
||||
// using gplx.xowa.mediawiki.includes.htmls;
|
||||
// using gplx.xowa.mediawiki.includes.linkers;
|
||||
// public class Xomw_link_holders {
|
||||
// private final Xomw_link_renderer link_renderer;
|
||||
// private final Bry_bfr tmp;
|
||||
// private int link_id = 0; // MOVED:Parser.php
|
||||
// private final XomwLinkHolderList internals = new XomwLinkHolderList();
|
||||
// private final Xomw_atr_mgr extra_atrs = new Xomw_atr_mgr();
|
||||
// private final Xomw_qry_mgr query = new Xomw_qry_mgr();
|
||||
// public Xomw_link_holders(Xomw_link_renderer link_renderer, Bry_bfr tmp) {
|
||||
// this.link_renderer = link_renderer;
|
||||
// this.tmp = tmp;
|
||||
// }
|
||||
// public void Clear() {
|
||||
// internals.Clear();
|
||||
//
|
||||
// link_id = 0;
|
||||
// }
|
||||
// public void Make_holder(Bry_bfr bfr, XomwTitle nt, byte[] text, byte[][] query, byte[] trail, byte[] prefix) {
|
||||
// if (nt == null) {
|
||||
// // Fail gracefully
|
||||
// bfr.Add_str_a7("<!-- ERROR -->").Add(prefix).Add(text).Add(trail);
|
||||
// }
|
||||
// else {
|
||||
// // Separate the link trail from the rest of the link
|
||||
//// list( $inside, $trail ) = Linker::splitTrail( $trail );
|
||||
// byte[] inside = Bry_.Empty;
|
||||
//
|
||||
// XomwLinkHolderItem entry = new XomwLinkHolderItem(nt, tmp.Add_bry_many(prefix, text, inside).To_bry_and_clear(), query);
|
||||
//
|
||||
// boolean is_external = false; // $nt->isExternal()
|
||||
// if (is_external) {
|
||||
// // Use a globally unique ID to keep the objects mergable
|
||||
//// $key = $this->parent->nextLinkID();
|
||||
//// $this->interwikis[$key] = $entry;
|
||||
//// $retVal = "<!--IWLINK $key-->{$trail}";
|
||||
// }
|
||||
// else {
|
||||
// int key = link_id++;
|
||||
// internals.Add(key, entry);
|
||||
// bfr.Add(Bry__link__bgn).Add_int_variable(key).Add(Gfh_tag_.Comm_end).Add(trail); // "<!--LINK $ns:$key-->{$trail}";
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// public void Test__add(XomwTitle ttl, byte[] capt) {
|
||||
// int key = link_id++;
|
||||
// XomwLinkHolderItem item = new XomwLinkHolderItem(ttl, capt, Bry_.Ary_empty);
|
||||
// internals.Add(key, item);
|
||||
// }
|
||||
// public void Replace(Xomw_parser_ctx pctx, Xomw_parser_bfr pbfr) {
|
||||
// this.Replace_internal(pbfr);
|
||||
//// $this->replaceInterwiki( $text );
|
||||
// }
|
||||
// private void Replace_internal(Xomw_parser_bfr pbfr) {
|
||||
// if (internals.Len() == 0)
|
||||
// return;
|
||||
//
|
||||
//// $colours = [];
|
||||
//// $linkCache = LinkCache::singleton();
|
||||
//// $output = $this->parent->getOutput();
|
||||
//// $linkRenderer = $this->parent->getLinkRenderer();
|
||||
//
|
||||
//// $linkcolour_ids = [];
|
||||
//
|
||||
// // SKIP:Replace_internals does db lookup to identify redlinks;
|
||||
//
|
||||
// // Construct search and replace arrays
|
||||
// Bry_bfr src_bfr = pbfr.Src();
|
||||
// byte[] src = src_bfr.Bfr();
|
||||
// int src_bgn = 0;
|
||||
// int src_end = src_bfr.Len();
|
||||
// Bry_bfr bfr = pbfr.Trg();
|
||||
// pbfr.Switch();
|
||||
//
|
||||
// int cur = src_bgn;
|
||||
// int prv = 0;
|
||||
// while (true) {
|
||||
// int link_bgn = Bry_find_.Find_fwd(src, Bry__link__bgn, cur, src_end);
|
||||
// if (link_bgn == Bry_find_.Not_found) {
|
||||
// bfr.Add_mid(src, prv, src_end);
|
||||
// break;
|
||||
// }
|
||||
// int key_bgn = link_bgn + Bry__link__bgn.length;
|
||||
// int key_end = Bry_find_.Find_fwd_while_num(src, key_bgn, src_end);
|
||||
// int link_key = Bry_.To_int_or(src, key_bgn, key_end, -1);
|
||||
// XomwLinkHolderItem item = internals.Get_by(link_key);
|
||||
//
|
||||
//// $pdbk = $entry['pdbk'];
|
||||
//// $title = $entry['title'];
|
||||
//// $query = isset( $entry['query'] ) ? $entry['query'] : [];
|
||||
//// $key = "$ns:$index";
|
||||
//// $searchkey = "<!--LINK $key-->";
|
||||
//// $displayText = $entry['text'];
|
||||
//// if ( isset( $entry['selflink'] ) ) {
|
||||
//// $replacePairs[$searchkey] = Linker::makeSelfLinkObj( $title, $displayText, $query );
|
||||
//// continue;
|
||||
//// }
|
||||
//// if ( $displayText === '' ) {
|
||||
//// $displayText = null;
|
||||
//// } else {
|
||||
//// $displayText = new HtmlArmor( $displayText );
|
||||
//// }
|
||||
//// if ( !isset( $colours[$pdbk] ) ) {
|
||||
//// $colours[$pdbk] = 'new';
|
||||
//// }
|
||||
//// $attribs = [];
|
||||
//// if ( $colours[$pdbk] == 'new' ) {
|
||||
//// $linkCache->addBadLinkObj( $title );
|
||||
//// $output->addLink( $title, 0 );
|
||||
//// $link = $linkRenderer->makeBrokenLink(
|
||||
//// $title, $displayText, $attribs, $query
|
||||
//// );
|
||||
//// } else {
|
||||
//// $link = $linkRenderer->makePreloadedLink(
|
||||
//// $title, $displayText, $colours[$pdbk], $attribs, $query
|
||||
//// );
|
||||
//// }
|
||||
//
|
||||
// bfr.Add_mid(src, prv, link_bgn);
|
||||
// link_renderer.Make_preloaded_link(bfr, item.Title(), item.Text(), Bry_.Empty, extra_atrs, query.Clear());
|
||||
// cur = key_end + Gfh_tag_.Comm_end_len;
|
||||
// prv = cur;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static final byte[] Bry__link__bgn = Bry_.new_a7("<!--LINK ");
|
||||
// }
|
||||
//}
|
@ -53,7 +53,6 @@ public class Xomw_parser {
|
||||
public Xomw_lnki_wkr Lnki_wkr() {return lnki_wkr;} private final Xomw_lnki_wkr lnki_wkr;
|
||||
public boolean Output_type__wiki() {return output_type__wiki;} private final boolean output_type__wiki = false;
|
||||
|
||||
|
||||
private int mLinkID;
|
||||
/**
|
||||
* @return int
|
||||
@ -177,7 +176,7 @@ public class Xomw_parser {
|
||||
|
||||
block_wkr.Do_block_levels(pctx, pbfr, line_start);
|
||||
|
||||
lnki_wkr.Replace_link_holders(pctx, pbfr);
|
||||
lnki_wkr.replaceLinkHolders(pbfr);
|
||||
|
||||
// The input doesn't get language converted if
|
||||
// a) It's disabled
|
||||
|
@ -675,24 +675,25 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
// $handler->parserTransformHook($this, $file);
|
||||
// }
|
||||
}
|
||||
// private byte[] stripAltText(byte[] caption, Xomw_link_holders holders) {
|
||||
// private byte[] stripAltText(byte[] caption, XomwLinkHolderArray holders) {
|
||||
// // Strip bad stuff out of the title (tooltip). We can't just use
|
||||
// // replaceLinkHoldersText() here, because if this function is called
|
||||
// // from replaceInternalLinks2(), mLinkHolders won't be up-to-date.
|
||||
// byte[] tooltip;
|
||||
// if (holders != null) {
|
||||
// tooltip = holders.Replace(caption);
|
||||
// tooltip = holders.replace(caption);
|
||||
// } else {
|
||||
// tooltip = this.Replace_link_holders(caption);
|
||||
// tooltip = this.replace_link_holders(caption);
|
||||
// }
|
||||
|
||||
//
|
||||
// // make sure there are no placeholders in thumbnail attributes
|
||||
// // that are later expanded to html- so expand them now and
|
||||
// // remove the tags
|
||||
// $tooltip = $this->mStripState->unstripBoth( $tooltip );
|
||||
// $tooltip = Sanitizer::stripAllTags( $tooltip );
|
||||
//
|
||||
// return $tooltip;
|
||||
//// $tooltip = $this->mStripState->unstripBoth( $tooltip );
|
||||
//// $tooltip = Sanitizer::stripAllTags( $tooltip );
|
||||
////
|
||||
//// return $tooltip;
|
||||
// return null;
|
||||
// }
|
||||
|
||||
private static Xomw_param_list[] internalParamNames;
|
||||
@ -816,8 +817,8 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
public void Maybe_do_subpage_link(XomwLinker_NormalizeSubpageLink rv, byte[] target, byte[] text) {
|
||||
linker.normalizeSubpageLink(rv, mPageTitle, target, text);
|
||||
}
|
||||
public void Replace_link_holders(Xomw_parser_ctx pctx, Xomw_parser_bfr pbfr) {
|
||||
holders.Replace(pctx, pbfr);
|
||||
public void replaceLinkHolders(Xomw_parser_bfr pbfr) {
|
||||
holders.replace(pbfr);
|
||||
}
|
||||
public void Make_known_link_holder(Bry_bfr bfr, XomwTitle nt, byte[] text, byte[] trail, byte[] prefix) {
|
||||
byte[][] split_trail = linker.splitTrail(trail);
|
||||
|
@ -112,7 +112,7 @@ class Xomw_lnki_wkr__fxt {
|
||||
private String Exec__to_html(String src_str) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
wkr.Replace_internal_links(pctx, pbfr.Init(src_bry));
|
||||
wkr.Replace_link_holders(pctx, pbfr);
|
||||
wkr.replaceLinkHolders(pbfr);
|
||||
return pbfr.Rslt().To_str_and_clear();
|
||||
}
|
||||
public void Test__parseWidthParam(int[] img_size, String src_str, int expd_w, int expd_h) {
|
||||
|
Loading…
Reference in New Issue
Block a user