4,476
edits
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
var showArticleWrapper = $('#show-article-wrapper'); | var showArticleWrapper = $('#show-article-wrapper'); | ||
function formatParagraphs(text) { | |||
var paragraphs = text.split('\n').filter(function (p) { return p.trim() !== '' }); | |||
return paragraphs.map(function (p) { return '<p>' + p.trim() + '</p>'; }).join(''); | |||
} | |||
function formatParagraphs(text) { | function formatParagraphs(text) { | ||
var paragraphs = text.split('\n').filter(function (p) { return p.trim() !== '' }); | var paragraphs = text.split('\n').filter(function (p) { return p.trim() !== '' }); | ||
Line 14: | Line 19: | ||
$('.community-card').each(function() { | $('.community-card').each(function() { | ||
console.log("Processing a community card"); | console.log("Processing a community card"); | ||
// Format paragraphs in community-description | |||
var descriptionContainer = $(this).find('.community-description'); | var descriptionContainer = $(this).find('.community-description'); | ||
var rawDescription = descriptionContainer.text(); | var rawDescription = descriptionContainer.text(); | ||
var formattedDescription = formatParagraphs(rawDescription); | var formattedDescription = formatParagraphs(rawDescription); | ||
descriptionContainer.html(formattedDescription); | descriptionContainer.html(formattedDescription); | ||
// Remove empty | // Remove empty elements in the entire card | ||
$(this).find('*').each(function() { | |||
if ($(this).is(':empty') || $(this).html().trim() === '<br>') { | if ($(this).is(':empty') || $(this).html().trim() === '<br>') { | ||
$(this).remove(); | $(this).remove(); | ||
Line 28: | Line 33: | ||
}); | }); | ||
console.log("Formatted | console.log("Formatted Community Card HTML:", $(this).html()); | ||
}); | }); | ||
} | } | ||
Line 36: | Line 41: | ||
formatCommunityCardDescriptions(); | formatCommunityCardDescriptions(); | ||
} | } | ||
// Delegate the mousedown event to the '.card' elements inside the '#list' container | // Delegate the mousedown event to the '.card' elements inside the '#list' container | ||
$('#list').on('mousedown', '.card', function (event) { | $('#list').on('mousedown', '.card', function (event) { |