mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Merge pull request #4722 from mbrock/master
Add reentrant conversion to Showdown footnotes.
This commit is contained in:
commit
a67b6bcd90
2 changed files with 20 additions and 9 deletions
|
@ -32,7 +32,7 @@ function replaceInlineFootnotes(text) {
|
|||
});
|
||||
}
|
||||
|
||||
function replaceEndFootnotes(text) {
|
||||
function replaceEndFootnotes(text, converter) {
|
||||
// Expanded footnotes at the end e.g. "[^1]: cool stuff"
|
||||
var endRegex = /\[\^(\d|n)\]: ([\s\S]*?)$(?! )/gim,
|
||||
m = text.match(endRegex),
|
||||
|
@ -45,12 +45,12 @@ function replaceEndFootnotes(text) {
|
|||
}
|
||||
|
||||
content = content.replace(/\n /g, '<br>');
|
||||
|
||||
content = converter.makeHtml(content);
|
||||
content = content.replace(/<\/p>$/, '');
|
||||
var s = '<li class="footnote" id="fn:' + n + '">' +
|
||||
'<p>' + content + ' <a href="#fnref:' + n +
|
||||
content + ' <a href="#fnref:' + n +
|
||||
'" title="return to article">↩</a>' +
|
||||
'</p>' +
|
||||
'</li>';
|
||||
'</p></li>';
|
||||
|
||||
if (i === 0) {
|
||||
s = '<div class="footnotes"><ol>' + s;
|
||||
|
@ -66,7 +66,7 @@ function replaceEndFootnotes(text) {
|
|||
}
|
||||
|
||||
(function () {
|
||||
var footnotes = function () {
|
||||
var footnotes = function (converter) {
|
||||
return [
|
||||
{
|
||||
type: 'lang',
|
||||
|
@ -86,7 +86,7 @@ function replaceEndFootnotes(text) {
|
|||
}, 'm');
|
||||
|
||||
text = replaceInlineFootnotes(text);
|
||||
text = replaceEndFootnotes(text);
|
||||
text = replaceEndFootnotes(text, converter);
|
||||
|
||||
// replace extractions
|
||||
text = text.replace(/\{gfm-js-extract-pre-([0-9]+)\}/gm, function (x, y) {
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
var should = require('should'),
|
||||
|
||||
// Stuff we are testing
|
||||
ghostfootnotes = require('../../shared/lib/showdown/extensions/ghostfootnotes');
|
||||
ghostfootnotes = require('../../shared/lib/showdown/extensions/ghostfootnotes'),
|
||||
Showdown = require('showdown-ghost'),
|
||||
converter = new Showdown.converter({extensions: []});
|
||||
|
||||
// To stop jshint complaining
|
||||
should.equal(true, true);
|
||||
|
@ -23,7 +25,7 @@ function _ExecuteExtension(ext, text) {
|
|||
}
|
||||
|
||||
function _ConvertPhrase(testPhrase) {
|
||||
return ghostfootnotes().reduce(function (text, ext) {
|
||||
return ghostfootnotes(converter).reduce(function (text, ext) {
|
||||
return _ExecuteExtension(ext, text);
|
||||
}, testPhrase);
|
||||
}
|
||||
|
@ -60,6 +62,15 @@ describe('Ghost footnotes showdown extension', function () {
|
|||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
|
||||
it('should expand Markdown inside footnotes', function () {
|
||||
var testPhrase = {
|
||||
input: '[^1]: *foo*',
|
||||
output: /<em>foo<\/em>/
|
||||
}, processedMarkup = _ConvertPhrase(testPhrase.input);
|
||||
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
|
||||
it('should number multiple footnotes correctly', function () {
|
||||
var testPhrase = {
|
||||
input: 'foo[^1] bar[^n] etc[^2]',
|
||||
|
|
Loading…
Reference in a new issue