codsen-tokenizer
TypeScript icon, indicating that this package has built-in type declarations

7.0.25 • Public • Published

codsen-tokenizer

HTML and CSS lexer aimed at code with fatal errors, accepts mixed coding languages

page on codsen.com page on npm page on github Downloads per month changelog MIT Licence

Install

This package is pure ESM. If you're not ready yet, install an older version of this program, 5.6.0 (npm i codsen-tokenizer@5.6.0).

npm i codsen-tokenizer

Quick Take

import { strict as assert } from "assert";

import { tokenizer } from "codsen-tokenizer";

const gathered = [];

// it operates from a callback, like Array.prototype.forEach()
tokenizer("<td nowrap>", {
  tagCb: (obj) => {
    gathered.push(obj);
  },
});

assert.deepEqual(gathered, [
  {
    type: "tag",
    start: 0,
    end: 11,
    value: "<td nowrap>",
    tagNameStartsAt: 1,
    tagNameEndsAt: 3,
    tagName: "td",
    recognised: true,
    closing: false,
    void: false,
    pureHTML: true,
    kind: null,
    attribs: [
      {
        attribName: "nowrap",
        attribNameRecognised: true,
        attribNameStartsAt: 4,
        attribNameEndsAt: 10,
        attribOpeningQuoteAt: null,
        attribClosingQuoteAt: null,
        attribValueRaw: null,
        attribValue: [],
        attribValueStartsAt: null,
        attribValueEndsAt: null,
        attribStarts: 4,
        attribEnds: 10,
        attribLeft: 2,
      },
    ],
  },
]);

Documentation

Please visit codsen.com for a full description of the API.

Contributing

To report bugs or request features or assistance, raise an issue on GitHub.

Licence

MIT License.

Copyright © 2010-2024 Roy Revelt and other contributors.

ok codsen star

/codsen-tokenizer/

    Package Sidebar

    Install

    npm i codsen-tokenizer

    Weekly Downloads

    22

    Version

    7.0.25

    License

    MIT

    Unpacked Size

    153 kB

    Total Files

    7

    Last publish

    Collaborators

    • royston