From 77215a8c9bd994417807f7304beee0d2b0fe18af Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Thu, 13 Jul 2017 14:42:54 +0100 Subject: [PATCH] Added documentation of transformations Former-commit-id: 1875b04960fc8b6b7eaf9dc68ec86c52191e25ab [formerly 294b25360bbf9034cc25ecc0ee66e45df90ea44a] Former-commit-id: 019e7c794233b93fd572ee7f0d3df66eff6006f6 --- www/js/app.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index ab7d117c..ee147e9a 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -866,21 +866,29 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles cssArray$ += cssArray$.match(/-\/s\/css_modules\/content\.parsoid\.css/i) ? "" : '\r\n'; cssArray$ += cssArray$.match(/-\/s\/css_modules\/inserted_style_mobile\.css/i) ? "" : '\r\n'; cssArray$ += cssArray$.match(/-\/s\/css_modules\/mobile\.css/i) ? "" : '\r\n'; - htmlArticle = htmlArticle.replace(/(]*mw-body[^>]+style[^>]+padding\s*:\s*)1em/i, "$10 1em"); + //Allow images to float right or left htmlArticle = htmlArticle.replace(/class\s*=\s*["']\s*thumb\s+tright\s*["']\s*/ig, 'style="float: right; clear: right; margin-left: 1.4em;"'); htmlArticle = htmlArticle.replace(/class\s*=\s*["']\s*thumb\s+tleft\s*["']\s*/ig, 'style="float: left; clear: left; margin-right: 1.4em;"'); + //Add styling to image captions that is hard-coded in Wikipedia mobile htmlArticle = htmlArticle.replace(/class\s*=\s*["']\s*thumbcaption\s*["']\s*/ig, 'style="margin: 0.5em 0 0.5em; font-size: 0.8em; line-height: 1.5; padding: 0 !important; color: #54595d; width: auto !important;"'); - //Move info-box below lead + //Move info-box below lead paragraph like on Wikipedia mobile htmlArticle = htmlArticle.replace(/(]*infobox)[\s\S]+?<\/table>[^<]*)(]*>(?:(?=([^<]+))\3|<(?!p\b[^>]*>))*?<\/p>)/ig, "$2$1"); + //Set infobox styling hard-coded in Wikipedia mobile htmlArticle = htmlArticle.replace(/(table\s+(?=[^>]*class\s*=\s*["'][^"']*infobox)[^>]*style\s*=\s*["'][^"']+[^;'"]);?\s*["']/ig, '$1; position: relative; border: 1px solid #eaecf0; text-align: left; background-color: #f8f9fa;"'); } if (cssSource == "desktop") { //If user has selected desktop display mode... + //Ensure white background colour htmlArticle = htmlArticle.replace(/class\s*=\s*["']\s*mw-body\s*["']\s*/ig, 'style="background-color: white; padding: 1em; border-width: 0px; max-width: 55.8em; margin: 0 auto 0 auto;"'); - htmlArticle = htmlArticle.replace(/]+titleHeading[^>]+>\s*<\/h1>\s*/ig, ""); //Void empty header title + //Void empty header title + htmlArticle = htmlArticle.replace(/]+titleHeading[^>]+>\s*<\/h1>\s*/ig, ""); + } + if (cssSource != "zimfile") { //For all cases except where user wants exactly what's in the zimfile... + //Reduce the hard-coded top padding to 0 + htmlArticle = htmlArticle.replace(/(]*mw-body[^>]+style[^>]+padding\s*:\s*)1em/i, "$10 1em"); } htmlArticle = htmlArticle.replace(/\s*(<\/head>)/i, cssArray$ + "$1"); console.log("All CSS resolved"); - injectHTML(htmlArticle); //This passes the revised HTML to the image and JS subroutine... + injectHTML(htmlArticle); //Pass the revised HTML to the image and JS subroutine... } else { //console.log("Waiting for " + (cssArray.length - blobArray.length) + " out of " + cssArray.length + " to resolve...") }