Ghost/core/server/utils/markdown-converter.js
Kevin Ansfield b82932b492 🎨 Disabled auto-linking of domain names in markdown (#9084)
closes https://github.com/TryGhost/Ghost/issues/8987

- set `linkify-it` `fuzzyLink` option to false so that it only auto-links URLs starting with `http(s)://` or other valid schemes
2017-10-03 12:14:53 +02:00

57 lines
1.7 KiB
JavaScript

var MarkdownIt = require('markdown-it'),
converter = new MarkdownIt({
html: true,
breaks: true,
linkify: true
})
.use(require('markdown-it-footnote'))
.use(require('markdown-it-lazy-headers'))
.use(require('markdown-it-mark'))
.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
});
// configure linkify-it
converter.linkify.set({
fuzzyLink: false
});
module.exports = {
render: function (markdown) {
return converter.render(markdown);
}
};