1.0.24 • Published 4 years ago

postlang v1.0.24

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

PostLang

PostLang is a component based markup language. It can be converted into HTML. Currently, the package only contains the parser, so anyone can write their own renderer. To use this package, you have to make sure that NodeJS is installed on your machine.

You can try out the language on this page: https://johetajava.hu/postlang-demo/

Language Specification

Components

Like in html, you can write components that have arguments and body. In postlang the body is also called 'content'. Here is an example of a normal tag:

task(title="Exercise 3." solution="6") {
    "The answer is 3!"
}

It has 2 attributes: title and solution. The values of each attribute must be "between two quotation marks". The attributes are either separated by a comma or a whitespace character (\n, space, \t) If the tag doesn't require a body, you don't have to write {""}:

video(source="https://www.youtube.com/watch?v=UfDFTCIZfEg" autoplay="true")

If you don't need arguments:

paragraph {
    "Lorem ipsum dolor sit amet."
}

Or if you don't need any of them:

br

The Content of an element

The Content of an element can be either An element:

outerElement {
    innerElement {
        "Inner element content"
    }
}

A string between quotation marks:

outerElement {
    "String content"
}

a list of Contents

list(orderType="numbers") {
    [
        "This is the first element",
        video(source="kMYp-c2pbZw" type="youtube"),
        list(orderType="letters") {
            [
                "This is a list inside a list."
            ]
        }
    ]
}

API

Importing:

const postlang = require("postlang");

Parsing code:

postlang.parseCode("code...");

It returns a list of components in the code:

interface Component {
    componentName: string;
    attributes: Attributes;
    content: Content;
};

type Attributes = { [key: string]: any }

type Content = string | Component | Content[] | null

Here is an example output of the parser:

[
    {
        "componentName": "heading",
        "attributes": {
            "level": "1"
        },
        "content": "Title 1"
    },
    {
        "componentName": "list",
        "attributes": {
            "orderType": "numbers"
        },
        "content": [
            "This is the first item.",
            "This is the second item",
            {
                "componentName": "video",
                "attributes": {
                    "type": "youtube",
                    "source": "kMYp-c2pbZw"
                },
                "content": null
            }
        ]
    },
    {
        "attributes": {},
        "componentName": "hr",
        "content": null
    }
]
1.0.22

4 years ago

1.0.21

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.19

4 years ago

1.0.20

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago