${featuredImage ? `
` : ''}
${excerpt ? `
${excerpt}
` : ''}
${content.split('\\n').map(para => `
${para.trim()}
`).join('\\n')}
${categories.length ? `
Categories:
${categories.map(cat => `\\n - ${cat}
`).join('')}
` : ''}
${tags.length ? `
Tags:
${tags.map(tag => `\\n - ${tag}
`).join('')}
` : ''}`;
return wpArticle;
} catch (error) {
return 'Error converting XML: ' + error.message;
}
}
// Event Listeners
convertBtn.addEventListener('click', () => {
const wpResult = convertToWordPress(xmlInput.value);
wpOutput.value = wpResult;
});
downloadBtn.addEventListener('click', () => {
const blob = new Blob([wpOutput.value], { type: 'text/html' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'wordpress-article.html';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
});
copyBtn.addEventListener('click', () => {
wpOutput.select();
document.execCommand('copy');
});
clearBtn.addEventListener('click', () => {
wpOutput.value = '';
});
xmlInput.addEventListener('input', () => {
wpOutput.value = '';
});
})();