aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-12-09 22:22:48 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2016-12-09 22:22:48 +0100
commit0a2d6af06db880bf4062d444bf8b7e2df6aacef2 (patch)
treec75c9e00192beab5bb743894512657d63f47240e
parent4e9b80ece8979c6dfd79a08672fa13c4d3104fd2 (diff)
Improved npm package: package.json and index.js.
Added .tests (JSON) and .version to index.js. Added version. Added license, description.
-rw-r--r--index.js28
-rw-r--r--package.json10
2 files changed, 33 insertions, 5 deletions
diff --git a/index.js b/index.js
index 6068627..9c6b739 100644
--- a/index.js
+++ b/index.js
@@ -1,7 +1,31 @@
'use strict';
-const fs = require('fs');
-const path = require('path');
+var fs = require('fs');
+var path = require('path');
+var extractSpecTests = function(data) {
+ var examples = [];
+ var current_section = "";
+ var example_number = 0;
+ var tests = data
+ .replace(/\r\n?/g, "\n") // Normalize newlines for platform independence
+ .replace(/^<!-- END TESTS -->(.|[\n])*/m, '');
+
+ tests.replace(/^`{32} example\n([\s\S]*?)^\.\n([\s\S]*?)^`{32}$|^#{1,6} *(.*)$/gm,
+ function(_, markdownSubmatch, htmlSubmatch, sectionSubmatch){
+ if (sectionSubmatch) {
+ current_section = sectionSubmatch;
+ } else {
+ example_number++;
+ examples.push({markdown: markdownSubmatch,
+ html: htmlSubmatch,
+ section: current_section,
+ number: example_number});
+ }
+ });
+ return examples;
+};
exports.text = fs.readFileSync(path.join(__dirname, 'spec.txt'), 'utf8');
+exports.tests = extractSpecTests(exports.text);
+exports.version = exports.text.match(/^version: *([0-9.]*)/m)[1];
diff --git a/package.json b/package.json
index 6883746..396be07 100644
--- a/package.json
+++ b/package.json
@@ -1,12 +1,16 @@
{
"name": "commonmark-spec",
- "version": "-",
- "description": "Commonmark spec.",
+ "version": "0.27.0",
+ "description": "CommonMark spec and test cases",
+ "homepage": "http://commonmark.org",
+ "license": "CC-BY-SA-4.0",
"keywords": [
"commonmark",
"markdown"
],
- "repository": "jgm/CommonMark",
+ "repository":
+ { "type": "git",
+ "url": "https://github.com/jgm/CommonMark.git" },
"license": "MIT",
"files": [
"index.js",