diff --git a/www/js/lib/transformStyles.js b/www/js/lib/transformStyles.js index 0f31e6c7..b717fe5d 100644 --- a/www/js/lib/transformStyles.js +++ b/www/js/lib/transformStyles.js @@ -107,11 +107,11 @@ define(['util', 'uiUtil'], function (util, uiUtil) { //var test = html.getElementById("qbRight") if (zim == "desktop") { var infobox = []; - if (/]+(?:infobox|vertical-navbox|qbRight|wikitable)/i.test(html)) { - infobox = util.matchOuter(html, ']+(?:infobox|vertical-navbox|qbRight|wikitable)[^>]+>', '', 'i'); + if (/]+(?:infobox|vertical-navbox|qbRight|wv-quickbar|wikitable)/i.test(html)) { + infobox = util.matchOuter(html, ']+(?:infobox|vertical-navbox|qbRight|wv-quickbar|wikitable)[^>]+>', '', 'i'); } else { - if (/]+(?:infobox|vertical-navbox|qbRight|wikitable)/i.test(html)) { - infobox = util.matchOuter(html, ']+(?:infobox|vertical-navbox|qbRight|wikitable)[^>]+>', '', 'i'); + if (/]+(?:infobox|vertical-navbox|qbRight|wv-quickbar|wikitable)/i.test(html)) { + infobox = util.matchOuter(html, ']+(?:infobox|vertical-navbox|qbRight|wv-quickbar|wikitable)[^>]+>', '', 'i'); } } if (infobox.length) { @@ -134,9 +134,9 @@ define(['util', 'uiUtil'], function (util, uiUtil) { } //html = zim == "desktop" ? html.replace(/(]*(?:infobox|vertical-navbox|qbRight))[\s\S]+?<\/table>[^<]*)((?:\s*)?]*>(?:(?=([^<]+))\3|<(?!p\b[^>]*>))*?<\/p>(?:)?)/i, "$2\r\n$1") : html; //Set infobox styling hard-coded in Wikipedia mobile - html = html.replace(/(table\s+(?=[^>]*class\s*=\s*["'][^"']*(?:infobox|vertical-navbox|qbRight|wikitable))[^>]*style\s*=\s*["'][^"']+[^;'"]);?\s*["']/ig, '$1; position: relative; border: 1px solid #eaecf0; text-align: left; background-color: #f8f9fa;"'); + html = html.replace(/(table\s+(?=[^>]*class\s*=\s*["'][^"']*(?:infobox|vertical-navbox|qbRight|wv-quickbar|wikitable))[^>]*style\s*=\s*["'][^"']+[^;'"]);?\s*["']/ig, '$1; position: relative; border: 1px solid #eaecf0; text-align: left; background-color: #f8f9fa;"'); //Wrap

tags in
to control bottom border width if there's an infobox - html = html.match(/table\s+(?=[^>]*class\s*=\s*["'][^"']*(?:infobox|vertical-navbox|qbRight|wikitable))/i) ? html.replace(/()/ig, '
$1
') : html; + html = html.match(/table\s+(?=[^>]*class\s*=\s*["'][^"']*(?:infobox|vertical-navbox|qbRight|wv-quickbar|wikitable))/i) ? html.replace(/()/ig, '
$1
') : html; } //Add dark theme if requested css += (params.cssTheme == "dark") ? '\r\n' : (params.cssTheme == "invert") ? '\r\n' :""; @@ -158,17 +158,15 @@ define(['util', 'uiUtil'], function (util, uiUtil) { console.log(zim == "mobile" ? "Transforming display style to desktop..." : "Optimizing cached styles for desktop display..."); uiUtil.poll("mobile" ? "Transforming display style to desktop..." : "Optimizing cached styles for desktop display..."); //If it's in mobile position, move info-box above lead paragraph like on Wikipedia desktop - //html = html.replace(/((?:\s*)?]*>(?:(?=([^<]+))\2|<(?!p\b[^>]*>))*?<\/p>(?:<\/span\s*>)?[^<]*)([\s\S]*?)(]*infobox)[\s\S]+?<\/table>)/i, "$4$3$1"); if (zim == "mobile") { - var tableBox = util.matchOuter(html, ']+?(?:infobox|vertical-navbox|qbRight|wikitable)[^>]+>', '', 'i'); - if (!(tableBox && tableBox.length)) { - //If above failed we may have div style infobox - tableBox = util.matchOuter(html, ']+?(?:qbRight)[^>]+>', '
', 'i'); - } - //html = tableBox && tableBox.length ? html.replace(tableBox, "@@@KiwixSep@@@") : html; + //Attempt to match div-style infobox first + var tableBox = util.matchOuter(html, ']+?(?:qbRight|wv-quickbar)[^>]+>', '', 'i'); + //If above failed we may have traditional table-style infobox + tableBox = !(tableBox && tableBox.length) ? util.matchOuter(html, ']+?(?:infobox|vertical-navbox|qbRight|wikitable)[^>]+>', '', 'i') : tableBox; if (tableBox && tableBox.length) { html = html.replace(tableBox, "@@@KiwixSep@@@"); - html = html.replace(/((?:\s*)?...

followed by Kiwix separator or

...

followed by small skpped

containing no more than 40 characters (this happens in Wikivoyage English) + html = html.replace(/(<(?:(span\b)[^>]*>\s*<)?p\b[^>]*>(?:(?=([^<]+))\3|<(?!p\b))*?<\/p>\s*(?:<\/)?\2(?:>\s*)?(?:\s*)?)@@@KiwixSep@@@/i, tableBox + "\r\n$1"); //Do the replacement below just in case above regex failed html = html.replace(/@@@KiwixSep@@@/, tableBox); }