markdown-proofing
Version:
A markdown proofing platform for individuals, teams, and organizations.
53 lines (39 loc) • 2.05 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _stripMarkdown = require('strip-markdown');
var _stripMarkdown2 = _interopRequireDefault(_stripMarkdown);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var remark = require('remark').use(_stripMarkdown2.default);
// Use this class for consistency across analyzers
//
// Note: Processing the original text in any manner may change the locations
// (as in, line and column) of characters. This may be applicable when
// reporting on text locations inside analyzers.
var TextProcessor = function () {
function TextProcessor() {
_classCallCheck(this, TextProcessor);
}
_createClass(TextProcessor, null, [{
key: 'removeYamlFrontMatter',
value: function removeYamlFrontMatter(str) {
return str.replace(/^\n*-{3}(.|\n)*-{3}\n*/, '');
}
}, {
key: 'markdownToText',
value: function markdownToText(str) {
var preprocessedStr = str
// Remove empty links
.replace(/\[\]\(\)/g, '')
// Remove empty list items
.replace(/^(-|\*)\s*\n/gm, '');
return this.removeYamlFrontMatter(remark.process(preprocessedStr));
}
}]);
return TextProcessor;
}();
exports.default = TextProcessor;
module.exports = exports['default'];
;