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

earldouglas / codedown / #371

21 Dec 2025 02:45AM UTC coverage: 71.429%. First build
#371

Pull #40

earldouglas
Format with prettier and add it as a linter
Pull Request #40: Format with prettier and add it as a linter

19 of 34 branches covered (55.88%)

33 of 52 new or added lines in 2 files covered. (63.46%)

50 of 70 relevant lines covered (71.43%)

1.61 hits per line

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

67.74
/lib/codedown.js
1
(function (root) {
1✔
2
  "use strict";
3

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

7
  var codedown = function (src, lang, separator, targetSections) {
1✔
8
    if (targetSections === undefined) {
1!
9
      targetSections = [];
1✔
10
    }
11

12
    if (separator === undefined) {
1!
13
      separator = "";
1✔
14
    }
15

16
    separator = separator + "\n";
1✔
17

18
    var renderer = new marked.Renderer();
1✔
19

20
    var renderers = Object.getOwnPropertyNames(marked.Renderer.prototype);
1✔
21

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

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

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

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

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

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

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

NEW
71
      currentSectionName = ("#".repeat(level) + " " + raw).trim();
×
NEW
72
      sectionNumbers[currentSectionName] = currentSectionNumber.join(".");
×
73

NEW
74
      return "";
×
75
    };
76

77
    renderer.code = function (src, language, escaped) {
1✔
78
      var result = "";
1✔
79

80
      if (languageMatches(language) && sectionMatches()) {
1!
81
        result = separator + src + "\n";
1✔
82
      }
83

84
      return result;
1✔
85
    };
86

87
    renderer.listitem = function (text) {
1✔
88
      return text;
2✔
89
    };
90
    renderer.list = function (body, ordered) {
1✔
91
      return body;
1✔
92
    };
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✔
NEW
106
  } else if (typeof define === "function" && define.amd) {
×
NEW
107
    define(function () {
×
NEW
108
      return codedown;
×
109
    });
110
  } else {
111
    root.codedown = codedown;
×
112
  }
113
})(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