/**
* transformStyles.js: Provides transformations in CSS of Wikipedia articles contained in the ZIM file
* This allows the user to choose the presentation style for the page to be viewed.
* Currently available are "mobile" and "desktop" display modes.
*
* Copyright 2017 Kiwix developers
* License GPL v3:
*
* This file is part of Kiwix.
*
* Kiwix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiwix 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kiwix (file LICENSE-GPLv3.txt). If not, see
]*>', '
', 'gi'); var matched = false; if (paras.length) { for (var g = 0; g < 3; g++) { //Check if the paragraph is a proper sentence, i.e. contains at least 50 non-HTML-delimetered non-full-stop characters, followed by a punctuation character if (paras[g] && /[^.]{50,}[^.]*[.,;:?!-]/.test(paras[g].replace(/<[^>]*>/g, ""))) { matched = true; break; } } if (matched) { //Swap table and first matched paragraph, but mark lead paragraph first //We already deleted the table above html = temphtml; html = html.replace(paras[g], paras[g].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;"');
//Wrap ]*>(?:(?=([^<]+))\2|<(?!p\b[^>]*>))*?<\/p>(?:<\/span\s*>)?[^<]*)([\s\S]*?)( ]+titleHeading[^>]+>\s*<\/h1>\s*/ig, "");
}
//Add dark theme if requested
css += (params.cssTheme == "dark") ? '\r\n' : (params.cssTheme == "invert") ? '\r\n' : "";
html = (params.cssTheme == "dark") ? html.replace(/( tags in
)/ig, '
]*)background-color\s*:\s*white;\s*/i, "$1") : html;
html = (params.cssTheme == "dark") ? html.replace(/(
]*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, ']*)background-color:\s*white;\s*/i, "$1") : html;
html = (params.cssTheme == "dark") ? html.replace(/(