|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const postBodies = document.querySelectorAll('.postbody');
|
|
|
|
postBodies.forEach(postBody => {
|
|
if (postBody) {
|
|
let html = postBody.innerHTML;
|
|
|
|
|
|
|
|
html = html.replace(/\*\*(.*?)\*\*/gs, '<strong>$1</strong>');
|
|
|
|
|
|
const lines = html.split(/<br\s*\/?>/i);
|
|
const processedLines = [];
|
|
let inList = false;
|
|
|
|
lines.forEach(line => {
|
|
const originalLine = line;
|
|
|
|
|
|
const nestedMatch = originalLine.match(/^((?: |\s){4,})(.*)/);
|
|
const topLevelMatch = !nestedMatch ? originalLine.match(/^((?: |\s){2,})(.*)/) : null;
|
|
|
|
if (nestedMatch) {
|
|
|
|
const potentialContentNested = nestedMatch[2].trimStart();
|
|
if (potentialContentNested.startsWith('<img') || potentialContentNested.startsWith('<font') || potentialContentNested.startsWith('<a href')) {
|
|
processedLines.push(originalLine);
|
|
inList = false;
|
|
} else {
|
|
|
|
let content = nestedMatch[2].replace(/^\*\s*(?: |\s)?/, '').trim();
|
|
if (content) {
|
|
processedLines.push(`<span class="md-list-item md-list-item-nested">${content}</span>`);
|
|
inList = true;
|
|
} else if (inList) {
|
|
processedLines.push('');
|
|
inList = false;
|
|
} else {
|
|
processedLines.push(originalLine);
|
|
}
|
|
}
|
|
} else if (topLevelMatch) {
|
|
|
|
const potentialContentTop = topLevelMatch[2].trimStart();
|
|
if (potentialContentTop.startsWith('<img') || potentialContentTop.startsWith('<font') || potentialContentTop.startsWith('<a href')) {
|
|
processedLines.push(originalLine);
|
|
inList = false;
|
|
} else {
|
|
|
|
let content = topLevelMatch[2].replace(/^\*\s*(?: |\s)?/, '').trim();
|
|
if (content) {
|
|
processedLines.push(`<span class="md-list-item">${content}</span>`);
|
|
inList = true;
|
|
} else if (inList) {
|
|
processedLines.push('');
|
|
inList = false;
|
|
} else {
|
|
processedLines.push(originalLine);
|
|
}
|
|
}
|
|
} else {
|
|
|
|
const trimmedLine = originalLine.trim();
|
|
if (trimmedLine === '' && inList) {
|
|
processedLines.push('');
|
|
inList = false;
|
|
} else if (trimmedLine !== '') {
|
|
processedLines.push(originalLine);
|
|
inList = false;
|
|
} else {
|
|
|
|
if (!inList) {
|
|
processedLines.push(originalLine);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
html = processedLines.join('<br />');
|
|
|
|
|
|
|
|
html = html.replace(/(?<!\*)\*(?!\*|\s)(.*?)(?<!\s|\*)\*(?!\*)/gs, '<em>$1</em>');
|
|
|
|
|
|
html = html.replace(/<span class="md-list-item">\s*<\/span>/g, '');
|
|
html = html.replace(/<span class="md-list-item md-list-item-nested">\s*<\/span>/g, '');
|
|
|
|
|
|
postBody.innerHTML = html;
|
|
}
|
|
});
|
|
}); |