Markdownipy, python markdown generator library
Project description
Markdownipy
Markdownipy is a Python library to generate markdown files using only two operators and some helpers
Markdownipy can be used in jupyter notebooks to generate markdown outputs in python cells or inside any .py file, see below for examples
<
(lower than operator) writes text to markdown file, |
(pipe operator) just gives property to the text
Even this README file is genereted by markdownipy!
Motivation
Lately, I'm trying to write markdown documentations for different codes and I needed to put some specs, numbers etc. so just copy-paste some tables, links. I was trying to change some predefined strings to speed up my writing process, yet instead of text manipulation I just wanted to make it as a library.
Sometimes I also forget markdown syntax, so this library requires no memory (I hope so, there is even no function calls) :)
Only requirement is remembering the properties of markdownipy and the rest will be handled
Install
pip install markdownipy
Quick start - example Jupyter cell
from markdownipy import markdownipy
from IPython.display import display,Markdown
md = markdownipy.markdownipy()
md < "hello there" | md.bold
md < "This should be a italic text" | md.italic
display(Markdown(md.print()))
See the example jupter notebook output: Example jupyter file
Quick start - example Python code
from markdownipy import markdownipy
md = markdownipy.markdownipy()
#Simple line
md < "Hello there!"
#Bold text, numbers are also allowed
md < 3.14159 | md.bold
#Italic text
md < "Above bold text is just some digits of pi" | md.italic
#One line code and codeblock
md < "One line code " | md.code
md < '''
void markdownipy_helper(int x, int y, int z):
return x*y*z
''' | md.codeb("cpp")
#Lists
md < ["Item1","Item2","Item3"]
#Tables
md < {
"Country":["Fran","Kate","Ivan"],
"Age" : [30,48,73]
}
#E-mail, links
md < "fbgencer8@gmail.com" | md.link
md < "fbgencer8@gmail.com" | md.link("My mail")
#Image
md < "./markdownipy_logo.png" | md.image
#Writing to a file, README or README.md both works!
#Even md >> sys.stdout prints the whole markdown document
md >> "README"
Library keywords
This table is the whole documentation of markdownipy! (Assuming md is the markdown object in python)
Keywords | Explanation | Markdown equivalent |
---|---|---|
md.bold | Bold text | __text__ |
md.italic | Italic text | _text_ |
md.strike | Strikethrough text | ~~text~~ |
md.code | For single line code | code |
md.codeb | Code fence, takes optional arg as language name | ```code``` |
md.link or md.link(link_name) | Link text | [link_name(optional)](link) |
md.hline | Horizontal line | --- |
md.chapter | Chapter | Chapter_name\n=== |
md.h1 | Header level 1 | # Header1 |
md.h2 | Header level 2 | ## Header2 |
md.h3 | Header level 3 | ### Header3 |
md.h4 | Header level 4 | #### Header4 |
md.h5 | Header level 5 | ##### Header5 |
md.h6 | Header level 6 | ###### Header6 |
md.image or md.image(image_name) | Image insertion | ![image_name(optional)](image_path) |
md.task | Task entry in a list | [ ] text |
md.task_check | Checked task entry in a list | [x] text |
object | md.keyword |
Pipes the above defined line property keywords to the object | |
md < object |
Adds any object to document (str,dict,list,numbers etc.) | |
md > file_name |
Writes document to a file | |
md > stdout |
Prints the document to console | |
md.print() | Returns the markdown document as string | |
md.clear() | Clears the markdown document |
Headers
md < "This is a chapter" | md.chapter
md < "This is header1" | md.h1
md < "This is header2" | md.h2
md < "This is header3" | md.h3
md < "This is header4" | md.h4
md < "This is header5" | md.h5
md < "This is header6" | md.h6
Output :
This is a chapter
This is header1
This is header2
This is header3
This is header4
This is header5
This is header6
Bold, italic, strikethrough texts
md < "This should be a bold text" | md.bold
md < "This is an italic text" | md.italic
md < "Strikethrough is banned" | md.strike
Output :
This should be a bold text
This is an italic text
Strikethrough is banned
Lists
md < [
"Classical mechanics" | md.bold,
[
"Newton's law of motion",
"Lagrangian Mechanics"
],
"Thermodynamics and statistical mechanics" | md.italic,
"Electromagnetism and photonics",
"Relativistic mechanics",
"Quantum mechanics, atomic physics, and molecular physics",
[
"*", #For dot bullet put bullet type
"Schrödinger equation",
"Quantum field theory",
[
"Lists can be nested :)",
"This is another liner",
[
"Oh this is getting serious" | md.strike,
"And now bunch of numbers",
[
3.1415,
2.7176,
99999,
88888
],
"Now another item"
],
],
"Quantum statistical mechanics"
],
"Optics and acoustics",
"Condensed matter physics",
"High-energy particle physics and nuclear physics",
]
Output :
-
Classical mechanics
-
Newton's law of motion
-
Lagrangian Mechanics
-
-
Thermodynamics and statistical mechanics
-
Electromagnetism and photonics
-
Relativistic mechanics
-
Quantum mechanics, atomic physics, and molecular physics
-
Schrödinger equation
-
Quantum field theory
-
Lists can be nested :)
-
This is another liner
-
Oh this is getting serious -
And now bunch of numbers
-
3.1415
-
2.7176
-
99999
-
88888
-
-
Now another item
-
-
-
Quantum statistical mechanics
-
-
Optics and acoustics
-
Condensed matter physics
-
High-energy particle physics and nuclear physics
Table
md < {
"Name" : ["Albert", "Paul" | md.bold, "Richard"],
"Surname" : ["Einstein" | md.italic, "Dirac" , "Feynman" | md.italic],
}
Output :
Name | Surname |
---|---|
Albert | Einstein |
Paul | Dirac |
Richard | Feynman |
Links
md < "https://github.com/fbgencer/markdownipy" | md.link("Markdownipy website")
Output :
Image
md < ("markdownipy_logo.png" | md.image("Image name"))
Output :
Single line Quote
md << ("With Great Power Comes Great Responsibility" | md.quote)
Output :
With Great Power Comes Great Responsibility
Task lists
md < ["-",
"Take the key" | md.bold | md.task,
"Cat food" | md.bold | md.task_check
]
Output :
-
Take the key
-
Cat food
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Markdownipy-1.0.0.tar.gz
.
File metadata
- Download URL: Markdownipy-1.0.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df7c7595ac671918e5124eec5894e5797034cf45130caa0cd49f8d90b445c3bc |
|
MD5 | d9cfe0890d589386de14fc07df9c0296 |
|
BLAKE2b-256 | 1923d3029310fe5d76bfcd5aa03d1be173fa10c595f7144cb7d317d065798802 |
File details
Details for the file Markdownipy-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: Markdownipy-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89868fbba9b7aa070ab465fe278694bc288926ed7adf49321cd655909b9dbc18 |
|
MD5 | f999ce80ed5fa78c5c77c425367152df |
|
BLAKE2b-256 | 66786702412c7926e8d10992ec73be3a3991f96a06a681f3b438f32c50e534fe |