mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Preserving paragraphs in magazine and grid views.
This commit is contained in:
parent
0e63da2d74
commit
00aabee31a
2 changed files with 10 additions and 8 deletions
|
@ -45,12 +45,14 @@ NEWSBLUR.Models.Story = Backbone.Model.extend({
|
|||
return score_name;
|
||||
},
|
||||
|
||||
content_preview: function(attribute, length) {
|
||||
content_preview: function(attribute, length, preserve_paragraphs) {
|
||||
var content = this.get(attribute);
|
||||
if (!attribute || !content) content = this.story_content();
|
||||
// First do a naive strip, which is faster than rendering which makes network calls
|
||||
content = content && content.replace(/<(?:.|\n)*?>/gm, ' ');
|
||||
content = content && Inflector.stripTags(content);
|
||||
content = content && content.replace(/<p(>| [^>]+>)/ig, '\n\n').replace(/(<([^>]+)>)/ig, ' ')
|
||||
if (preserve_paragraphs) {
|
||||
content = content && _.string.trim(content).replace(/\n{2,}/gm, '<br><br>').replace(/(<br\s*\/?>\s*){3,}/igm, '<br><br>');
|
||||
}
|
||||
content = content && content.replace(/[\u00a0\u200c]/g, ' '); // Invisible space, boo
|
||||
content = content && content.replace(/\s+/gm, ' ');
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ NEWSBLUR.Views.StoryTitleView = Backbone.View.extend({
|
|||
NEWSBLUR.reader.flags.social_view) &&
|
||||
NEWSBLUR.assets.get_feed(this.model.get('story_feed_id')),
|
||||
options : this.options,
|
||||
show_content_preview : this.show_content_preview(),
|
||||
show_content_preview : this.show_content_preview(template_name),
|
||||
show_image_preview : this.show_image_preview()
|
||||
}));
|
||||
this.$st = this.$(".NB-story-title");
|
||||
|
@ -251,15 +251,15 @@ NEWSBLUR.Views.StoryTitleView = Backbone.View.extend({
|
|||
}
|
||||
},
|
||||
|
||||
show_content_preview: function() {
|
||||
show_content_preview: function(template_name) {
|
||||
var preference = NEWSBLUR.assets.preference('show_content_preview');
|
||||
if (!preference) return preference;
|
||||
var max_length = preference == 'small' ? 300 : preference == 'medium' ? 600 : 1000;
|
||||
|
||||
if (this.options.override_layout == 'grid' ||
|
||||
NEWSBLUR.assets.view_setting(NEWSBLUR.reader.active_feed, 'layout') == 'grid') {
|
||||
if (_.contains(['grid_template', 'magazine_template'], template_name)) {
|
||||
max_length = preference == 'small' ? 500 : preference == 'medium' ? 1000 : 1500;
|
||||
return this.model.content_preview('story_content', max_length) || " ";
|
||||
var preserve_paragraphs = true;
|
||||
return this.model.content_preview('story_content', max_length, preserve_paragraphs) || " ";
|
||||
}
|
||||
var pruned_description = this.model.content_preview('story_content', max_length) || " ";
|
||||
var pruned_title = this.model.content_preview('story_title');
|
||||
|
|
Loading…
Add table
Reference in a new issue