From 738579d7fc35b16b3938573f2dc6a86f37c547da Mon Sep 17 00:00:00 2001 From: dennisgunia Date: Tue, 2 Feb 2021 23:12:52 +0100 Subject: [PATCH] init --- outfile.info | 59 +++++ primalmarkup-lang/.vscode/launch.json | 17 ++ primalmarkup-lang/.vscodeignore | 4 + primalmarkup-lang/CHANGELOG.md | 9 + primalmarkup-lang/README.md | 65 +++++ primalmarkup-lang/language-configuration.json | 22 ++ primalmarkup-lang/package.json | 25 ++ .../syntaxes/pms.tmLanguage.json | 79 ++++++ primalmarkup-lang/vsc-extension-quickstart.md | 29 +++ readme.md | 148 +++++++++++ src/__pycache__/render.cpython-37.pyc | Bin 0 -> 1846 bytes src/main.py | 229 ++++++++++++++++++ src/render.py | 51 ++++ test/test.info | 59 +++++ test/test.info.tmp | 48 ++++ test/test.pms | 38 +++ 16 files changed, 882 insertions(+) create mode 100644 outfile.info create mode 100644 primalmarkup-lang/.vscode/launch.json create mode 100644 primalmarkup-lang/.vscodeignore create mode 100644 primalmarkup-lang/CHANGELOG.md create mode 100644 primalmarkup-lang/README.md create mode 100644 primalmarkup-lang/language-configuration.json create mode 100644 primalmarkup-lang/package.json create mode 100644 primalmarkup-lang/syntaxes/pms.tmLanguage.json create mode 100644 primalmarkup-lang/vsc-extension-quickstart.md create mode 100644 readme.md create mode 100644 src/__pycache__/render.cpython-37.pyc create mode 100644 src/main.py create mode 100644 src/render.py create mode 100644 test/test.info create mode 100644 test/test.info.tmp create mode 100644 test/test.pms diff --git a/outfile.info b/outfile.info new file mode 100644 index 0000000..a758316 --- /dev/null +++ b/outfile.info @@ -0,0 +1,59 @@ +################################################################################ + _ _ _ _ + / \ _ __ ___(_) |__ | | ___ + / _ \ | '_ \/ __| | '_ \| |/ _ \ + / ___ \| | | \__ \ | |_) | | __/ +/_/ \_\_| |_|___/_|_.__/|_|\___| + +Title : Testdokument +Author : Dennis Gunia + +################################################################################ + +Inhalt: +======= + +1. Kapitel1 +----------- + 1.1 Hier gehts weiter + 1.2 Hier gehts weiter Pt. 2 + +2. Kapitel2 +----------- + +3. Kapitel3 +----------- + 3.1 Hier gehts weiter Pt. 2 + + +################################################################################ + +1. Kapitel1 +=========== +Dies ist ein Testdokument + + 1.1 Hier gehts weiter + --------------------- +Wenn der Kühler friert, der Keilriemen durchhängt und Schläuche nicht ganz dicht sind, +kann es dem Motor ganz schön heiß werden. Damit Ihnen Ihr Motor bei Kälte keine Kopfschmerzen bereitet, +sollten Sie Ihr Kühlsystem zum günstigen Komplett-Preis durchchecken lassen. +Ihr Opel-Händler nimmt dabei alle Kühlmittel- und Heizungsschläuche, den Kühler samt ... + + 1.2 Hier gehts weiter Pt. 2 + --------------------------- +ur wer seinen Visionen vertraut, kann die Wirklichkeit verändern. Denn Visionen sind es, die uns weiterbringen. +Visionen sind es, die uns und unseren Kunden zu einem wirklichen Wettbewerbsvorsprung verhelfen und neue Perspektiven erschließen. + + +2. Kapitel2 +=========== +Dies ist ein Testdokument + + +3. Kapitel3 +=========== +Dies ist ein Testdokument + + 3.1 Hier gehts weiter Pt. 2 + --------------------------- +wieso? diff --git a/primalmarkup-lang/.vscode/launch.json b/primalmarkup-lang/.vscode/launch.json new file mode 100644 index 0000000..0e191b5 --- /dev/null +++ b/primalmarkup-lang/.vscode/launch.json @@ -0,0 +1,17 @@ +// A launch configuration that launches the extension inside a new window +// Use IntelliSense to learn about possible attributes. +// Hover to view descriptions of existing attributes. +// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Extension", + "type": "extensionHost", + "request": "launch", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}" + ] + } + ] +} \ No newline at end of file diff --git a/primalmarkup-lang/.vscodeignore b/primalmarkup-lang/.vscodeignore new file mode 100644 index 0000000..f369b5e --- /dev/null +++ b/primalmarkup-lang/.vscodeignore @@ -0,0 +1,4 @@ +.vscode/** +.vscode-test/** +.gitignore +vsc-extension-quickstart.md diff --git a/primalmarkup-lang/CHANGELOG.md b/primalmarkup-lang/CHANGELOG.md new file mode 100644 index 0000000..f6dfa73 --- /dev/null +++ b/primalmarkup-lang/CHANGELOG.md @@ -0,0 +1,9 @@ +# Change Log + +All notable changes to the "primalmarkup-lang" extension will be documented in this file. + +Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. + +## [Unreleased] + +- Initial release \ No newline at end of file diff --git a/primalmarkup-lang/README.md b/primalmarkup-lang/README.md new file mode 100644 index 0000000..c77d0fc --- /dev/null +++ b/primalmarkup-lang/README.md @@ -0,0 +1,65 @@ +# primalmarkup-lang README + +This is the README for your extension "primalmarkup-lang". After writing up a brief description, we recommend including the following sections. + +## Features + +Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file. + +For example if there is an image subfolder under your extension project workspace: + +\!\[feature X\]\(images/feature-x.png\) + +> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow. + +## Requirements + +If you have any requirements or dependencies, add a section describing those and how to install and configure them. + +## Extension Settings + +Include if your extension adds any VS Code settings through the `contributes.configuration` extension point. + +For example: + +This extension contributes the following settings: + +* `myExtension.enable`: enable/disable this extension +* `myExtension.thing`: set to `blah` to do something + +## Known Issues + +Calling out known issues can help limit users opening duplicate issues against your extension. + +## Release Notes + +Users appreciate release notes as you update your extension. + +### 1.0.0 + +Initial release of ... + +### 1.0.1 + +Fixed issue #. + +### 1.1.0 + +Added features X, Y, and Z. + +----------------------------------------------------------------------------------------------------------- + +## Working with Markdown + +**Note:** You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts: + +* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux) +* Toggle preview (`Shift+CMD+V` on macOS or `Shift+Ctrl+V` on Windows and Linux) +* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (macOS) to see a list of Markdown snippets + +### For more information + +* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown) +* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/) + +**Enjoy!** diff --git a/primalmarkup-lang/language-configuration.json b/primalmarkup-lang/language-configuration.json new file mode 100644 index 0000000..00f4b47 --- /dev/null +++ b/primalmarkup-lang/language-configuration.json @@ -0,0 +1,22 @@ +{ + "comments": { + // symbol used for single line comment. Remove this entry if your language does not support line comments + "lineComment": "%%", + + }, + // symbols used as brackets + "brackets": [ + ["{{", "}}"], + ["[[", "]]"] + ], + // symbols that are auto closed when typing + "autoClosingPairs": [ + ["{{", "}}"], + ["[[", "]]"] + ], + // symbols that can be used to surround a selection + "surroundingPairs": [ + ["{{", "}}"], + ["[[", "]]"] + ] +} \ No newline at end of file diff --git a/primalmarkup-lang/package.json b/primalmarkup-lang/package.json new file mode 100644 index 0000000..6792751 --- /dev/null +++ b/primalmarkup-lang/package.json @@ -0,0 +1,25 @@ +{ + "name": "primalmarkup-lang", + "displayName": "primalmarkup-lang", + "description": "PrimalMarkup Language Syntax", + "version": "0.0.1", + "engines": { + "vscode": "^1.52.0" + }, + "categories": [ + "Programming Languages" + ], + "contributes": { + "languages": [{ + "id": "pms", + "aliases": ["PrimalMarkupScript", "pms"], + "extensions": [".pml",".pms",".pmc1",".pmc2",".pml"], + "configuration": "./language-configuration.json" + }], + "grammars": [{ + "language": "pms", + "scopeName": "pm", + "path": "./syntaxes/pms.tmLanguage.json" + }] + } +} \ No newline at end of file diff --git a/primalmarkup-lang/syntaxes/pms.tmLanguage.json b/primalmarkup-lang/syntaxes/pms.tmLanguage.json new file mode 100644 index 0000000..b8b8d61 --- /dev/null +++ b/primalmarkup-lang/syntaxes/pms.tmLanguage.json @@ -0,0 +1,79 @@ +{ + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "PrimalMarkupScript", + "patterns": [ + { + "include": "#object" + }, + { + "include": "#comments" + }, + { + "include": "#metatag" + } + ], + "repository": { + "object": { + "patterns": [ + { + "match": "^\\[\\[([\\w\\d._]*)\\=([\\w\\d\\-\\\":;,._$%&\/\\\\ ]*)\\]\\]$", + "captures": { + "0":{ + "name": "support.type.exception.python" + }, + "1": { + "name": "support.type.property-name.json" + }, + "2": { + "name": "string.quoted.double.json" + } + }, + "name": "punctuation.definition.string.end.json" + }, + { + "match": "^\\{\\{([\\w\\d._]*)\\=([\\w\\d\\-\\\":;,._$%&\/\\\\ ]*)\\}\\}$", + "captures": { + "0":{ + "name": "support.type.exception.python" + }, + "1": { + "name": "keyword.control.flow.python" + }, + "2": { + "name": "string.quoted.double.json" + }, + "3": { + "name": "comment.block.empty.java" + } + }, + "name": "punctuation.definition.string.end.json" + }, + { + "match": "^\\{\\{([\\w\\d._]*)\\}\\}$", + "captures": { + "0":{ + "name": "support.type.exception.python" + }, + "1": { + "name": "keyword.control.flow.python" + } + }, + "name": "punctuation.definition.string.end.json" + } + ] + }, + "comments": { + "patterns": [{ + "name": "comment.line.as", + "match": "(\\%\\%).*$\\n?", + "captures": { + "1": { + "name": "comment.line.double-slash.js" + } + } + }] + } + + }, + "scopeName": "pm" +} \ No newline at end of file diff --git a/primalmarkup-lang/vsc-extension-quickstart.md b/primalmarkup-lang/vsc-extension-quickstart.md new file mode 100644 index 0000000..8159b45 --- /dev/null +++ b/primalmarkup-lang/vsc-extension-quickstart.md @@ -0,0 +1,29 @@ +# Welcome to your VS Code Extension + +## What's in the folder + +* This folder contains all of the files necessary for your extension. +* `package.json` - this is the manifest file in which you declare your language support and define the location of the grammar file that has been copied into your extension. +* `syntaxes/pms.tmLanguage.json` - this is the Text mate grammar file that is used for tokenization. +* `language-configuration.json` - this is the language configuration, defining the tokens that are used for comments and brackets. + +## Get up and running straight away + +* Make sure the language configuration settings in `language-configuration.json` are accurate. +* Press `F5` to open a new window with your extension loaded. +* Create a new file with a file name suffix matching your language. +* Verify that syntax highlighting works and that the language configuration settings are working. + +## Make changes + +* You can relaunch the extension from the debug toolbar after making changes to the files listed above. +* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. + +## Add more language features + +* To add features such as intellisense, hovers and validators check out the VS Code extenders documentation at https://code.visualstudio.com/docs + +## Install your extension + +* To start using your extension with Visual Studio Code copy it into the `/.vscode/extensions` folder and restart Code. +* To share your extension with the world, read on https://code.visualstudio.com/docs about publishing an extension. diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..65aa550 --- /dev/null +++ b/readme.md @@ -0,0 +1,148 @@ + ____ _ _ __ __ _ + | _ \ _ __(_)_ __ ___ __ _| | \/ | __ _ _ __| | ___ _ _ __ + | |_) | '__| | '_ ` _ \ / _` | | |\/| |/ _` | '__| |/ / | | | '_ \ + | __/| | | | | | | | | (_| | | | | | (_| | | | <| |_| | |_) | + |_| |_| |_|_| |_| |_|\__,_|_|_| |_|\__,_|_| |_|\_\\__,_| .__/ + |_| +# PrimalMarkup + +The name already implies everything. PrimalMarkup is probably the worst Markup-Language out there. Please do yourself a favor and don't look at the source-code. This project has been done in a hurry! + +PrimalMarkupScript was originally designed to easily add a content table and chapter-numbers to text files. This is achieved by 'compiling' .pms (Primal-Markup-Script-File) into plain text files. Chapter-numbering and indentation as well as generating the table of contents is handled by the compiler. + +As of now, the compiler supports two levels of headlines. + +# Files + +PrimalMarkupScript uses the .pms extension for its sourcefiles. The Repository also contains the complementary VS-Code plugin for syntax highlighting. +Temporary files are created in /tmp and have the suffix .pmc1 + +## Syntax + +The PrimalMarkupScript-Language conatins three basic elements: + + - Comments (of course...) + - Metadata Tags + - Content-Tags + + ### Comments + Comments are single-lined and start with `%% `. Inline Comments are not supported. + It is recommended to remove any preceding white-spaces to avoid bugs. + +### Metadata Tags +Metadata Tags set options for the current scope. Right now,there is only one scope available: + + - Document + + All Meta-Tags for the Document-Scope have to be at the beginning of the file. + The snytax is: `[[gmu.\=\]]` + Valid values are: +|Option|Default|Function|Required| +|--|--|--|--| +| defaultWidth | 80 | Width of the seperator | no | +| spacerChar | '#' | Char used for generating the seperators | no | +| indentation | '\\t' | Char/String used to indent the sub-chapters | no | +| title | | Document title | yes | +| shorttitle | | Short title for generating the ASCII-Art | no | +| author | | Document author | yes | + +Example: + + [[gmu.title=Testdokument]] + [[gmu.shorttitle=Ansible]] + [[gmu.author=Dennis Gunia]] + %% Dies ist ein Kommentar. Einfach ignorieren .... + +### Content Tags +Metadata Tags are substituted by the compiler. + The snytax is: `{{gmu.\(=\)}}` + Value is only required by section and subsection. + + Valid values are: + + + - header + - contents + - seperator + - section + - subsection +#### header +The **header** generates an ASCII-Art banner with the author and title. +Example: + + {{gmu.header}} + + Output: + + + _ _ _ _ + / \ _ __ ___(_) |__ | | ___ + / _ \ | '_ \/ __| | '_ \| |/ _ \ + / ___ \| | | \__ \ | |_) | | __/ + /_/ \_\_| |_|___/_|_.__/|_|\___| + + Title : Testdokument + Author : Dennis Gunia + +The ASCII-Text is defined by `gmu.shorttitle`, the Title is defined by `gmu.title` and the Author is defined by `gmu.author`. + +#### contents +The content-tag is replaced with the generated table of contents +Example: + + {{gmu.contents}} + + Output: + + 1. Kapitel1 + ----------- + 1.1 Hier gehts weiter + 1.2 Hier gehts weiter Pt. 2 + + 2. Kapitel2 + ----------- + + 3. Kapitel3 + ----------- + 3.1 Hier gehts weiter Pt. 2 + +#### seperator +The seperator generates a bar with the symbol specified in `gmu.spacerChar` and a width of `gmu.defaultWidth`. + +Example: + + {{gmu.seperator}} + + Output: + + + ################################################################################ + +#### section +The section tag generates a new chapter and automatically assigns a chapter number. + +Example: + + {{gmu.section=Kapitel1}} + +Output: + + 1. Kapitel1 + =========== + +#### subsection +The subsection tag generates a new sub-chapter and automatically assigns a sub-chapter number. + +Example: + + {{gmu.subsection=Hier gehts weiter}} + +Output: + + 1.1 Hier gehts weiter + --------------------- +## Prerequisite + + python3.7 -m pip install pyfiglet + + diff --git a/src/__pycache__/render.cpython-37.pyc b/src/__pycache__/render.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..177384557fa4b1ac7f3b585be253cdb74966763c GIT binary patch literal 1846 zcmZXUPj4eN7{+bS-%S3rgl=gU4h2p@yA4N#$_i)?9F|~GJg+m!X1kMk?6Ezb_xZh#{bREkFK zzDLQAaFa~(5$iK4r1K~1bLmPCwUE9HP&+b|HPo(*WF5698?uSom;97kTs}$Gch48R>i75AYf7^?Di%gGW({ajZ zqO*z8CQ*4=%ckbk=p?-?dGdzoI#z$^cCWIr>PnTSNq#v^lel}Cn67R89P8hwlWwku zU9D27^x@>T+*&qI6_$-nrb%)h;>Nfu_V}LAO|;iUh_#1eiM&9=FsKF>un^D;KGL}t zmIL*H4{-pScYPI`ii`bXKgzE%ZA@ZDYPLNuUQy%V;NV*nQ1O-n?RgRXFg2LD8j1RT zY&*avoZMa{mm_8R&1HSQ#HQgF))AUS^&4?MOp^0KoTf@!WXoFvgJomM;wKdY4&kgo zwD}HxdK*1M0zj9GvIg-C53q)~`GTxrV1qkuZLwWA76SXN+(IpGGe#y=eOfQHiE`+Hbr-hUZH*PIPgd#eX$|ee1zdu{t)yw*KPE?7xvoG zUtvV@dxrcWcMDD-B6xAfZP*Ca2QKZRM&Bxq+4ILT=cbg^)WhAXtBlRm=8T^>nZj zUZZUb>6k-Xr>rN~S*eMM$^(C1;m}Vo_5lvPOT8rRF@Yx)f%SJRgwHUug0M>v=y?r+ z0IVVWg9mHKzZV>*(;tPia45%x3p=s}a$4<75Bc_xZy!69PqiIlHv{Y7Akwv+Ed0l#d_T4*iPE`mfbG)#0rnbnVgQ)3zD5vS17_T^zrjT?| {}".format(lineContent)) + print (" ===> {}".format(errorMessage)) + exit(1) + +def processLine(lineNumber, lineContent, tempFile): + #print("[DEBUG] Line{}: {}".format(lineNumber, lineContent)) + + if len(lineContent) > 8: + + if lineContent[0:6] == "[[gmu.": + # found meta-tag + # pares tag + tagData = metatagRegEx.match(lineContent) + + if not tagData: + abortParseError(lineNumber, lineContent, "Cannot parse meta-tag") + + gmuSettings_global[currentScope][tagData.group(1)[4:]] = tagData.group(2) + return + + + if lineContent[0:6] == "{{gmu.": + # found content-tag + tagData = contenttagRegEx.match(lineContent) + + if not tagData: + abortParseError(lineNumber, lineContent, "Cannot parse content-tag") + + tagType = tagData.group(1)[4:] + + if tagType == 'header': + tempFile.write(renderHeader(gmuSettings_global) + '\n') + return + if tagType == 'seperator': + tempFile.write(renderSeperator(gmuSettings_global) + '\n') + return + if tagType == 'section': + gmuSettings_global['counter_section'] += 1 + gmuSettings_global['counter_subsection'] = 0 + + content.append({ + 'title': tagData.group(3), + 'number': gmuSettings_global['counter_section'], + 'subsections': [] + }) + + tempFile.write(renderSectionTitle(gmuSettings_global, tagData.group(3)) + '\n') + return + if tagType == 'subsection': + + gmuSettings_global['counter_subsection'] += 1 + content[gmuSettings_global['counter_section'] - 1]['subsections'].append({ + 'title': tagData.group(3), + 'number': gmuSettings_global['counter_subsection'], + }) + + tempFile.write(renderSubsectionTitle(gmuSettings_global, tagData.group(3)) + '\n') + return + + if tagType == 'contents': + tempFile.write('{{gmu.contents}}\n') + return + + if lineContent[0:2] == "%%": + return + + tempFile.write(lineContent + '\n') + +def processLine2(lineNumber, lineContent, tempFile): + #print("[DEBUG] Line{}: {}".format(lineNumber, lineContent)) + + if len(lineContent) > 8: + + if lineContent[0:6] == "{{gmu.": + # found content-tag + tagData = contenttagRegEx.match(lineContent) + + if not tagData: + abortParseError(lineNumber, lineContent, "Cannot parse content-tag") + + tagType = tagData.group(1)[4:] + + if tagType == 'contents': + tempFile.write(renderContentTable(gmuSettings_global, content ) + '\n') + return + + if lineContent[0:2] == "%%": + return + + tempFile.write(lineContent + '\n') + + +def processFile(path): + try: + startTime = time.time() + print("[Phase 1] Processing PrimalMarkupScript-Sourcefile: " + path) + + inFile = open(path, 'r') + inFileLines = inFile.readlines() + tempFile = open(gmuOutputFileTmp, 'w') + + lineCount = 0 + for line in inFileLines: + lineCount += 1 + processLine(lineCount, line.strip(), tempFile) + + tempFile.close() + endTime = time.time() + + print("[Phase 1] Compiled {} lines in {}s".format(lineCount, (endTime - startTime))) + print(" => Registered {} Sections".format(gmuSettings_global['counter_section'])) + print(" => Generated pmc1-file {}".format(gmuOutputFileTmp)) + except IOError: + print("Sourcefile not accessible") + + + +def processFileRound2(path): + try: + startTime = time.time() + print("[Phase 2] Processing pmc1-file: " + path) + + inFile = open(path, 'r') + inFileLines = inFile.readlines() + tempFile = open(gmuOutputFile, 'w') + + lineCount = 0 + for line in inFileLines: + lineCount += 1 + processLine2(lineCount, line[:-1], tempFile) + + tempFile.close() + endTime = time.time() + + print("[Phase 2] Generated Content-Table in {}s".format((endTime - startTime))) + print(" => Generated info-file {}".format(gmuOutputFile)) + except IOError: + print("Sourcefile not accessible") + +def printHeader(): + print(pyfiglet.figlet_format("PrimalMarkup")) + print("PrimalMarkupScript Compiler v1.0.0") + print("(c)2021 - Dennis Gunia - dennisgunia.de\n") + + +#### EVALUATE PARAMETERS + + +full_cmd_arguments = sys.argv +argument_list = full_cmd_arguments[1:] + +short_options = "ho:i:" +long_options = ["help", "output=", "input="] + +try: + arguments, values = getopt.getopt(argument_list, short_options, long_options) +except getopt.error as err: + print (str(err)) + sys.exit(2) + + +#### MAIN +printHeader() + + +for current_argument, current_value in arguments: + if current_argument in ("-i", "--input"): + gmuInputFile = current_value + elif current_argument in ("-h", "--help"): + print ("Specify Input with -i or --input") + print ("Specify Output with -o or --output") + exit(0) + elif current_argument in ("-o", "--output"): + gmuOutputFile = current_value + +if gmuInputFile == '': + print("[ERROR] You need to specify an input file") + exit(2) + +if gmuOutputFile == '': + print("[ERROR] You need to specify an output file") + exit(2) + +#check if files exist + +processFile(gmuInputFile) +processFileRound2(gmuOutputFileTmp) + +print("\nDone! Compiled 1 File.") \ No newline at end of file diff --git a/src/render.py b/src/render.py new file mode 100644 index 0000000..4bdf852 --- /dev/null +++ b/src/render.py @@ -0,0 +1,51 @@ +import pyfiglet + +def renderSeperator(properties): + outString = '' + + for i in range(0, properties['Document']['defaultWidth']): + outString = "{}{}".format(outString, properties['Document']['spacerChar']) + + return outString + +def renderHeader(properties): + ascii_banner = pyfiglet.figlet_format(properties['Document']['shorttitle']) + ascii_banner = "{}Title : {}".format(ascii_banner,properties['Document']['title']) + ascii_banner = "{}\nAuthor : {}\n".format(ascii_banner,properties['Document']['author']) + return ascii_banner + +def repeatChar(symbol, amount): + outString = '' + for i in range(0, int(amount)): + outString = "{}{}".format(outString, symbol) + return outString + +def renderSectionTitle(properties, title): + titleString = "{}. {}".format(properties['counter_section'] ,title) + titleLen = len(titleString) + return "{}\n{}".format(titleString, repeatChar('=', titleLen)) + +def renderSubsectionTitle(properties, title): + titleString = "{}.{} {}".format(properties['counter_section'] ,properties['counter_subsection'] ,title) + titleLen = len(titleString) + return "{}{}\n{}{}".format(properties['Document']['indentation'],titleString, properties['Document']['indentation'], repeatChar('-', titleLen)) + +def renderContentTable(properties, content): + contentString = '' + + for section in content: + sectionNumber = section['number'] + titleString = "{}. {}".format(sectionNumber, section['title']) + titleStringLen = len(titleString) + contentString = "{}\n{}\n{}".format(contentString,titleString,repeatChar('-',titleStringLen)) + + #subsections + + for subsection in section['subsections']: + titleString = "{}.{} {}".format(sectionNumber,subsection['number'], subsection['title']) + contentString = "{}\n{}{}".format(contentString,properties['Document']['indentation'],titleString) + + contentString = "{}\n".format(contentString) + + + return contentString[1:] \ No newline at end of file diff --git a/test/test.info b/test/test.info new file mode 100644 index 0000000..a758316 --- /dev/null +++ b/test/test.info @@ -0,0 +1,59 @@ +################################################################################ + _ _ _ _ + / \ _ __ ___(_) |__ | | ___ + / _ \ | '_ \/ __| | '_ \| |/ _ \ + / ___ \| | | \__ \ | |_) | | __/ +/_/ \_\_| |_|___/_|_.__/|_|\___| + +Title : Testdokument +Author : Dennis Gunia + +################################################################################ + +Inhalt: +======= + +1. Kapitel1 +----------- + 1.1 Hier gehts weiter + 1.2 Hier gehts weiter Pt. 2 + +2. Kapitel2 +----------- + +3. Kapitel3 +----------- + 3.1 Hier gehts weiter Pt. 2 + + +################################################################################ + +1. Kapitel1 +=========== +Dies ist ein Testdokument + + 1.1 Hier gehts weiter + --------------------- +Wenn der Kühler friert, der Keilriemen durchhängt und Schläuche nicht ganz dicht sind, +kann es dem Motor ganz schön heiß werden. Damit Ihnen Ihr Motor bei Kälte keine Kopfschmerzen bereitet, +sollten Sie Ihr Kühlsystem zum günstigen Komplett-Preis durchchecken lassen. +Ihr Opel-Händler nimmt dabei alle Kühlmittel- und Heizungsschläuche, den Kühler samt ... + + 1.2 Hier gehts weiter Pt. 2 + --------------------------- +ur wer seinen Visionen vertraut, kann die Wirklichkeit verändern. Denn Visionen sind es, die uns weiterbringen. +Visionen sind es, die uns und unseren Kunden zu einem wirklichen Wettbewerbsvorsprung verhelfen und neue Perspektiven erschließen. + + +2. Kapitel2 +=========== +Dies ist ein Testdokument + + +3. Kapitel3 +=========== +Dies ist ein Testdokument + + 3.1 Hier gehts weiter Pt. 2 + --------------------------- +wieso? diff --git a/test/test.info.tmp b/test/test.info.tmp new file mode 100644 index 0000000..442a310 --- /dev/null +++ b/test/test.info.tmp @@ -0,0 +1,48 @@ +################################################################################ + _ _ _ _ + / \ _ __ ___(_) |__ | | ___ + / _ \ | '_ \/ __| | '_ \| |/ _ \ + / ___ \| | | \__ \ | |_) | | __/ +/_/ \_\_| |_|___/_|_.__/|_|\___| + +Title : Testdokument +Author : Dennis Gunia + +################################################################################ + +Inhalt: +======= + +{{gmu.contents}} + +################################################################################ + +1. Kapitel1 +=========== +Dies ist ein Testdokument + + 1.1 Hier gehts weiter + --------------------- +Wenn der Kühler friert, der Keilriemen durchhängt und Schläuche nicht ganz dicht sind, +kann es dem Motor ganz schön heiß werden. Damit Ihnen Ihr Motor bei Kälte keine Kopfschmerzen bereitet, +sollten Sie Ihr Kühlsystem zum günstigen Komplett-Preis durchchecken lassen. +Ihr Opel-Händler nimmt dabei alle Kühlmittel- und Heizungsschläuche, den Kühler samt ... + + 1.2 Hier gehts weiter Pt. 2 + --------------------------- +ur wer seinen Visionen vertraut, kann die Wirklichkeit verändern. Denn Visionen sind es, die uns weiterbringen. +Visionen sind es, die uns und unseren Kunden zu einem wirklichen Wettbewerbsvorsprung verhelfen und neue Perspektiven erschließen. + + +2. Kapitel2 +=========== +Dies ist ein Testdokument + + +3. Kapitel3 +=========== +Dies ist ein Testdokument + + 3.1 Hier gehts weiter Pt. 2 + --------------------------- +wieso? diff --git a/test/test.pms b/test/test.pms new file mode 100644 index 0000000..3894735 --- /dev/null +++ b/test/test.pms @@ -0,0 +1,38 @@ +[[gmu.title=Testdokument]] +[[gmu.shorttitle=Ansible]] +[[gmu.author=Dennis Gunia]] +%% Dies it ein Kommentar. Einfach Ignorieren +{{gmu.seperator}} +{{gmu.header}} +{{gmu.seperator}} + +Inhalt: +======= + +{{gmu.contents}} + +{{gmu.seperator}} + +{{gmu.section=Kapitel1}} +Dies ist ein Testdokument + +{{gmu.subsection=Hier gehts weiter}} +Wenn der Kühler friert, der Keilriemen durchhängt und Schläuche nicht ganz dicht sind, +kann es dem Motor ganz schön heiß werden. Damit Ihnen Ihr Motor bei Kälte keine Kopfschmerzen bereitet, +sollten Sie Ihr Kühlsystem zum günstigen Komplett-Preis durchchecken lassen. +Ihr Opel-Händler nimmt dabei alle Kühlmittel- und Heizungsschläuche, den Kühler samt ... + +{{gmu.subsection=Hier gehts weiter Pt. 2}} +ur wer seinen Visionen vertraut, kann die Wirklichkeit verändern. Denn Visionen sind es, die uns weiterbringen. +Visionen sind es, die uns und unseren Kunden zu einem wirklichen Wettbewerbsvorsprung verhelfen und neue Perspektiven erschließen. + + +{{gmu.section=Kapitel2}} +Dies ist ein Testdokument + + +{{gmu.section=Kapitel3}} +Dies ist ein Testdokument + +{{gmu.subsection=Hier gehts weiter Pt. 2}} +wieso? \ No newline at end of file