Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Mutliple fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Gerber committed Oct 27, 2014
1 parent f315f25 commit 77bb2d9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1>{{propName}}</h1>
<div class="scroller" tabIndex="0"> <!-- tabIndex needed: otherwise can't be focused on open or via click -->
<dl>
{{#propValues}}
<dt>{{value}}</dt>
<dt>{{{value}}}</dt>
<dd>{{{description}}}</dd>
{{/propValues}}
</dl>
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/default/WebPlatformDocs/css.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
}
],
"devDependencies": {
"instaview": "0.6.3",
"lodash.unescape": "2.4.1"
"instaview": "0.6.3"
},
"repository": {
"type": "git",
Expand Down
33 changes: 20 additions & 13 deletions src/extensions/default/WebPlatformDocs/update-docs/update-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@
*
*/
/*global require*/
/*jslint regexp:true */

(function () {
"use strict";

var fs = require("fs"),
https = require("https"),
instaview = require("instaview"),
unescape = require("lodash.unescape");
instaview = require("instaview"); // Wikitext > HTML

instaview.conf.paths.articles = "https://docs.webplatform.org/wiki/";
instaview.conf.paths.articles = "https://docs.webplatform.org/wiki/"; // base URL for every link
instaview.conf.locale.image = "__Image__"; // disable <img> tags

var propertiesURL = "https://docs.webplatform.org/w/api.php?action=ask&format=json&query=%20%5B%5BPath%3A%3A~css%2Fproperties%2F*%5D%5D%7C%3FSummary%7Cprettyprint%3Dno%7Climit%3D100000", // #ask: [[Path::~css/properties/*]]|?Summary|prettyprint=no|limit=100000
valuesURL = "https://docs.webplatform.org/w/api.php?action=ask&format=json&query=%5B%5BValue%20for%20property%3A%3A~css%2Fproperties%2F*%5D%5D%7C%3FProperty%20value%7C%3FProperty%20value%20description%7C%3FValue%20for%20property%7Cprettyprint%3Dno%7Climit%3D100000"; // #ask: [[Value for property::~css/properties/*]]|?Property value|?Property value description|?Value for property|prettyprint=no|limit=100000
Expand All @@ -39,6 +40,15 @@
outputFile = "../css.json",
propertiesResponse = "",
valuesResponse = "";

function htmlEscape(str) {
return str.replace(/<(\/?)([^>]*)>/g, function (match, slash, inner) {
if (["code", "div", "tt"].indexOf(inner) === -1) { // escape all tags except <code>, <div>, <tt>
return "&lt;" + slash + inner + "&gt;";
}
return match;
});
}

console.log("Getting properties");
https.get(propertiesURL, function (res) {
Expand All @@ -53,7 +63,7 @@
var data = propertiesResponse[propertyName];
var propertyData = {};
if (data.printouts.Summary.length) {
propertyData.SUMMARY = instaview.convert(data.printouts.Summary[0]);
propertyData.SUMMARY = instaview.convert(htmlEscape(data.printouts.Summary[0]));
propertyData.URL = data.fullurl;
propertyData.VALUES = [];

Expand All @@ -67,27 +77,24 @@
});

res.on("end", function () {
function parseHTMLEntities(str) {
return str.replace(/&#([0-9]{1,4});/g, function (match, numStr) {
var num = parseInt(numStr, 10);
return String.fromCharCode(num);
});
}

console.log("Parsing values");
valuesResponse = JSON.parse(valuesResponse).query.results;

Object.keys(valuesResponse).forEach(function (valueIdentifier) {
var data = valuesResponse[valueIdentifier].printouts;
var forProperty = data["Value for property"].length && data["Value for property"][0].fulltext;
var valueData = {};
var description;
if (data["Property value"].length && forProperty && result.hasOwnProperty(forProperty)) {
valueData.DESCRIPTION = "";
if (data["Property value description"].length) {
valueData.DESCRIPTION = instaview.convert(data["Property value description"][0]);
// Remove possible "alt=...;" (image Wikitext)
description = htmlEscape(data["Property value description"][0].replace(/\|alt=([^;]*);/, "|$1"));
valueData.DESCRIPTION = instaview.convert(description);
}
valueData.TITLE = parseHTMLEntities(unescape(data["Property value"][0]));
valueData.TITLE = instaview.convert(htmlEscape(data["Property value"][0])).substr(3); // trim <p> tag

// FUTURE: Currently, there's no deterministic order for the value listing
result[forProperty].VALUES.push(valueData);
}
});
Expand Down

0 comments on commit 77bb2d9

Please sign in to comment.