/**
* Question Service
* Handles question display and navigation
*/
// Process question content to improve formatting and highlighting
function processQuestionContent(content) {
// First, preserve existing HTML formatting
let processedContent = content;
// Add highlighting to text in single quotes that isn't already styled
processedContent = processedContent.replace(
/`([^`]+)`/g,
function(match, text) {
// Skip if already inside an HTML tag or existing styled element
if (match.match(/<.*>/) ||
match.includes('class="code"') ||
match.includes('class="highlight"')) {
return match;
}
return `${text}`;
}
);
// Style inline code with backticks if not already styled
processedContent = processedContent.replace(
/`([^`]+)`/g,
'$1'
);
// Style bold text
processedContent = processedContent.replace(
/\*\*([^*]+)\*\*/g,
'$1'
);
// Style italic text
processedContent = processedContent.replace(
/\*([^*]+)\*/g,
'$1'
);
// Convert literal newline characters to HTML line breaks
processedContent = processedContent.replace(/\n/g, ' ');
// Ensure paragraphs have proper spacing and line breaks
processedContent = processedContent.replace(
/<\/p>
/g,
'
\n
'
);
// Add more spacing between list items
processedContent = processedContent.replace(
/<\/li>
/g,
'
\n
'
);
return processedContent;
}
// Generate question content HTML
function generateQuestionContent(question) {
try {
// Get original data
const originalData = question.originalData || {};
const machineHostname = originalData.machineHostname || 'N/A';
const namespace = originalData.namespace || 'N/A';
const concepts = originalData.concepts || [];
const conceptsString = concepts.join(', ');
// Format question content with improved styling
const formattedQuestionContent = processQuestionContent(question.content);
// Create formatted content with minimal layout
return `
Solve this question on instance:ssh ${machineHostname}