Skip to content
This repository has been archived by the owner on Feb 25, 2021. It is now read-only.

wegotpop/prt

Repository files navigation

PRT

PRT (POP Rich Text) is a safe, small and strict rich text serialisation protocol which can be used in server - client communication. The protocol is JSON compatible.

Table of Content

PRTv2.0

Protocol

document         ::=   { type_pair, version_pair, dialect_pair, elements_pair }
type_pair        ::=   'type' : 'PRTDocument'
version_pair     ::=   'version' : version_string
version_string   ::=   'unsigned integer.unsigned integer'
dialect_pair     ::=   <optional 'dialect' : string>
elements_pair    ::=   'elements' : elements
elements         ::=   null | text | <sequence of element>
element          ::=   null | text | [ identifier, attributes, elements ]
attributes       ::=   null | { <sequence of attribute_pair> }
attribute_pair   ::=   attribute_name : attribute_value ,
attribute_name   ::=   string
attribute_value  ::=   string
text             ::=   string
identifier       ::=   unsigned integer

Example

The following examples are all in JSON.

  1. This example is the smallest possible PRT document:

    {
        "type": "PRTDocument",
        "version": "2.0",
        "elements": null
    }
  2. The classic hello-world example:

    {
        "type": "PRTDocument",
        "version": "2.0",
        "dialect": "pop",
        "elements":
        [
            [2, {"id": "source"}, [13, null, ["hello, ", [1, null, "world"], "!"]]]
        ]
    }

    And this can be translated to:

    <code id="source"><pre>hello, <b>world</b>!</pre></code>

Reference Implementations

The pop-dialect

Dialect

  • 'dialect': 'pop'

Identifiers

  • 0x00: 'a'
  • 0x01: 'b'
  • 0x02: 'code'
  • 0x03: 'h1'
  • 0x04: 'h2'
  • 0x05: 'h3'
  • 0x06: 'h4'
  • 0x07: 'h5'
  • 0x08: 'h6'
  • 0x09: 'h7'
  • 0x0A: 'i'
  • 0x0B: 'img'
  • 0x0C: 'p'
  • 0x0D: 'pre'
  • 0x0E: 's'
  • 0x0F: 'u'

Attributes

Generic
  • 'id'
  • 'class'
Specific to 0x00
  • 'href'
Specific to 0x0B
  • 'alt'
  • 'src'

PRTv1.0

The initial version was used internally and has never been released to the public.

License

Copyright ©2017 We Got POP Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.