hevslib.md module

Hevslib md module is facilitating creating a markdown document the only requirement is the hevslib.general module

Import

import sys
sys.path.append("hevslib")

from hevslib.md import *

Example

mdFile = Md(filepath="mdTest.md", append=False)
mdFile.h1("Title 1")
mdFile.text("normal")
mdFile.list(["1", ["1.1", "1.2"], "2"])
mdFile.link("https://duckduckgo.com", "DuckDuckGo")
mdFile.image("img/dashboard.png", "dashboard")
table.append(["Header 1", "Header 2", "Header 3"])
table.append(["R1 C1", "R1 C2", "R1 C3"])
table.append(["R2 C1", "R2 C2", "R2 C3"])
table.append(["R3 C1", "R3 C2", "R3 C3"])
mdFile.table(table)
mdFile.rule()
mdFile.linesep()
mdFile.inlineCode("int i = 0")
mdFile.code("i = 0", "python")

mdFile.writeMd(append=True)
mdFile.writePdf(output_dir="./")

Documentation

class hevslib.md.Md(filepath=None, append=False, log=None)

Bases: object

Main Md class holds all content of one markdown document

blockquotes(stringQuotes=[], level=0, newline=True, append=True)

Create Markdown Blockquotes from a python list of string. Can also be a list of list of string to create multilevel blockquotes

Parameters
  • stringQuotes – list of strings or lists of strings [“”, “”, [“”, “”], …]

  • level – int of list (starts with 0)

  • newline – adds a newline at the end (default: True)

  • append – appends to internal variable or gives just the value on return (default: True)

Returns

string

Raises

None

bold(text=None, newline=False)

Create Markdown bold text

Parameters
  • text – string

  • newline – adds a newline at the end (default: False)

Returns

string

Raises

None

code(code=None, lang=None, newline=True)

Create Markdown Code Block

Parameters
  • code – string of code including line separations

  • lang – markdown codeblock valid language for syntax highlighting

  • newline – adds a newline at the end (default: True)

Returns

string

Raises

None

getDoc()

Get markdown document as string

Parameters

None

Returns

string

Raises

None

getFile()

Get markdown document as filepath

Parameters

Nonec

Returns

string

Raises

None

h1(text=None)

Create Markdown Header Level 1

Parameters

text – string header text

Returns

string

Raises

None

h2(text=None)

Create Markdown Header Level 2

Parameters

text – string header text

Returns

string

Raises

None

h3(text=None)

Create Markdown Header Level 3

Parameters

text – string header text

Returns

string

Raises

None

h4(text=None)

Create Markdown Header Level 4

Parameters

text – string header text

Returns

string

Raises

None

h5(text=None)

Create Markdown Header Level 5

Parameters

text – string header text

Returns

string

Raises

None

heading(text=None, level=1)

Create Markdown Header

Parameters
  • text – header text

  • level – level of headers [1 .. x]

Returns

string

Raises

None

image(imagelink=None, alt=None, url=None, absolutePath=False, space=True, newline=False)

Create Markdown Image Link

Parameters
  • imagelink – string image url or link to file

  • alt – string optional image alt text

  • url – string optional link when clicking on image

  • space – add a space at the end (default: True)

  • newline – adds a newline at the end (default: True)

Returns

string

Raises

None

inlineCode(code=None, space=True, newline=False)

Create Markdown inline code text

Parameters
  • code – string

  • newline – adds a newline at the end (default: False)

Returns

string

Raises

None

italic(text=None, newline=False)

Create Markdown italic text

Parameters
  • text – string

  • newline – adds a newline at the end (default: False)

Returns

string

Raises

None

linesep()

Creates a markdown line separation

Parameters

None

Returns

string

Raises

None

Create Markdown Link

Parameters
  • url – string url to link to

  • alt – string url alt text

  • space – add a space at the end (default: True)

  • newline – adds a newline at the end (default: False)

Returns

string

Raises

None

list(stringList=[], level=0, ordered=False, newline=True, append=True)

Create Markdown ordered or unordered list from a python list of string. Can also be a list of list of string to create multilevel lists

Parameters
  • stringList – list of strings or lists of strings [“”, “”, [“”, “”], …]

  • level – int of list (starts with 0)

  • ordered – bool ordered vs unordered list

  • newline – adds a newline at the end (default: True)

  • append – appends to internal variable or gives just the value on return (default: True)

Returns

string

Raises

None

rule()

Creates a markdown rule

Parameters

None

Returns

string

Raises

None

strikethrough(text=None, newline=False)

Create Markdown strikethrough text

Parameters
  • text – string

  • newline – adds a newline at the end (default: False)

Returns

string

Raises

None

table(stringlist=[], align=[], header=True)

Create Markdown table

Parameters
  • stringList – list list of strings with content of table [[“”, “”], [“”, “”]]

  • align – list optional with same width as stringList ‘l’,’c’,’r’ left center right aligned

  • header – bool optional create header or not

Returns

string

Raises

NotSameLengthError

text(text=None, newline=False)

Create Markdown normal text

Parameters
  • text – string

  • newline – adds a newline at the end (default: False)

Returns

string

Raises

None

verifyUrl(url=None)

Verify url syntax

Parameters

url – valid url

Returns

bool

Raises

None

writeMd(append=None)

Creates and writes markdown file

Parameters

None

Returns

string

Raises

None

writePdf(output_dir=None, css_path=None)

Converts md file to a pdf file markdown-pdf is needed for PDF Report: https://www.npmjs.com/package/markdown-pdf

`npm install -g markdown-pdf`

Parameters
  • output_dir – output directory for output pdf file (default same as source file)

  • css_path – path to css file

Returns

absolute path to pdf file

Return type

path

Raises

None