htm - convert plain text to HTML 2.0, auto-linked.
Usage
import htm from "htm"
const text = "plain text"
const html = htm(text)
The returned value is a string contaning valid [HTML 2.0].
The first line will be the TITLE and H1 heading.
The remaining part will be enclosed with a PRE element,
with links auto-linked.
Besides HTML 2.0, ISO HTML and HTML5 are also supported.
Below is the type definition in TypeScript:
type htmlVariant = "tags" | "html2" | "iso" | "html5";
const html: (text: string, variant: htmlVariant) => string;
In fact, `htm(text)` is just a shortcut for `html(text, "html2")`.
HTML 2.0 is the first standard of HTML, published in 1995.
ISO HTML, published as an ISO standard in 2000,
is almost identical to HTML 4.01 Strict.
HTML 4.01, published in 1999,
is the most widely adopted standard in the first decade of the 21st century.
HTML5 is the current recommendation by all mainstream web browsers.
It also supports generating HTML tags, the HTML language before 2.0,
which was published in 1991 and is the first publicly available description of HTML.
Auto-link is not supported when specifying this as the output format.
API
See src/index.bs.d.ts
APIs not listed there are considered internal.
Changes to internal APIs are not considered as breaking changes on releases.
Markdown Compatibility
The input is supposed to be plain text.
However, the following Markdown syntax is supported:
- If the first line starts with `# `, then the leading `# ` will be trimmed.
- Inline links (brackets immediately followed with parentheses) will be converted to links,
without displaying the URL.
Contributing
The source code repository is at
https://github.com/weakish/htm
This project is written in ReScript (src/index.res),
with tests written in TypeScript.
"dependencies": {
"linkify-string": "auto link URLs and escape <,>,&"
},
"devDependencies": {
"c8": "coverage",
"gentype": "generate TypeScript type definitions from ReScript",
"husky": "manage git pre commits",
"prettier": "code format",
"pretty-quick": "code format pre-commit",
"reanalyze": "analyze ReScript code for common problems",
"tap": "test"
}
License
0BSD, excluding dependencies that have various licenses.
Reference
- HTML Tags
- [Hypertext Markup Language - 2.0][html 2.0]
- RFC1866
- ISO/IEC 15445:2000
- HTML Validator
[html 2.0]: https://www.w3.org/MarkUp/html-spec/html-spec_toc.html