aboutsummaryrefslogtreecommitdiff
path: root/guidelines/wikipedia/src/headingOrder.js
diff options
context:
space:
mode:
authorGravatar Jesse Hallett <jesse@galois.com>2014-01-06 10:50:22 -0800
committerGravatar Jesse Hallett <jesse@galois.com>2014-01-06 11:15:49 -0800
commit55cd32bfaf9ed5bc5418751369e46fa1d7f098e8 (patch)
treec5759cf75241a4e6bc0fb31596b69c59a9bdc6b5 /guidelines/wikipedia/src/headingOrder.js
parent0a47eab285bf1c04f48a2d6d84838a98807c8c69 (diff)
Moves rule files to src/
Diffstat (limited to 'guidelines/wikipedia/src/headingOrder.js')
-rw-r--r--guidelines/wikipedia/src/headingOrder.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/guidelines/wikipedia/src/headingOrder.js b/guidelines/wikipedia/src/headingOrder.js
new file mode 100644
index 0000000..dfb7777
--- /dev/null
+++ b/guidelines/wikipedia/src/headingOrder.js
@@ -0,0 +1,47 @@
+/**
+ * Layout rules for Wikipedia article content
+ */
+exports.name = "Headings should be in order.";
+exports.description = "Headers should increase sequentially, or reset to a higher section level.";
+
+exports.rule = function(report) {
+ findH1s(report);
+
+ checkHeadingOrder(report);
+};
+
+/**
+ * No H1 headings should be used in the article content.
+ */
+var findH1s = function(report) {
+ $5('#mw-content-text h1').each(
+ function(idx, elt){
+ report.error("Top-level headings should not be used in article content.");
+ });
+};
+
+
+/**
+ * Check that headers increase one step at a time, or go back to the
+ * beginning (in this case, heading 2).
+ *
+ * Headers using the &lt;header&gt; tag are except from this check.
+ */
+var checkHeadingOrder = function(report) {
+ var last=1;
+
+ $5('#mw-content-text :header').each(
+ function(idx, elt){
+ // parse the level out of 'h1', 'h2', 'h3', etc.
+ var level = parseInt(elt.tagName.substring(1,2));
+
+ if (level > (last + 1)) {
+ report.error("Heading is out of order; heading level was: "+level+
+ " but last level was: "+last, elt);
+ }
+ // set the level regardless, since the error *could* be with the
+ // prior level heading, so we don't want to cause more errors
+ // erroniously:
+ last = level;
+ });
+};