Package: markyp
markypPython 3 tools for creating markup documents.InstallationThe project is listed on the Python Package Index, it can be installed simply by executingpip install markyp.General conceptsElement creation inmarkypand its derivates usually works as follows:If an element can have children, then the positional arguments passed to the component become the children of the created element.If an element can have attributes, then keyword arguments that are not listed explicitly on the argument list (i.e.**kwargs) are turned into element attributes.Explicitly declared keyword arguments work as documented.The markup defined by the created elements can be obtained by converting to root element to string (str()) or by using the root element'smarkupproperty.Getting startedCreating newmarkypelement types is typically as simple as deriving new classes with the right name from the base elements that are provided by the project. The following example shows the creation of some HTML elements:frommarkypimportElementTypefrommarkyp.elementsimportElement,StringElementclasshtml(Element):__slots__=()def__str__(self)->str:returnf"<!DOCTYPE html>\n{(super().__str__())}"classhead(Element):__slots__=()classbody(Element):__slots__=()classtitle(StringElement):__slots__=()classp(Element):__slots__=()@propertydefinline_children(self)->bool:returnTrueclasscode(StringElement):__slots__=()classul(Element):__slots__=()classli(Element):__slots__=()Once you have defined the basic components that are required by your project, you can make document creation easier by creating higher order functions that convert your data into markup elements.defcreate_unordered_list(*items:ElementType)->ul:"""Creates an unordered list from the received arguments."""returnul(*(li(item,class_="fancy-list-item",style="color:blue;")foriteminitems),class_="fancy-list")When everything is in place, a document can be created simply by instantiating the elements that make up the document. Notice that during element construction, positional arguments are treated as children elements and keyword arguments are treated as element attributes, allowing you to create documents using a markup-like syntax.document=html(head(title("Hello World!")),body(p(code("markyp"),"HTML example.",style="font-weight:bold;"),p("Creating lists is easy as",style="color:blue;"),create_unordered_list("One",p("Two",style="font-style:italic;"),"Three"),style="font-size:20px"))At this point, you have a Python object representing your document. The actual markup is created only when you convert this object into a string using either thestr()method or themarkupproperty of the element.print(document)Domain-specificmarkypextensionsmarkypextensions should follow themarkyp-{domain-or-extension-name}naming convention. Here is a list of domain-specific extensions:markyp-rss: RSS 2 implementation athttps://github.com/volfpeter/markyp-rss, contribution is welcome.markyp-html: HTML implementation athttps://github.com/volfpeter/markyp-html, contribution is welcome.markyp-highlightjs: HTML code highlighting usinghighlight.jsathttps://github.com/volfpeter/markyp-highlightjs, contribution is welcome.markyp-bootstrap4: Bootstrap 4 implementation athttps://github.com/volfpeter/markyp-bootstrap4, contribution is welcome.markyp-fontawesome: Font Awesome icons formarkyp-html-based web pages athttps://github.com/volfpeter/markyp-fontawesome, contribution is welcome.If you have created an open sourcemarkypextension, please let us know and we will include your project in this list.Community guidelinesIn general, please treat each other with respect and follow the below guidelines to interact with the project:Questions, feedback: Open an issue with a[Question] <issue-title>title.Bug reports: Open an issue with a[Bug] <issue-title>title, an adequate description of the bug, and a code snippet that reproduces the issue if possible.Feature requests and ideas: Open an issue with an[Enhancement] <issue-title>title and a clear description of the enhancement proposal.Contribution guidelinesEvery form of contribution is welcome, including documentation improvements, tests, bug fixes, and feature implementations.Please follow these guidelines to contribute to the project:Make sure your changes match the documentation and coding style of the project, includingPEP 484type annotations.mypyis used to type-check the codebase, submitted code should not produce typing errors. Seethis pagefor more information onmypy.Smallfixes can be submitted simply by creating a pull request.Non-trivial changes should have an associatedissuein the issue tracker that commits must reference (typically by adding#refs <issue-id>to the end of commit messages).Please writetestsfor the changes you make (if applicable).If you have any questions about contributing to the project, please contact the project owner.TestingAs mentioned in thecontribution guidelines, the project is type-checked usingmypy, so first of all, the project must passmypy's static code analysis.The project is tested usingpytest. The chosen test layout is that tests are outside the application code, seethis pagefor details on what it means in practice.Ifpytestis installed, the test set can be executed using thepytest testcommand from within the project directory.Ifpytest-covis also installed, a test coverage report can be generated by executingpytest test --cov markypfrom the root directory of the project.License - MITThe library is open-sourced under the conditions of the MITlicense.