[mod]
This commit is contained in:
parent
a605e5713d
commit
c51f6d12b0
|
|
@ -1,7 +1,233 @@
|
||||||
{
|
{
|
||||||
|
"definitions": {
|
||||||
|
"doc_object": {
|
||||||
"anyOf": [
|
"anyOf": [
|
||||||
{
|
{
|
||||||
"type": "
|
"type": "object",
|
||||||
|
"reqired": [
|
||||||
|
"kind",
|
||||||
|
"data"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"kind": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["code"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "object",
|
||||||
|
"reqired": [
|
||||||
|
"content"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"content": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"reqired": [
|
||||||
|
"kind",
|
||||||
|
"data"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"kind": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["text"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "object",
|
||||||
|
"reqired": [
|
||||||
|
"content"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"content": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"reqired": [
|
||||||
|
"kind",
|
||||||
|
"data"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"kind": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["link"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "object",
|
||||||
|
"reqired": [
|
||||||
|
"target",
|
||||||
|
"label"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"target": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"label": {
|
||||||
|
"nullable": true,
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"reqired": [
|
||||||
|
"kind",
|
||||||
|
"data"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"kind": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["section"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"title",
|
||||||
|
"content"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"title": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"$ref": "#/definitions/doc_object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"reqired": [
|
||||||
|
"kind",
|
||||||
|
"data"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"kind": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["group"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"members"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"members": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/doc_object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"reqired": [
|
||||||
|
"kind",
|
||||||
|
"data"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"kind": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["list"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"items"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"items": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/doc_object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"reqired": [
|
||||||
|
"kind",
|
||||||
|
"data"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"kind": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["table"]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"head",
|
||||||
|
"rows"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"head": {
|
||||||
|
"nullable": true,
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/doc_object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rows": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/doc_object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"definitions",
|
||||||
|
"content"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"definitions": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"$ref": "#/definitions/doc_object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"title",
|
||||||
|
"main"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"title": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"main": {
|
||||||
|
"$ref": "#/definitions/doc_object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
28
readme.md
Normal file
28
readme.md
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
# docdef
|
||||||
|
|
||||||
|
zum Erzeugen von Dokumenten anhand von JSON-Daten
|
||||||
|
|
||||||
|
|
||||||
|
## Nutzung
|
||||||
|
|
||||||
|
Am beigefügten Beispiel `polyhedra`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
misc/conv misc/examples/polyhedra/transform-default.js misc/examples/polyhedra/data.json | build/sd -o markdown > /tmp/polyhedra-default.md
|
||||||
|
```
|
||||||
|
|
||||||
|
Der erste Teil (vor der Pipe) transformiert die rohen Daten in ein ein JSON-Dokument im `sd`-Dialekt. `build/sd -o markdown` liest dieses Dokument von der Standard-Eingabe und erzeugt die Ausgabe im Markdown-Format.
|
||||||
|
|
||||||
|
Folgende Abwandlungen sind möglich:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Markdown-Tabelle
|
||||||
|
misc/conv misc/examples/polyhedra/transform-table.js misc/examples/polyhedra/data.json | build/sd -o markdown > /tmp/polyhedra-table.md
|
||||||
|
|
||||||
|
# HTML-Liste
|
||||||
|
misc/conv misc/examples/polyhedra/transform-default.js misc/examples/polyhedra/data.json | build/sd -o html > /tmp/polyhedra-default.html
|
||||||
|
|
||||||
|
# HTML-Tabelle
|
||||||
|
misc/conv misc/examples/polyhedra/transform-table.js misc/examples/polyhedra/data.json | build/sd -o html > /tmp/polyhedra-table.html
|
||||||
|
```
|
||||||
|
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
type type_object_group_data = {
|
type type_object_group_data = {
|
||||||
members : type_object;
|
members : Array<
|
||||||
|
type_object
|
||||||
|
>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
type type_object_list_data = {
|
type type_object_list_data = {
|
||||||
items : Array<type_object>;
|
items : Array<
|
||||||
|
type_object
|
||||||
|
>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,18 @@
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
type type_object_table_data = {
|
type type_object_table_data = {
|
||||||
head : (null | Array<type_object>);
|
head : (
|
||||||
rows : Array<Array<type_object>>;
|
null
|
||||||
|
|
|
||||||
|
Array<
|
||||||
|
type_object
|
||||||
|
>
|
||||||
|
);
|
||||||
|
rows : Array<
|
||||||
|
Array<
|
||||||
|
type_object
|
||||||
|
>
|
||||||
|
>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,30 @@ class type_output_html implements type_output<string>
|
||||||
: [new lib_plankton.xml.class_node_text(label)]
|
: [new lib_plankton.xml.class_node_text(label)]
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
"image": ({"url": url, "label": label}) => new lib_plankton.xml.class_node_complex(
|
||||||
|
"img",
|
||||||
|
{
|
||||||
|
"class": "sd-image",
|
||||||
|
"alt": label,
|
||||||
|
"src": url,
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
),
|
||||||
|
"paragraph": ({"content": content}) => new lib_plankton.xml.class_node_complex(
|
||||||
|
"p",
|
||||||
|
{
|
||||||
|
"class": "sd-paragraph",
|
||||||
|
},
|
||||||
|
[
|
||||||
|
this.render_object_internal(
|
||||||
|
content,
|
||||||
|
{
|
||||||
|
"level": options.level,
|
||||||
|
"depth": (options.depth + 1),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
]
|
||||||
|
),
|
||||||
"section": ({"title": title, "content": content}) => new lib_plankton.xml.class_node_complex(
|
"section": ({"title": title, "content": content}) => new lib_plankton.xml.class_node_complex(
|
||||||
"section",
|
"section",
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -48,13 +48,33 @@ class type_output_markdown implements type_output<string>
|
||||||
"label": label,
|
"label": label,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
"image": ({"url": url, "label": label}) => lib_plankton.string.coin(
|
||||||
|
"",
|
||||||
|
{
|
||||||
|
"url": url,
|
||||||
|
"label": label,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
"paragraph": ({"content": content}) => lib_plankton.string.coin(
|
||||||
|
"{{content}}\n\n",
|
||||||
|
{
|
||||||
|
"content": this.render_object_internal(
|
||||||
|
content,
|
||||||
|
{
|
||||||
|
"depth": (options.depth + 1),
|
||||||
|
"headline_level": options.headline_level,
|
||||||
|
"list_level": options.list_level,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
"section": ({"title": title, "content": content}) => lib_plankton.string.coin(
|
"section": ({"title": title, "content": content}) => lib_plankton.string.coin(
|
||||||
"{{head}}\n\n{{body}}\n\n\n",
|
"{{head}}\n\n{{body}}\n\n\n",
|
||||||
{
|
{
|
||||||
"head": lib_plankton.string.coin(
|
"head": lib_plankton.string.coin(
|
||||||
"{{prefix}} {{value}}",
|
"{{prefix}} {{value}}",
|
||||||
{
|
{
|
||||||
"prefix": "#".repeat(options.level + 1),
|
"prefix": "#".repeat(options.headline_level + 1),
|
||||||
"value": title,
|
"value": title,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|
@ -62,7 +82,7 @@ class type_output_markdown implements type_output<string>
|
||||||
content,
|
content,
|
||||||
{
|
{
|
||||||
"depth": (options.depth + 1),
|
"depth": (options.depth + 1),
|
||||||
"headline_level": (options.level + 1),
|
"headline_level": (options.headline_level + 1),
|
||||||
"list_level": options.list_level,
|
"list_level": options.list_level,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|
@ -78,7 +98,7 @@ class type_output_markdown implements type_output<string>
|
||||||
x,
|
x,
|
||||||
{
|
{
|
||||||
"depth": options.depth,
|
"depth": options.depth,
|
||||||
"headline_level": options.level,
|
"headline_level": options.headline_level,
|
||||||
"list_level": options.list_level
|
"list_level": options.list_level
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -103,7 +123,7 @@ class type_output_markdown implements type_output<string>
|
||||||
item,
|
item,
|
||||||
{
|
{
|
||||||
"depth": (options.depth + 1),
|
"depth": (options.depth + 1),
|
||||||
"headline_level": options.level,
|
"headline_level": options.headline_level,
|
||||||
"list_level": (options.list_level + 1),
|
"list_level": (options.list_level + 1),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|
@ -117,8 +137,62 @@ class type_output_markdown implements type_output<string>
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
"table": ({"head": head, "rows": rows}) => lib_plankton.string.coin(
|
"table": ({"head": head, "rows": rows}) => lib_plankton.string.coin(
|
||||||
"(unhandled)",
|
"{{head}}\n{{separation}}\n{{body}}\n\n",
|
||||||
{
|
{
|
||||||
|
"head": lib_plankton.string.coin(
|
||||||
|
"| {{entries}} |",
|
||||||
|
{
|
||||||
|
"entries": (
|
||||||
|
head
|
||||||
|
.map(
|
||||||
|
(object) => this.render_object_internal(
|
||||||
|
object,
|
||||||
|
{
|
||||||
|
"depth": (options.depth + 1),
|
||||||
|
"headline_level": options.headline_level,
|
||||||
|
"list_level": options.list_level,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.join(" | ")
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
"separation": lib_plankton.string.coin(
|
||||||
|
"| {{entries}} |",
|
||||||
|
{
|
||||||
|
"entries": (
|
||||||
|
head
|
||||||
|
.map((object) => "-- ")
|
||||||
|
.join(" | ")
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
"body": (
|
||||||
|
rows
|
||||||
|
.map(
|
||||||
|
row => lib_plankton.string.coin(
|
||||||
|
"| {{entries}} |",
|
||||||
|
{
|
||||||
|
"entries": (
|
||||||
|
row
|
||||||
|
.map(
|
||||||
|
(object) => this.render_object_internal(
|
||||||
|
object,
|
||||||
|
{
|
||||||
|
"depth": (options.depth + 1),
|
||||||
|
"headline_level": options.headline_level,
|
||||||
|
"list_level": options.list_level,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.join(" | ")
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.join("\n")
|
||||||
|
),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue