From c9069cc234b13c21e9c1e2ef8b775a3045937f66 Mon Sep 17 00:00:00 2001 From: Mikael Brockman Date: Sat, 27 Dec 2014 06:15:21 -0500 Subject: [PATCH] Add reentrant conversion to Showdown footnotes. closes #4668 - inline markup in footnotes now works properly - note that multi-paragraph footnotes are still broken --- .../lib/showdown/extensions/ghostfootnotes.js | 14 +++++++------- core/test/unit/showdown_footnotes_spec.js | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/core/shared/lib/showdown/extensions/ghostfootnotes.js b/core/shared/lib/showdown/extensions/ghostfootnotes.js index f99bd8a992..28a4a083de 100644 --- a/core/shared/lib/showdown/extensions/ghostfootnotes.js +++ b/core/shared/lib/showdown/extensions/ghostfootnotes.js @@ -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, '
'); - + content = converter.makeHtml(content); + content = content.replace(/<\/p>$/, ''); var s = '
  • ' + - '

    ' + content + ' ' + - '

    ' + - '
  • '; + '

    '; if (i === 0) { s = '
      ' + 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) { diff --git a/core/test/unit/showdown_footnotes_spec.js b/core/test/unit/showdown_footnotes_spec.js index 298e86c1fa..7c1bbea641 100644 --- a/core/test/unit/showdown_footnotes_spec.js +++ b/core/test/unit/showdown_footnotes_spec.js @@ -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: /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]',