aboutsummaryrefslogtreecommitdiff
path: root/guidelines/wikipedia/src/spaceBetweenParagraphs.js
blob: ccab3a4aef6a4fd4c7541569d99157af63226e74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
exports.name = "There should only be one blank line between paragraphs";
exports.description = "Between sections - as between sections - there should be only a single blank line.";

exports.rule = function(report) {
  var problemPs = [];

  $5('p:has(> br)').each(function(i, p) {
    var $p = $(p), prevP;
    if ($.trim($p.text()).length === 0) {
      prevP = $p.prevAll('p').filter(function(i, pp) {
        return $.trim($(pp).text()).length > 0;
      }).first();

      if (prevP.length) {
        problemPs.push(prevP.get(0));
      }
      else {
        report.error('Paragraph contains line breaks but does not contain text.', p);
      }
    }
  });

  _.uniq(problemPs, false).forEach(function(p) {
    var text = $.trim($(p).text());
    report.error('Paragraph is followed by more than one blank line: '+ text, p);
  });
};