{
  "id": "markdown-tool",
  "name": "Markdown-Konverter",
  "version": "1.0.0",
  "type": "agent-tool",
  "author": "Astoris",
  "premium": false,
  "description": "Konvertiert Markdown nach HTML (Mini-Parser) oder strippt es zu sauberem Klartext.",
  "inputHint": "{ \"markdown\": \"# Titel\\n**fett** und *kursiv*\\n- Punkt 1\", \"output\": \"html\" }",
  "code": "async function run(input) {\n  var md = String((input && input.markdown) || '');\n  var output = String((input && input.output) || 'html').toLowerCase();\n  function escapeHtml(s) {\n    return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n  }\n  function inline(s) {\n    s = escapeHtml(s);\n    s = s.replace(/`([^`]+)`/g, '<code>$1</code>');\n    s = s.replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, '<a href=\"$2\">$1</a>');\n    s = s.replace(/\\*\\*([^*]+)\\*\\*/g, '<strong>$1</strong>');\n    s = s.replace(/\\*([^*]+)\\*/g, '<em>$1</em>');\n    return s;\n  }\n  var lines = md.replace(/\\r\\n/g, '\\n').split('\\n');\n  if (output === 'text') {\n    var out = [];\n    for (var i = 0; i < lines.length; i++) {\n      var t = lines[i];\n      t = t.replace(/^\\s{0,3}#{1,6}\\s+/, '');\n      t = t.replace(/^\\s*[-*+]\\s+/, '');\n      t = t.replace(/`([^`]+)`/g, '$1');\n      t = t.replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, '$1');\n      t = t.replace(/\\*\\*([^*]+)\\*\\*/g, '$1');\n      t = t.replace(/\\*([^*]+)\\*/g, '$1');\n      out.push(t);\n    }\n    var text = out.join('\\n').replace(/\\n{3,}/g, '\\n\\n').trim();\n    return { output: 'text', ergebnis: text };\n  }\n  var html = [];\n  var inList = false;\n  var para = [];\n  function flushPara() {\n    if (para.length) { html.push('<p>' + inline(para.join(' ')) + '</p>'); para = []; }\n  }\n  function flushList() {\n    if (inList) { html.push('</ul>'); inList = false; }\n  }\n  for (var j = 0; j < lines.length; j++) {\n    var line = lines[j];\n    var h = line.match(/^\\s{0,3}(#{1,6})\\s+(.*)$/);\n    var li = line.match(/^\\s*[-*+]\\s+(.*)$/);\n    if (h) {\n      flushPara(); flushList();\n      var lvl = h[1].length;\n      html.push('<h' + lvl + '>' + inline(h[2]) + '</h' + lvl + '>');\n    } else if (li) {\n      flushPara();\n      if (!inList) { html.push('<ul>'); inList = true; }\n      html.push('<li>' + inline(li[1]) + '</li>');\n    } else if (line.trim() === '') {\n      flushPara(); flushList();\n    } else {\n      flushList();\n      para.push(line.trim());\n    }\n  }\n  flushPara(); flushList();\n  return { output: 'html', ergebnis: html.join('\\n') };\n}"
}
