2017-10-03 13:14:53 +03:00
|
|
|
var MarkdownIt = require('markdown-it'),
|
replace custom showdown fork with markdown-it (#8451)
refs https://github.com/TryGhost/Ghost-Admin/pull/690, closes #1501, closes #2093, closes #4592, closes #4627, closes #4659, closes #5039, closes #5237, closes #5587, closes #5625, closes #5632, closes #5822, closes #5939, closes #6840, closes #7183, closes #7536
- replace custom showdown fork with markdown-it
- swaps showdown for markdown-it when rendering markdown
- match existing header ID behaviour
- allow headers without a space after the #s
- add duplicate header ID handling
- remove legacy markdown spec
- move markdown-it setup into markdown-converter util
- update mobiledoc specs to match markdown-it newline behaviour
- update data-generator HTML to match markdown-it newline behaviour
- fix Post "converts html to plaintext" test
- update rss spec to match markdown-it newline behaviour
- close almost all related showdown bugs
2017-05-15 19:48:14 +03:00
|
|
|
converter = new MarkdownIt({
|
|
|
|
html: true,
|
|
|
|
breaks: true,
|
|
|
|
linkify: true
|
|
|
|
})
|
2017-11-01 16:44:54 +03:00
|
|
|
.use(require('markdown-it-footnote'))
|
|
|
|
.use(require('markdown-it-lazy-headers'))
|
|
|
|
.use(require('markdown-it-mark'))
|
|
|
|
.use(function namedHeaders(md) {
|
|
|
|
// 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 usedHeaders = {};
|
|
|
|
|
|
|
|
tokens[idx].attrs = tokens[idx].attrs || [];
|
|
|
|
|
|
|
|
var title = tokens[idx + 1].children.reduce(function (acc, t) {
|
|
|
|
return acc + t.content;
|
|
|
|
}, '');
|
|
|
|
|
|
|
|
var slug = slugify(title, usedHeaders);
|
|
|
|
tokens[idx].attrs.push(['id', slug]);
|
|
|
|
|
|
|
|
if (originalHeadingOpen) {
|
|
|
|
return originalHeadingOpen.apply(this, arguments);
|
|
|
|
} else {
|
|
|
|
return self.renderToken.apply(self, arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
replace custom showdown fork with markdown-it (#8451)
refs https://github.com/TryGhost/Ghost-Admin/pull/690, closes #1501, closes #2093, closes #4592, closes #4627, closes #4659, closes #5039, closes #5237, closes #5587, closes #5625, closes #5632, closes #5822, closes #5939, closes #6840, closes #7183, closes #7536
- replace custom showdown fork with markdown-it
- swaps showdown for markdown-it when rendering markdown
- match existing header ID behaviour
- allow headers without a space after the #s
- add duplicate header ID handling
- remove legacy markdown spec
- move markdown-it setup into markdown-converter util
- update mobiledoc specs to match markdown-it newline behaviour
- update data-generator HTML to match markdown-it newline behaviour
- fix Post "converts html to plaintext" test
- update rss spec to match markdown-it newline behaviour
- close almost all related showdown bugs
2017-05-15 19:48:14 +03:00
|
|
|
|
2017-10-03 13:14:53 +03:00
|
|
|
// configure linkify-it
|
|
|
|
converter.linkify.set({
|
|
|
|
fuzzyLink: false
|
|
|
|
});
|
|
|
|
|
replace custom showdown fork with markdown-it (#8451)
refs https://github.com/TryGhost/Ghost-Admin/pull/690, closes #1501, closes #2093, closes #4592, closes #4627, closes #4659, closes #5039, closes #5237, closes #5587, closes #5625, closes #5632, closes #5822, closes #5939, closes #6840, closes #7183, closes #7536
- replace custom showdown fork with markdown-it
- swaps showdown for markdown-it when rendering markdown
- match existing header ID behaviour
- allow headers without a space after the #s
- add duplicate header ID handling
- remove legacy markdown spec
- move markdown-it setup into markdown-converter util
- update mobiledoc specs to match markdown-it newline behaviour
- update data-generator HTML to match markdown-it newline behaviour
- fix Post "converts html to plaintext" test
- update rss spec to match markdown-it newline behaviour
- close almost all related showdown bugs
2017-05-15 19:48:14 +03:00
|
|
|
module.exports = {
|
|
|
|
render: function (markdown) {
|
|
|
|
return converter.render(markdown);
|
|
|
|
}
|
|
|
|
};
|