Credits: Developers, Contributors and free software used in Coppermine. MIT License A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.
Released:
A renderer for markdown text onto pygame surfaces.
Project description
Purpose
The package's class parses and renders the contents of a markdown file onto a pygame surface.
Usage
1. Instantiation
The class instantiation takes one parameter: the path to the local markdown file.
2. Set the surface, location and area
To display the content of the markdown file on a specific surface in a specific location use the method:
surface
- the pygame surface which the text is blitted onoffset_X
- the offset of the text from the surface's left sided borderoffset_Y
- the offset of the text from the surface's top border
Optional:
textAreaWidth
- the width of the textareatextAreaHeight
- the height of the textarea
If no width/height is supplied, the entire length - starting from the x-/y-coordinateto the right/bottom side of the supplied surface - is used.
3. Display
In the pygame loop, the method display
renders the contents of the markdown file onto the surface.In order to allow for scrolling, the display method requires some values from pygame.
Internal workings
The class uses a two stage process to render the contents of a markdown file onto a pygame surface.For an overview of the implemented syntactic markdown structures, see Markdown element implementations.
Stage 1: Parsing
The markdown file is parsed to HTML using the package markdown.
Based on the HTML-markers for different types of paragraphs, lists and headers, the text is split into thematic blocks.
Stage 2: Rendering
Each block is rendered based on its specifications. Inline formatting such as bold/strong
, italic
and code
are taken into account during the rendering process.
- Text (excluding code-blocks!) is automatically continued in the next line if the supplied width is too small for theparagraph to fit into one line.
- Code is indented and has a different background color
- Quotes are indentend, have a different font color and a vertical rectangle in front of the text.
- Horizontal rule blocks are rendered as a horizontal rectangle along the width of the textarea.
Customization
The visuals of the markdown code can be customized with the following function.All functions have default values for the parameters.
Text Format
- Setting gaps after lines and paragraphs respectively:
Fonts
- Setting the font for the normal text and for the code-blocks independently.The module uses pygame.font.SysFont. Possible options are Verdana, Arial, CourierNew, Helvetica etc.The Fonts are given by name as Strings.
- Setting Font sizes for the three headers, normal text and code-blocks.
Coloring
- Setting the background color of the markdown area
- Setting the general font color of via rgb codes (no default values)
- Setting the font color of quote-blocks via rgb codes (no default values)
- Setting the background color of the code-blocks via rgb codes (no default values)
- Setting the color of the horizontal line:
Markdown element implementations
The following table gives an overview on which markdown elements are implemented so far and can be displayed correctly.
Element | Markdown Syntax |
---|---|
Heading | # h1 ## h2 ### h3 |
Bold | Lorem **bold text** ipsum |
Italic | Lorem *italicized text* ipsum |
Block of code | ``` print('Hello World!') ``` |
Inline code | Lorem `print('Hello World')` ipsum |
Unordered List | - First item - Second item - Third item |
Ordered List | 1. First item 2. Second item 3. Third Item |
Blockquote | > Lorem ipsum |
Horizontal rule | --- |
Limitations
Warning: Disregarding the following limitations leads to unpredictable outcomes.
A further indented sublist within a list (2nd level items) is not possible at the moment.
Codeblocks are not wrapped. This can lead to code being displayed to the right side of the text area if a code lineis longer than the specified width of the textarea.
Code blocks do not recognize language strings. Code highlighting is hence not implemented.
Mit License Markdown Calculator
Overloading the format of a word with bold and italic at the same time is not possible.
Inline formatting is currently only recognized if a whitespace leads and trails the formatting characters.
Incorrect Example:
Correct example:
Contributing
Mit License Open Source
I welcome pull requests from the community.Please take a look at the TODO file for opportunities to help this project.
Please ensure your PR fulfills the following requirements:
- English code documentation - including doc-strings for new methods.
- Pull Requests must fulfill at least one of the following purposes:
- Bugfixing
- New functionality (or extending the existing functionalities)
- Enhancement concerning performance or ease of use.
- The README is updated accordingly.
- Your code should pass PEP8. You can check your code's PEP8 compliance here.The exception is the errorcode
E501 - line too long
- because 79 characters per line is a stupid limit.
Full example
The following code is a full example of how the package can be used.
Release historyRelease notifications | RSS feed
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.9.2
1.0.9.1
1.0.9
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size pygame_markdown-1.1.4-py3-none-any.whl (18.8 kB) | File type Wheel | Python version py3 | Upload date | Hashes |
Filename, size pygame-markdown-1.1.4.tar.gz (17.9 kB) | File type Source | Python version None | Upload date | Hashes |
Hashes for pygame_markdown-1.1.4-py3-none-any.whl
Algorithm | Hash digest |
---|---|
SHA256 | 2f2eeed418852b461da3539dd9a6c4c32de0716588f8b7f59a900e496b961a4a |
MD5 | 2748e9ad5da8b7e465aeef069e0802a4 |
BLAKE2-256 | 10600472fe01bff0f31f5c5d3958337a1c7e8b95d1cd780625885229c4a56f93 |
Hashes for pygame-markdown-1.1.4.tar.gz
Algorithm | Hash digest |
---|---|
SHA256 | 4f0dc7db9203d4b4b137e760a9d9f38b7b0844ecb09ff44858249ccd57c1056f |
MD5 | b9f8a6d8c0082d1b9aabf280a491264b |
BLAKE2-256 | 941c64da19a2be19e5c5b30e6e4f0238655218c4dcec18a8c02a60676d55225a |
Released:
A small library for writing markdown with a tree structure of python objects that you can transform into a markdown snippet(string).
Project description
-----
A small library for writing markdown with a tree structure of python objects that you can transform into a
markdown snippet(string).
I started it by extracting some code I wrote for a reddit bot.
It was partially inspired by looking at the ScalaTags examples(although not using it).
ex. 2 Paragraphs, 1 in Italic the other in Bold.
import markdown_tags as m
tags = m.MD(m.Paragraph(m.Italic('Italian')), m.Paragraph(m.Bold('Boring, Portland')))
markdown_str = tags.tags_to_markdown(recover=False, format_md=m.MarkdownFormats.reddit)
*returns a markdown string that will render as:*
*Italian*
**Boring, Portland**'
ex. of a nested list or a list with multi paragraph items.
import markdown_tags as m
tags = m.MD(m.UnorderedList.with_title('Maslow's hierarchy of needs partial outline',
m.OrderedList(
m.UnorderedList.with_title('Physiological needs',
'Air',
'Water'),
m.UnorderedList.with_title('Safety needs',
'Personal security',
'Financial security',
'Health and well-being',
'Safety net against accidents/illness ' +
'and their adverse impacts'),
'Love and belonging',
'Esteem',
'Self-actualization'),
'Research',
'Criticism'))
*returns a markdown string that will render as:*
Maslow's hierarchy of needs partial outline
+ Needs
1. Physiological needs
+ Air
+ Water
2. Safety needs
+ Personal security
+ Financial security
+ Health and well-being
+ Safety net against accidents/illness and their adverse impacts
3. Love and belonging
4. Esteem
5. Self-actualization
+ Research
+ Criticism
*note that the discount markdown implementation used by reddit seems to translate this to html fine but it shows up
a little strange with outer unordered list w/ the same indentation as inner ordered list on reddit.*
Tested with the discount markdown implementation used by reddit.
I might look into testing with other markdown implementations later.
Release historyRelease notifications | RSS feed
0.2.1
0.2.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size markdown_tags-0.2.1.tar.gz (5.6 kB) | File type Source | Python version None | Upload date | Hashes |
Hashes for markdown_tags-0.2.1.tar.gz
Algorithm | Hash digest |
---|---|
SHA256 | 6a51a3b29390d8a454926da7e3a4a6b86d88399a8ce058918436907a863e5aec |
MD5 | 0fc68c6d607c27bfe14966804a16b5d1 |
BLAKE2-256 | cef45e549e21360e70e37bddd421fd1010ae094dd112f4373dfd1fbb66eeee26 |