mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fix footnote handling for n-digit numbers
fixes #4815 - Fix regex - Add new test
This commit is contained in:
parent
75ef56e91b
commit
90ac1fdd16
2 changed files with 11 additions and 2 deletions
|
@ -15,7 +15,7 @@
|
|||
|
||||
function replaceInlineFootnotes(text) {
|
||||
// Inline footnotes e.g. "foo[^1]"
|
||||
var inlineRegex = /(?!^)\[\^(\d|n)\]/gim,
|
||||
var inlineRegex = /(?!^)\[\^(\d+|n)\]/gim,
|
||||
i = 0;
|
||||
|
||||
return text.replace(inlineRegex, function (match, n) {
|
||||
|
@ -34,7 +34,7 @@ function replaceInlineFootnotes(text) {
|
|||
|
||||
function replaceEndFootnotes(text, converter) {
|
||||
// Expanded footnotes at the end e.g. "[^1]: cool stuff"
|
||||
var endRegex = /\[\^(\d|n)\]: ([\s\S]*?)$(?! )/gim,
|
||||
var endRegex = /\[\^(\d+|n)\]: ([\s\S]*?)$(?! )/gim,
|
||||
m = text.match(endRegex),
|
||||
total = m ? m.length : 0,
|
||||
i = 0;
|
||||
|
|
|
@ -53,6 +53,15 @@ describe('Ghost footnotes showdown extension', function () {
|
|||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
|
||||
it('should handle n-digit footnotes', function () {
|
||||
var testPhrase = {
|
||||
input: 'foo_bar[^42]',
|
||||
output: /<sup id="fnref:42"><a href="#fn:42" rel="footnote">42<\/a><\/sup>/
|
||||
}, processedMarkup = _ConvertPhrase(testPhrase.input);
|
||||
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
|
||||
it('should replace end footnotes with the right html', function () {
|
||||
var testPhrase = {
|
||||
input: '[^1]: foo bar',
|
||||
|
|
Loading…
Add table
Reference in a new issue