Removed markdown-it-named-headers and unused string deps (#8994)

refs https://github.com/TryGhost/Ghost-Admin/pull/856

- moves `markdown-it-named-headers` functionality into our own app code without requiring the [`string.js`](http://stringjs.com) sub-dependency
- matches Ghost-Admin markdown-it code
This commit is contained in:
Kevin Ansfield 2017-09-25 15:36:34 +01:00 committed by Katharina Irrgang
parent 55bf5997b9
commit ec6e25674c
3 changed files with 29 additions and 15 deletions

View File

@ -7,16 +7,41 @@ var MarkdownIt = require('markdown-it'),
.use(require('markdown-it-footnote'))
.use(require('markdown-it-lazy-headers'))
.use(require('markdown-it-mark'))
.use(require('markdown-it-named-headers'), {
// match legacy Showdown IDs otherwise default is github style dasherized
slugify: function (inputString, usedHeaders) {
.use(function namedHeaders(md) {
// jscs:disable
// match legacy Showdown IDs
var slugify = function (inputString, usedHeaders) {
var slug = inputString.replace(/[^\w]/g, '').toLowerCase();
if (usedHeaders[slug]) {
usedHeaders[slug] += 1;
slug += usedHeaders[slug];
}
return slug;
}
};
var originalHeadingOpen = md.renderer.rules.heading_open;
// originally from https://github.com/leff/markdown-it-named-headers
// moved here to avoid pulling in http://stringjs.com dependency
md.renderer.rules.heading_open = function (tokens, idx, something, somethingelse, self) {
var used_headers = {};
tokens[idx].attrs = tokens[idx].attrs || [];
var title = tokens[idx + 1].children.reduce(function (acc, t) {
return acc + t.content;
}, '');
var slug = slugify(title, used_headers);
tokens[idx].attrs.push(['id', slug]);
if (originalHeadingOpen) {
return originalHeadingOpen.apply(this, arguments);
} else {
return self.renderToken.apply(self, arguments);
}
};
// jscs:enable
});
module.exports = {

View File

@ -67,7 +67,6 @@
"markdown-it-footnote": "3.0.1",
"markdown-it-lazy-headers": "0.1.3",
"markdown-it-mark": "2.0.0",
"markdown-it-named-headers": "0.0.4",
"mobiledoc-dom-renderer": "0.6.5",
"moment": "2.18.1",
"moment-timezone": "0.5.13",

View File

@ -3311,12 +3311,6 @@ markdown-it-mark@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/markdown-it-mark/-/markdown-it-mark-2.0.0.tgz#46a1aa947105aed8188978e0a016179e404f42c7"
markdown-it-named-headers@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/markdown-it-named-headers/-/markdown-it-named-headers-0.0.4.tgz#82efc28324240a6b1e77b9aae501771d5f351c1f"
dependencies:
string "^3.0.1"
markdown-it@8.4.0:
version "8.4.0"
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.4.0.tgz#e2400881bf171f7018ed1bd9da441dac8af6306d"
@ -5040,10 +5034,6 @@ string-width@^1.0.1:
is-fullwidth-code-point "^1.0.0"
strip-ansi "^3.0.0"
string@^3.0.1:
version "3.3.3"
resolved "https://registry.yarnpkg.com/string/-/string-3.3.3.tgz#5ea211cd92d228e184294990a6cc97b366a77cb0"
string_decoder@~0.10.x:
version "0.10.31"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"