Skip to content

rylito/dentmark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dentmark

An indentation-delimited, configurable markup language

Syntax Demo: https://www.transvec.com/dentmark

Introduction

Dentmark is an indentation-delimited, configurable markup language. Its syntax is designed to be very simple with minimal special character usage and very easy to learn. The schema is user-defined, meaning that you can customize Dentmark for a variety of tasks.

Render Example

This example demonstrates a user-defined schema and a dentmark file that renders a simple HTML page. The schema itself is defined in dentmark.

demo_repo/demo/demo.schema

container:
    selectors:
        ^

    render:
        doc = html.get_document_container()

        title = html.inline('title', {}, html.text('Demo'))

        doc.head.add_children(title)
        doc.body.add_children(child_results['content'])

        return render('main', doc)

container:
    selectors:
        (p)

    render:
        content = html.block('p', {}, child_results['content'])
        return render('content', content)

container:
    selectors:
        (a)

    render:
        url = data_utils.only_containers(node.data, as_dict=True)['url']
        a = html.inline('a', {'href': url},
            child_results['content'],
            node.pad_before, node.pad_after)
        return render('content', a)


container:
    selectors:
        (a).(url)

    required: True
    many: False


text:
    selectors:
        ^.()
        (p).()
        (a).()

    render:
        return render('content', html.text(clean_text))

text:
    selectors:
        (a).(url).()

    required: True
    many: False

demo_repo/demo/demo.dentmark

_schema: demo/demo.schema

p:
    This is a demo. Here is a

    a: link
        url: https://www.github.com

    that points to github.

demo.py

from dentmark.loaders import FileLoader

loader = FileLoader('demo_repo')
rendered = loader.render('demo/demo.dentmark')['main']
print(rendered)

output

<!DOCTYPE html>
<html>
  <head>
    <title>Demo</title>
  </head>
  <body>
    <p>
      This is a demo. Here is a
      <a href="https://www.github.com">link</a>
      that points to github.
    </p>
  </body>
</html>

Data Example

Dentmark can be used as a data or config format as well. This example demonstrates a user-defined schema and a dentmark file that returns a Python dictionary with scalar and list values.

demo_repo/demo/demo_data.schema

container:
    selectors:
        ^

    data_container_type: dict

str_scalar:
    required_selectors:
        ^.(document_name)

bool_scalar:
    required_selectors:
        ^.(is_published)

container:
    selectors:
        ^.(authors)

    required: True
    many: False

text:
    selectors:
        ^.(authors).()

    required: True
    many: True

demo_repo/demo/demo_data.dentmark

_schema: demo/demo_data.schema

document_name: Demo
is_published: False
authors:
    John
    Sarah

demo_data.py

from dentmark.loaders import FileLoader

loader = FileLoader('demo_repo')

root = loader.get_root('demo/demo_data.dentmark')

print(root.data)

output

>>> {'document_name': 'Demo', 'is_published': False, 'authors': ['John', 'Sarah']}

Syntax

Dentmark is designed to minimize the number of 'special' characters it uses. These are the only ones: ':', '|', '=' (to delimit preformatted blocks) and '#' (for comments). Here's an example of some syntax features and a raw representation of the data structure it generates in a pseudo-code representation.

p: inline

p:
    nested
    content

    |   preserves whitespace

example:

===
This is a preformatted block.
Even though it starts at the left edge of the
document, it is a member of the
previously-defined node.
    whitespace is preserved
===

# this is a comment

p: content # A trailing comment
p: content |# Escaped comment for literal hash symbol

list_of_lists:
    :
        item1
        item2
    :
        item1
        item2

This parses into a tree-like data structure that is then bound to a schema and validated

[p[inline],p[nested,content,   preserves whitespace],example[This is a preformatted block.
Even though it starts at the left edge of the
document, it is a member of the
previously-defined node.
    whitespace is preserved],p[content],p[content # Escaped comment for literal hash symbol],list_of_lists[[item1,item2],[item1,item2]]]

Additional Resources

Full documentation and site coming soon. Work is also progressing on indentgen, a static-site generator that uses Dentmark to generate websites, blogs, and documentation.

About

An indentation-delimited, configurable markup language

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages