Skip to content

BjornRuud/HTMLLexer

Repository files navigation

HTMLLexer

A lexer (or tokenizer) to parse a string containing HTML elements into tokens representing the order of the various elements. It is written in Swift and depends on swift-parsing.

Note that this is not a full HTML parser and it performs no validation. This means it will not check if the HTML structure is valid or that the content of the HTML elements are valid, but it will check if the structure of the parsed HTML elements is valid according to the HTML syntax specification. Elements that could not be parsed are output as text.

The typical use-case for this library is strings using HTML for formatting where full control of the processing and rendering is required.

Example: The string "A <b>bold</b> move" will output

[
  .text("A "),
  .tagStart(name: "b", attributes: [], isSelfClosing: false),
  .text("bold"),
  .tagEnd(name: "b"),
  .text(" move")
]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published