File size: 2,859 Bytes
ef987bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!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>