UXInteract / task_008 /solution /code /index.html
DojiSum's picture
Publish the current 141-task UXInteract release
ef987bb verified
Raw History Blame Contribute Delete
2.86 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown Batch Converter</title>
<style>
* { box-sizing: border-box; }
body { font-family: system-ui, sans-serif; margin: 0; background: #f6f8fa; color: #1f2328; }
header { background: #24292f; color: #fff; padding: 16px 24px; }
header h1 { margin: 0; font-size: 20px; }
main { max-width: 880px; margin: 0 auto; padding: 20px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.col { flex: 1; min-width: 300px; }
textarea { width: 100%; height: 220px; padding: 10px; font-family: ui-monospace, monospace;
border: 1px solid #d0d7de; border-radius: 6px; }
.preview { min-height: 220px; background: #fff; border: 1px solid #d0d7de; border-radius: 6px; padding: 12px; }
.toolbar { margin: 12px 0; display: flex; gap: 8px; }
button { padding: 8px 16px; border: none; border-radius: 6px; background: #1f883d; color: #fff; cursor: pointer; }
button.secondary { background: #0969da; }
#status { margin-top: 10px; color: #57606a; }
</style>
</head>
<body>
<header><h1>Markdown Batch Converter (PDF Export)</h1></header>
<main>
<p>Enter Markdown on the left and convert it to see a preview. For command-line batch conversion, use <code>node convert.js samples out</code>.</p>
<div class="row">
<div class="col">
<label for="md">Markdown Input</label>
<textarea id="md">## Example\n\nThe Pythagorean theorem shows that \\(\\sqrt{2}\\) is irrational.</textarea>
</div>
<div class="col">
<label>Preview</label>
<div class="preview" id="preview">The preview will appear here.</div>
</div>
</div>
<div class="toolbar">
<button id="convert">Convert Preview</button>
<button id="export" class="secondary">Export PDF</button>
</div>
<p id="status">Ready.</p>
</main>
<script>
function renderInlineMath(text) {
return text
.replace(/\\\(\\sqrt\{2\}\\\)/g, 'sqrt(2)')
.replace(/\\sqrt\{([^}]+)\}/g, 'sqrt($1)')
.replace(/\\\(|\\\)/g, '');
}
function toHtml(md) {
return renderInlineMath(md)
.replace(/^## (.*)$/gm, '<h2>$1</h2>')
.replace(/\n/g, '<br>');
}
const md = document.getElementById('md');
const preview = document.getElementById('preview');
const status = document.getElementById('status');
document.getElementById('convert').addEventListener('click', () => {
preview.innerHTML = toHtml(md.value);
status.textContent = 'Preview updated.';
});
document.getElementById('export').addEventListener('click', () => {
status.textContent = 'PDF export: use Print to save as PDF in the browser, or run convert.js for batch export.';
});
// initial render
preview.innerHTML = toHtml(md.value);
</script>
</body>
</html>