Skip to content

Commit

Permalink
Merge pull request #1519 from amobiz/fix_more_excerpt
Browse files Browse the repository at this point in the history
Fix more excerpt
  • Loading branch information
tommy351 committed Nov 1, 2015
2 parents c3ba3f6 + 946d3dd commit 85fccb6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/plugins/filter/after_post_render/excerpt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var rExcerpt = /<!-{2,} *more *-{2,}>/;
var rExcerpt = /<!--+\s*more\s*--+>/i;

function excerptFilter(data) {
var content = data.content;
Expand Down
87 changes: 60 additions & 27 deletions test/scripts/filters/excerpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,67 @@ describe('Excerpt', function() {
});

it('with <!-- more -->', function() {
var content = [
'foo',
'bar',
'<!-- more -->',
'baz'
].join('\n');

var data = {
content: content
};

excerpt(data);

data.content.should.eql([
'foo',
'bar',
'<a id="more"></a>',
'baz'
].join('\n'));

data.excerpt.should.eql([
'foo',
'bar'
].join('\n'));

data.more.should.eql([
'baz'
].join('\n'));
_moreCases().forEach(_test);

function _moreCases() {
var template = '<!--{{lead}}more{{tail}}-->';
// see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Special_characters_meaning_in_regular_expressions
var spaces = ' \f\n\r\t\v\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff';
var cases = [];
var more, lead, tail, s, e;

for (var i = 0; i < spaces.length; ++i) {
lead = spaces[i];
for (var k = 0; k < spaces.length; ++k) {
tail = spaces[k];
s = '';
for (var m = 0; m < 3; ++m) {
e = '';
for (var n = 0; n < 3; ++n) {
more = template.replace('{{lead}}', s).replace('{{tail}}', e);
cases.push(more);
e += tail;
}

s += lead;
}
}
}

return cases;
}

function _test(more) {
var content = [
'foo',
'bar',
more,
'baz'
].join('\n');

var data = {
content: content
};

excerpt(data);

data.content.should.eql([
'foo',
'bar',
'<a id="more"></a>',
'baz'
].join('\n'));

data.excerpt.should.eql([
'foo',
'bar'
].join('\n'));

data.more.should.eql([
'baz'
].join('\n'));
}
});

it('multiple <!-- more -->', function() {
Expand Down

0 comments on commit 85fccb6

Please sign in to comment.