An open API service indexing awesome lists of open source software.

https://github.com/bluebie/pigeonmark

Superset of JsonML more capable of accurately handling XML and HTML documents
https://github.com/bluebie/pigeonmark

Last synced: 8 months ago
JSON representation

Superset of JsonML more capable of accurately handling XML and HTML documents

Awesome Lists containing this project

README

          

# PigeonMark

This repo contains codecs and specs for PigeonMark, a superset of JsonML encoding, capable of fully representing anything html5 or xml 1.0 encoding can represent, as structured compact data.

Additionally, PigeonMark specifies pigeonmark:arbitrary, an opinionated minimalist standard for encoding JSON-like data structures in to XML. It's also a superset of JSON, with support for undefined, and binary values.

Implementations are available here for NodeJS-like platforms.

## NPM packages

Provided in this repo, some commonjs packages:

- pigeonmark-xml offers encode and decode functions to transform XML strings in to PigeonMark and vice versa
- pigeonmark-html offers encode and decode functions to transform HTML5 strings in to PigeonMark and vice versa
- pigeonmark-utils provides builders, getters and setters to navigate and manipulate PigeonMark DOMs
- pigeonmark-select wraps `css-select`'s powerful css selector engine, allowing css querying of JsonML and PigeonMark documents
- pigeonmark-arbitrary provides encode and decode functions for transforming arbitrary javascript structures in to JsonML structures and vice versa, which can then be xml encoded with pigeonmark-xml or another jsonml codec.

Any assistance with making these packages also work with the modern ES6 modules system would be appreciated.

## Format

PigeonMark implements JsonML encoding at it's core:

- `text` becomes `['tag', 'text']`
- `` becomes `['tag', { attr: 'val' }]`
- `` becomes `['tag', { attr: 'val' }]`
- `text` becomes `['tag', { id: 'foo' }, 'text']`
- `plain text` becomes `'plain text'`

PigeonMark adds extra encoding to represent other aspects of XML and HTML documents:

- `` becomes `['#comment', 'text']`
- `\n` becomes `['#document', { doctype: 'html' }, ['html']]`
- `\n` becomes `['#document', { pi: [['?xml', { version: '1.0' }]] }, ['root']]`
- `` becomes `['#cdata-section', 'text']`
- `

` becomes `['#document-fragment', ['br'], ['br']]`

Where possible these map to WebAPI DOM nodeName properties, to create something like a very lightweight virtual DOM that is easily passed around or stored in any medium that supports JSON strings, objects, and array types.

## pigeonmark:arbitrary encoding

PigeonMark also specifies an XML encoding for arbitrary data, allowing any JSON-like structure to be transformed to XML

- `123` becomes `123`
- `true` becomes ``
- `false` becomes ``
- `null` becomes ``
- `undefined` becomes ``
- `"text"` becomes `text`
- `[true, false, 123]` becomes `123`
- `{ handshape: 5 }` becomes `5`
- `Buffer.from('Hello')` becomes `Hello` (or possibly base64 or hex encoding)
- `new Set([1,2])` becomes `12`
- `new Map([['a', 'b']])` becomes `b`
- `123n` becomes `123`
- `Symbol('foo')` becomes `foo`

The root node of a pigeonmark:arbitrary document must always have the `xmlns` attribute set to `"pigeonmark:arbitrary"`. For example:

```json
{
"name": "Henry",
"age": 45,
}
```

encodes to the PigeonMark structure:

```json
["object", { "xmlns": "pigeonmark:arbitrary" },
["string", { "name": "name" }, "Henry"],
["number", { "name": "age" }, "45"]
]
```

which serializes to XML:

```xml
Henry45
```

GitHub Actions Continuous Integration Status