{"library":"prescribe","title":"Prescribe HTML Parser","description":"Prescribe is a small, forgiving JavaScript HTML parser that originated from John Resig's parsing code and was hardened through use in Krux's postscribe library. It is currently at version 1.1.3, released in 2017. The project appears to be abandoned, with no active development or maintenance since then, indicating a stalled release cadence. Its key differentiator is its tolerance for real-world, often malformed HTML, particularly in contexts like ad serving, rather than aiming for strict W3C compliance. This makes it suitable for environments where robust error handling of imperfect HTML is preferred over strict validation. It boasts broad browser compatibility, including support for older browsers like Internet Explorer 8+.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install prescribe"],"cli":null},"imports":["import HtmlParser from 'prescribe';","const HtmlParser = require('prescribe');","define(['prescribe'], function(HtmlParser) { /* use HtmlParser */ });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import HtmlParser from 'prescribe';\n\nconst htmlString = `\n  <div>\n    <p>Hello <span>World!</span></p>\n    <!-- This is a comment -->\n    <script>console.log('inline script');</script>\n  </div>\n`;\n\nconst parsedElements = [];\n\nconst parser = new HtmlParser(htmlString, {\n  start: function(tag, attrs, unary) {\n    parsedElements.push({ type: 'start', tag, attrs, unary });\n    // console.log(`Start tag: <${tag}>, Attributes: ${JSON.stringify(attrs)}, Unary: ${unary}`);\n  },\n  end: function(tag) {\n    parsedElements.push({ type: 'end', tag });\n    // console.log(`End tag: </${tag}>`);\n  },\n  chars: function(text) {\n    const trimmedText = text.trim();\n    if (trimmedText.length > 0) {\n      parsedElements.push({ type: 'text', text: trimmedText });\n      // console.log(`Text: \"${trimmedText}\"`);\n    }\n  },\n  comment: function(text) {\n    parsedElements.push({ type: 'comment', text });\n    // console.log(`Comment: <!--${text}-->`);\n  }\n});\n\nparser.parse();\n\nconsole.log('Parsed HTML Structure:');\nparsedElements.forEach(el => console.log(el));\n\n/* Example of expected output for a start tag:\n{\n  \"type\": \"start\",\n  \"tag\": \"p\",\n  \"attrs\": {},\n  \"unary\": false\n}\n*/","lang":"javascript","description":"Demonstrates how to parse an HTML string using Prescribe's SAX-like API, logging the sequence of parsed elements, text, and comments.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}