{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Detailed Usage Instructions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Given here is a brief overview. See the ipython notebooks within the `examples` folder within this repository for more detailed usage examples. \n", "\n", "### `Doc` the Document builder\n", "\n", "The `Doc` class from `pydocmaker` is the basic building element for making a report. Here each element will be appended to the end of the document if no `index` or `chapter` is given. Alternatively the chapter to which to append a document part can be specified by `chapter='xxx'`. Furthermore you can also specify the index position (after which part of the document to insert) by adding `index=i` where `i` is `int`. You can use the object like a list.\n", "\n", "\n", "\n", "### Document part schemas\n", "\n", "The basic building blocks for a document are called `document parts` and are always either of type `dict` or type `str` (A string will automatically parsed as a text dict element). \n", "\n", "Each document part has a `typ` field which states the type of document part and a `children` field, which can be either `string` or `list`. This way hirachical documents can be build if needed. \n", "\n", "The `document-parts` are:\n", "- `text`: holds text as string (`children`) which will inserted directly as raw text\n", "- `markdown`: holds text as string (`children`) which will be rendered by markdown markup language before parsing into the documents\n", "- `image`: holds all needed information to render an image in a report. The image data is saved as a string in base64 encoded format in the `imageblob` field. A `caption` (str) can be given which will be inserted below the image. The filename is given by the `children` field. The relative width can be given by the `width` field (float). \n", "- `verbatim`: holds text as string (`children`) which will be inserted as preformatted text into the documents\n", "- `iter`: a meta `document-part` which holds n sub `document-parts` in the `children` field which will be rendered and inserted into the documents in given order. \n", "\n", "An example of the whole schema is given below.\n", "\n", "```json\n", "{\n", " \"text\": {\"typ\": \"text\", \"children\": \"\"},\n", " \"markdown\": {\"typ\": \"markdown\", \"children\": \"\"},\n", " \"image\": {\"typ\": \"image\", \"children\": \"\", \"imageblob\": \"\", \"caption\": \"\", \"width\": 0.8},\n", " \"verbatim\": {\"typ\": \"verbatim\", \"children\": \"\"},\n", " \"iter\": {\"typ\": \"iter\", \"children\": [] }\n", "}\n", "```\n", "\n", "\n", "### Adding document parts to a doc\n", "\n", "Alternatively you can add elements to a document directly using the add and add_kw methods of the document builders:\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pydocmaker as pyd" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "some dummy markdown text!
this text will be shown preformatted!\n", "\n", "
This text will be appended to the first section after the 2nd element (index is zero based!), which is the text (the chapter definition itself is the 1st element!)
This is my fancy markdown text for the Second Chapter
My Markdown text
My preformatted text\n", "\n", "