# tag-parser

> A utility for parsing text markup

Latest version **0.0.4-alpha** (published 2013-02-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install tag-parser
pnpm add tag-parser
yarn add tag-parser
bun add tag-parser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4-alpha |
| Published | 2013-02-05 |
| First published | 2013-01-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Abbey Hawk Sparrow |
| Maintainers | khrome |
| Keywords | tag, parser, markup, html |

## Links

- npm: https://www.npmjs.com/package/tag-parser
- Repository: git@github.com:khrome/tag-parser
- Homepage: https://github.com/khrome/tag-parser
- Issues: https://github.com/khrome/tag-parser/issues
- npm.io page: https://npm.io/package/tag-parser

## Dependencies (2)

- [prime](https://npm.io/package/prime.md) 0.0.5-alpha
- [prime-ext](https://npm.io/package/prime-ext.md) *

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.0.4-alpha (latest) — 2013-02-05
- 0.0.3-alpha — 2013-01-11
- 0.0.2-alpha — 2013-01-09
- 0.0.1-alpha — 2013-01-02

## README

tag-parser.js
==============
An NPM for parsing text markup

TagParser
---------
First include the module:

    var TagParser = require('tag-parser');

then, instantiate the object:

    var parser = new TagParser([environments]);
    
where environments may contain:

1. *name* : 
2. *sentinels* : a list of the following mixed types:
    1. an array of 2 strings, the first being the 'open' sentinel, the second, 'close'.
    2. an object containing 'opener' && 'closer'
    3. a single string that is both the opener and closer
3. *onParse* : a callback allowing you to make custom modifications of an existing tag

parse with:

    var parseTree = parser.parse(text);

HTMLParser
----------
First include the module:

    var HTMLParser = require('tag-parser/html');
    
then, instantiate the object:

    var parser = new HTMLParser();
    
parse with:

    var parseTree = parser.parse('<html><head><title>Awesome!</title></head><body onload="callReady()"><h1>Congrats</h1><p>It worked.</p><!--a comment--></body></html>');
    
which will produce:
    
    {
        type: 'tag',
        text: 'html',
        name: 'html',
        attributes: {},
        children: [
            {
                type: 'tag',
                text: 'head',
                name: 'head',
                attributes: {},
                children: [
                    {
                        type: 'tag',
                        text: 'title',
                        name: 'title',
                        attributes: {},
                        children: [
                            'Awesome!'
                        ]
                    }
                ]
            },
            {
                type: 'tag',
                text: 'body onload="callReady()"',
                name: 'body',
                attributes: {
                    onload : 'callReady()'
                },
                children: [
                    {
                        type: 'tag',
                        text: 'h1',
                        name: 'h1',
                        attributes: {},
                        children: [
                            'Congrats!'
                        ]
                    },
                    {
                        type: 'tag',
                        text: 'p',
                        name: 'p',
                        attributes: {},
                        children: [
                            'It worked.'
                        ]
                    },
                    {
                        type: 'comment',
                        text: 'a comment',
                        children: [
                            'a comment'
                        ]
                    }
                ]
            }
        ]
    }

Testing
-------

Run the tests at the project root with:

    mocha

Enjoy,

-Abbey Hawk Sparrow

---
_Source: https://npm.io/package/tag-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
