{
  "name": "HTML heading outline export (Skillaisle)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 10 * * 3"
            }
          ]
        }
      },
      "id": "c6d7e8f9-6006-4000-8000-000000000001",
      "name": "Wednesdays 10:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        40,
        240
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c6d7e8f9-6006-4000-8000-0000000000c1",
              "name": "page_url",
              "value": "https://example.com/help/getting-started",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "c6d7e8f9-6006-4000-8000-000000000002",
      "name": "Page config",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        300,
        240
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.page_url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "text"
            }
          }
        }
      },
      "id": "c6d7e8f9-6006-4000-8000-000000000003",
      "name": "Fetch HTML page",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        560,
        240
      ]
    },
    {
      "parameters": {
        "jsCode": "const cfg = $('Page config').first().json;\nconst raw = String($json.data ?? $json.body ?? '');\nconst pageUrl = String(cfg.page_url || '').trim();\nlet html = raw;\n// drop script/style blocks so heading regex does not see their text\nhtml = html.replace(/<script\\b[^>]*>[\\s\\S]*?<\\/script>/gi, ' ');\nhtml = html.replace(/<style\\b[^>]*>[\\s\\S]*?<\\/style>/gi, ' ');\nhtml = html.replace(/<!--([\\s\\S]*?)-->/g, ' ');\nconst re = /<h([1-6])\\b[^>]*>([\\s\\S]*?)<\\/h\\1>/gi;\nconst outline = [];\nlet m;\nwhile ((m = re.exec(html)) !== null) {\n  const level = Number(m[1]);\n  let text = m[2].replace(/<[^>]+>/g, ' ').replace(/\\s+/g, ' ').trim();\n  if (!text) continue;\n  outline.push({ level, text });\n}\nconst nowIso = new Date().toISOString();\nconst md = ['# Heading outline export', '', `Page: ${pageUrl}`, `Captured: ${nowIso}`, `Headings: ${outline.length}`, ''];\nif (!outline.length) {\n  md.push('No H1\u2013H6 tags found after stripping script/style. Confirm page_url returns HTML (not a JSON API or empty shell).');\n} else {\n  for (const h of outline) {\n    const indent = '  '.repeat(Math.max(0, h.level - 1));\n    md.push(`${indent}- H${h.level}: ${h.text}`);\n  }\n}\nreturn [{ json: { report: md.join('\\n'), heading_count: outline.length, page_url: pageUrl } }];\n"
      },
      "id": "c6d7e8f9-6006-4000-8000-000000000004",
      "name": "Build heading outline",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        820,
        240
      ]
    },
    {
      "parameters": {
        "operation": "toText",
        "sourceProperty": "report",
        "options": {
          "fileName": "heading-outline.md"
        }
      },
      "id": "c6d7e8f9-6006-4000-8000-000000000005",
      "name": "Attach outline file",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        1080,
        240
      ]
    }
  ],
  "connections": {
    "Wednesdays 10:00": {
      "main": [
        [
          {
            "node": "Page config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Page config": {
      "main": [
        [
          {
            "node": "Fetch HTML page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch HTML page": {
      "main": [
        [
          {
            "node": "Build heading outline",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build heading outline": {
      "main": [
        [
          {
            "node": "Attach outline file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
