• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

earldouglas / codedown / #342

21 Dec 2025 02:28AM UTC coverage: 78.431%. First build
#342

Pull #38

earldouglas
Add support for multiple --section arguments
Pull Request #38: Add support for multiple --section arguments

33 of 62 branches covered (53.23%)

14 of 24 new or added lines in 2 files covered. (58.33%)

120 of 153 relevant lines covered (78.43%)

1.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.24
/lib/codedown.js
1
(function(root) {
1✔
2

3
  'use strict';
4

5
  var marked    = root.marked || require('marked');
1✔
6
  var minimatch = root.minimatch || require("minimatch");
1✔
7

8
  var codedown = function(src, lang, separator, targetSections) {
1✔
9

10
    if (targetSections === undefined) {
1!
11
      targetSections = [];
1✔
12
    }
13

14
    if (separator === undefined) {
1!
15
      separator = '';
1✔
16
    }
17

18
    separator = separator + '\n';
1✔
19

20
    var renderer = new marked.Renderer();
1✔
21

22
    var renderers =
1✔
23
      Object.getOwnPropertyNames(marked.Renderer.prototype);
24

25
    for (var i = 0; i < renderers.length; i++) {
1✔
26
      var f = renderers[i];
21✔
27
      if (f !== 'constructor') {
21✔
28
        renderer[renderers[i]] = function () { return ''; };
20✔
29
      }
30
    }
31

32
    var currentSectionNumber = [];
1✔
33
    var currentSectionName = null;
1✔
34
    var sectionNumbers = {};
1✔
35

36
    var sectionNumberMatches =
1✔
37
      function () {
NEW
38
        var n = currentSectionNumber.join('.');
×
NEW
39
        var k = function (x) {
×
NEW
40
          return n.startsWith(x);
×
41
        };
NEW
42
        return targetSections.find(k) !== undefined;
×
43
      };
44

45
    var sectionNameMatches =
1✔
46
      function () {
NEW
47
        var n = sectionNumbers[currentSectionName];
×
NEW
48
        var k = function (x) {
×
NEW
49
          return n.startsWith(sectionNumbers[x]);
×
50
        };
NEW
51
        return targetSections.find(k) !== undefined;
×
52
      };
53

54
    var sectionMatches =
1✔
55
      function () {
56
        return targetSections.length === 0 || sectionNumberMatches() || sectionNameMatches();
1!
57
      };
58

59
    var languageMatches =
1✔
60
      function (language) {
61
        return language && (language === '*' || minimatch(language, lang));
1✔
62
      };
63

64
    renderer.heading =
1✔
65
      function(text, level, raw) {
66
        var index = level - 1; // 0-based indexing
×
67
        for (var i = 0; i <= index;  i++) {
×
68
          currentSectionNumber[i] = currentSectionNumber[i] || 0;
×
69
        }
70
        currentSectionNumber[index] = currentSectionNumber[index] + 1;
×
71
        currentSectionNumber.splice(level);
×
72

73
        currentSectionName = ('#'.repeat(level) + ' ' + raw).trim();
×
74
        sectionNumbers[currentSectionName] = currentSectionNumber.join('.');
×
75

76
        return '';
×
77
      };
78

79
    renderer.code =
1✔
80
      function (src, language, escaped) {
81

82
        var result = '';
1✔
83

84
        if (languageMatches(language) && sectionMatches()) {
1!
85
          result = separator + src + '\n';
1✔
86
        }
87

88
        return result;
1✔
89
      };
90

91
    renderer.listitem = function (text) { return text; };
2✔
92
    renderer.list = function (body, ordered) { return body; };
1✔
93

94
    marked.use({ renderer: renderer });
1✔
95

96
    var output = marked.parse(src);
1✔
97
    output = output.replace(/\n+$/g, '');
1✔
98

99
    return output.substring(separator.length);
1✔
100
  };
101

102
  root.codedown = codedown;
1✔
103

104
  if (typeof module !== 'undefined' && typeof exports === 'object') {
1!
105
    module.exports = codedown;
1✔
106
  } else if (typeof define === 'function' && define.amd) {
×
107
    define(function() { return codedown; });
×
108
  } else {
109
    root.codedown = codedown;
×
110
  }
111
})(this || (typeof window !== 'undefined' ? window : global));
1!
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc