From 7a52ddeba2a68388b544f529d2d92104420f77b0 Mon Sep 17 00:00:00 2001 From: Shipwreckt Date: Fri, 31 Oct 2025 20:02:14 +0000 Subject: Changed from static to 11ty! --- node_modules/posthtml-parser/readme.md | 130 +++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 node_modules/posthtml-parser/readme.md (limited to 'node_modules/posthtml-parser/readme.md') diff --git a/node_modules/posthtml-parser/readme.md b/node_modules/posthtml-parser/readme.md new file mode 100644 index 0000000..5098122 --- /dev/null +++ b/node_modules/posthtml-parser/readme.md @@ -0,0 +1,130 @@ +# posthtml-parser +[![npm version](https://badge.fury.io/js/posthtml-parser.svg)](http://badge.fury.io/js/posthtml-parser) +[![Build Status](https://travis-ci.org/posthtml/posthtml-parser.svg?branch=master)](https://travis-ci.org/posthtml/posthtml-parser?branch=master) +[![Coverage Status](https://coveralls.io/repos/posthtml/posthtml-parser/badge.svg?branch=master)](https://coveralls.io/r/posthtml/posthtml-parser?branch=master) + +Parse HTML/XML to [PostHTML AST](https://github.com/posthtml/posthtml-parser#posthtml-ast-format). +More about [PostHTML](https://github.com/posthtml/posthtml#readme) + +## Install + +[NPM](http://npmjs.com) install +``` +$ npm install posthtml-parser +``` + +## Usage + +#### Input HTML +```html + + Cat + +``` +```js +import { parser } from 'posthtml-parser' +import fs from 'fs' + +const html = fs.readFileSync('path/to/input.html', 'utf-8') + +console.log(parser(html)) // Logs a PostHTML AST +``` + +#### input HTML +```html + + Cat + +``` + +#### Result PostHTMLTree +```js +[{ + tag: 'a', + attrs: { + class: 'animals', + href: '#' + }, + content: [ + '\n ', + { + tag: 'span', + attrs: { + class: 'animals__cat', + style: 'background: url(cat.png)' + }, + content: ['Cat'] + }, + '\n' + ] +}] +``` + +## PostHTML AST Format + +Any parser being used with PostHTML should return a standard PostHTML [Abstract Syntax Tree](https://www.wikiwand.com/en/Abstract_syntax_tree) (AST). Fortunately, this is a very easy format to produce and understand. The AST is an array that can contain strings and objects. Any strings represent plain text content to be written to the output. Any objects represent HTML tags. + +Tag objects generally look something like this: + +```js +{ + tag: 'div', + attrs: { + class: 'foo' + }, + content: ['hello world!'] +} +``` + +Tag objects can contain three keys. The `tag` key takes the name of the tag as the value. This can include custom tags. The optional `attrs` key takes an object with key/value pairs representing the attributes of the html tag. A boolean attribute has an empty string as its value. Finally, the optional `content` key takes an array as its value, which is a PostHTML AST. In this manner, the AST is a tree that should be walked recursively. + +## Options + +### `directives` +Type: `Array` +Default: `[{name: '!doctype', start: '<', end: '>'}]` +Description: *Adds processing of custom directives. Note: The property ```name``` in custom directives can be ```String``` or ```RegExp``` type* + +### `xmlMode` +Type: `Boolean` +Default: `false` +Description: *Indicates whether special tags (`