Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

codsen-parser

codsen509MIT0.14.25TypeScript support: included

Parser aiming at broken or mixed code, especially HTML & CSS

ast, css, html, parse, parsing, processing, tokenizer

readme

codsen-parser

Parser aiming at broken or mixed code, especially HTML & CSS

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

Install

This package is pure ESM.

npm i codsen-parser

Quick Take

import { strict as assert } from "assert";

import { cparser } from "codsen-parser";

assert.deepEqual(cparser("<br>z</a>"), [
  {
    type: "tag",
    kind: "inline",
    tagName: "br",
    tagNameStartsAt: 1,
    tagNameEndsAt: 3,
    closing: false,
    void: true,
    pureHTML: true,
    recognised: true,
    start: 0,
    end: 4,
    value: "<br>",
    attribs: [],
    children: [],
  },
  {
    type: "text",
    start: 4,
    end: 5,
    value: "z",
  },
  {
    type: "tag",
    kind: "inline",
    tagName: "a",
    tagNameStartsAt: 7,
    tagNameEndsAt: 8,
    closing: true,
    void: false,
    pureHTML: true,
    recognised: true,
    start: 5,
    end: 9,
    value: "</a>",
    attribs: [],
    children: [],
  },
]);

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

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

0.14.0 (2022-12-01)

BREAKING CHANGES

  • Minimum supported Node version is v14.18; we're dropping v12 support

0.13.0 (2022-08-12)

Features

0.12.17 (2022-04-18)

Fixed

0.12.0 (2021-09-09)

Features

BREAKING CHANGES

  • programs now are in ES Modules and won't work with Common JS require()

0.11.0 (2021-05-24)

Features

  • config file based major bump blacklisting (e15f9bb)

0.10.12 (2021-04-11)

Reverts

  • Revert "chore: setup refresh" (23cf206)

0.10.3 (2021-02-27)

Fixed

  • build against the latest tokenizer, with !important support (66d2b2c)

0.10.1 (2021-02-09)

Fixed

  • correctly nest the broken tag layers (4ad69f6)

0.10.0 (2021-02-07)

Fixed

  • tweak the type definitions, DRY up moving ErrorObj definitions from emlint here (0b07c0a)

Features

  • recognise missing closing tag gaps bigger than one; prepare to revamp rogue tag clauses (1b81b2a)

0.9.1 (2021-01-28)

Fixed

  • add testStats to npmignore (f3c84e9)

0.9.0 (2021-01-23)

Features

  • rewrite in TypeScript, start using named exports, import { cparser } from "codsen-parser";

0.8.0 (2020-11-28)

Accidental version bump during migration to SourceHut. Sorry about that.

0.7.9 (2020-10-19)

Fixed

  • update tests to the latest tokenizer api (5b46ff0)

0.7.0 (2020-05-24)

Features

  • update to the latest tokenizer algorithm (6d92c43)

0.6.5 (2020-05-11)

Fixed

  • nesting fix - closing tags don't next text tokens that follow (de384b5)

0.6.2 (2020-04-26)

Fixed

  • harden the eslint rules set, make all tests pass and rebase a little (40cf4b9)

0.6.0 (2020-04-19)

Features

  • don't nest under rogue opening tags (54e0947)

0.5.0 (2020-04-04)

Fixed

  • tend the layer endings properly (c563d2a)

Features

  • algorithm improvements to tackle cases of rogue tag being in place of another tag (6dde396)
  • don't put tag names that dont have closings into layers (58f528c)
  • first case of missing closing tag, <table><tr><td>x</td></tr> (ce439f0)
  • improve the algorithm to recognise missing closing tag (c56363f)
  • push all kinds of opening tokens into layers, not just comment-type (2dc552d)

0.4.0 (2020-03-24)

Fixed

  • correctly nest empty tags (380c268)

Features

  • new error rule, tag-void-frontal-slash (6a93052)

0.3.0 (2020-03-16)

Features

  • catch even more broken closing comment cases (edf1bae)
  • improve the comment tag recognition, also broken "->" recognition (49a2ddc)
  • recognise malformed front part of "not" kind comment in preceding text token (b388754)
  • recognise malformed opening comment tag's first part within nested preceding token (71092b6)

0.2.0 (2020-02-24)

Fixed

  • missing tag opening rule - demand that closing tag's previous tag would be not closing (ceff20b)
  • nested tags (5846347)

Features

  • empty tag pair, one opening one closing tag (47b212d)
  • extend missing closing tag rules to comment tags (50996e5)
  • nest commment tags how it should be done (5f132a4)
  • update to the tokenizer's latest api (29134fa)

0.1.0 (2020-02-09)

Features

  • algorithm improvements for broken tag pairs (0a65546)
  • assembles AST of nested tags (2a85a06)
  • init (310c617)
  • new error, tag-missing-opening (a24adae)
  • rewire tokenizer results to both feed the program and the callbacks in the opts (e090822)

Change Log

0.0.1 (2020-02-02)

  • First public release.