An indentation-delimited, configurable markup language
Syntax Demo: https://www.transvec.com/dentmark
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.
This example demonstrates a user-defined schema and a dentmark file that renders a simple HTML page. The schema itself is defined in dentmark.
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
_schema: demo/demo.schema
p:
This is a demo. Here is a
a: link
url: https://www.github.com
that points to github.
from dentmark.loaders import FileLoader
loader = FileLoader('demo_repo')
rendered = loader.render('demo/demo.dentmark')['main']
print(rendered)<!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>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.
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
_schema: demo/demo_data.schema
document_name: Demo
is_published: False
authors:
John
Sarah
from dentmark.loaders import FileLoader
loader = FileLoader('demo_repo')
root = loader.get_root('demo/demo_data.dentmark')
print(root.data)>>> {'document_name': 'Demo', 'is_published': False, 'authors': ['John', 'Sarah']}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]]]
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.