Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
31fb56e
Created NewFile class.
didix21 Apr 7, 2018
e952f9d
Python code inspection done.
didix21 Apr 7, 2018
47bb68c
new classes created Headers and MdUtils.
didix21 Apr 7, 2018
dca343b
Added new Class TableOfContents
didix21 Apr 10, 2018
4000926
It has been added comment on the different methods
didix21 Apr 10, 2018
d7faa15
Added new method append_after_first_line and added new documentation
didix21 Apr 12, 2018
caa1ab0
Added new documentation on each method MdUtils Class method.
didix21 Apr 12, 2018
96ec0c0
Renamed append_after_first_line by append_after_second_line. It has b…
didix21 Apr 12, 2018
bf1ef0d
Now the table of contents will be written at the second line of Markd…
didix21 Apr 12, 2018
0b4503f
""
didix21 Apr 12, 2018
d900cf3
Firs commit of tools.py: Contain classes Header, TableOfCOntents, Tab…
didix21 Apr 12, 2018
0656303
Adding __init__.py file
didix21 Apr 12, 2018
b8e4a2a
Ignore Test.md file.
didix21 Apr 12, 2018
32cb7d3
Renamed _llop_trough
didix21 Apr 12, 2018
226c6d5
Ignore .idea folder.
Apr 13, 2018
1662777
" Now you can create tables"
didix21 Apr 13, 2018
6bd28be
Now tables are correctly created
didix21 Apr 13, 2018
fb1fe32
Adding Readme.md
didix21 Apr 13, 2018
41fd444
Changed some features, now all data will be saved previously in a st…
didix21 Apr 15, 2018
7926291
Merge branch 'redo_structure' into development
didix21 Apr 15, 2018
2571d91
Added text format method. Now, it is simple to give format to text.
didix21 Apr 15, 2018
6aa60cb
Added a long description to MdUtils Class.
didix21 Apr 15, 2018
98cedcc
TestHeader created and it is correctly passed.
didix21 Apr 15, 2018
6514fbb
TestTableOfContents created and correctly passed.
didix21 Apr 15, 2018
74253c8
PEP8 OK.
didix21 Apr 15, 2018
3a4d4b7
Adding test file
didix21 Apr 15, 2018
a7ba391
Added test_mdUtils.py file.
didix21 Apr 15, 2018
8336c7f
Added table test. It is passed correctly.
didix21 Apr 15, 2018
422d677
updating main test
didix21 Apr 15, 2018
a36fe17
Updated test_table result.
didix21 Apr 16, 2018
9312d1b
Creating new method to add internal and external links.
didix21 Apr 16, 2018
6c73986
Updated reame with actual features and possible ones.
didix21 Apr 16, 2018
799026f
Renamed Readme by README
didix21 Apr 16, 2018
c701683
Added MANIFEST and setup.py files.
didix21 Apr 16, 2018
ad6616a
Added some spaces on setup.py between item lists.
didix21 Apr 16, 2018
50de94b
Changed __init__.py, now calls MdUtils.
didix21 Apr 16, 2018
5b2a06b
Updated setup.py
didix21 Apr 16, 2018
831e08c
Solved import errors.
didix21 Apr 16, 2018
91ee535
Solved import errors.
didix21 Apr 16, 2018
9ce8948
Added methods create_marker and place_text_using_marker. Methods impl…
didix21 Apr 16, 2018
824378b
Deleted create_itnernal_link method and created a new one named heade…
didix21 Apr 16, 2018
5158ddf
It is not necessary to give a link value. Anchor can be directly crea…
didix21 Apr 16, 2018
3ef0d15
Added new methods to align text.
didix21 Apr 16, 2018
5d7c12c
Merge remote-tracking branch 'origin/development' into development
didix21 Apr 16, 2018
bdb5c73
Added TextUtils test.
didix21 Apr 16, 2018
1850635
Added author and project name on test.
didix21 Apr 16, 2018
9044145
Now doctest works well
didix21 Apr 16, 2018
8db288c
Now table of contents can be placed wherever you want using a marker.
didix21 Apr 16, 2018
f575904
Implemented depth functionlity when creating table of contents. This …
didix21 Apr 16, 2018
392f342
Merge branch 'table_content_deep' into development
didix21 Apr 16, 2018
147e960
New method new_line implemented.
didix21 Apr 17, 2018
852fe69
Now, you can read markdown files.
didix21 Apr 17, 2018
dfbe94b
New method write added.
didix21 Apr 17, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ __pycache__/
# C extensions
*.so

# Others
Test.md
.idea*

# Distribution / packaging
.Python
build/
Expand Down
9 changes: 9 additions & 0 deletions .idea/dictionaries/didix21.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/mdutils_develop.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

850 changes: 850 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include README.md
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# mdutils
This package contains all of this utils necessary to create a Markdown file while you are executing python code. This
package it is useful when you are interested in save data on file and give format to it at the same time.

## Featerues

- Create a Markdown file.
- Create headers (1, 2, 3 til... 6).
- Create automatic table of contents.
- Give format to text: **bold**, _italics_ , `inline code`, <font color='orange'> change text color </font>...
- Insert internal links `[Text to be displayed](#text-to-be-displayed)` or external links `[external link]
(https://external.link.es)`
- Create tables

## Thinks to do

- Insert images, align them...

Empty file added Test/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions Test/test_mdUtils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from unittest import TestCase


class TestMdUtils(TestCase):
def test_create_md_file(self):
self.fail()

def test_new_header(self):
self.fail()

def test__add_new_item_table_of_content(self):
self.fail()

def test_new_table_of_contents(self):
self.fail()

def test_create_table(self):
self.fail()
Empty file added Test/test_tools/__init__.py
Empty file.
62 changes: 62 additions & 0 deletions Test/test_tools/test_header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from unittest import TestCase
from mdutils.tools.tools import Header

__author__ = 'didix21'
__project__ = 'MdUtils'

class TestHeader(TestCase):

def test_atx_level_1(self):
title = "Text Title Atx 1"
result = '\n# ' + title + '\n'
self.assertEqual(Header().atx_level_1(title), result)

def test_atx_level_2(self):
title = "Text Title Atx 2"
result = '\n## ' + title + '\n'
self.assertEqual(Header().atx_level_2(title), result)

def test_atx_level_3(self):
title = "Text Title Atx 3"
result = '\n### ' + title + '\n'
self.assertEqual(Header().atx_level_3(title), result)

def test_atx_level_4(self):
title = "Text Title Atx 4"
result = '\n#### ' + title + '\n'
self.assertEqual(Header().atx_level_4(title), result)

def test_atx_level_5(self):
title = "Text Title Atx 5"
result = '\n##### ' + title + '\n'
self.assertEqual(Header().atx_level_5(title), result)

def test_atx_level_6(self):
title = "Text Title Atx 6"
result = '\n###### ' + title + '\n'
self.assertEqual(Header().atx_level_6(title), result)

def test_setext_level_1(self):
title = "Text Title Setext 1"
result = '\n' + title + '\n' + ''.join(['=' for _ in title]) + '\n'
self.assertEqual(Header().setext_level_1(title), result)

def test_setext_level_2(self):
title = "Text Title Setext 2"
result = '\n' + title + '\n' + ''.join(['-' for _ in title]) + '\n'
self.assertEqual(Header().setext_level_2(title), result)

def test_choose_header(self):
header = Header()
func_list = [header.atx_level_1('Atx Example'), header.atx_level_2('Atx Example'),
header.atx_level_3('Atx Example'), header.atx_level_4('Atx Example'),
header.atx_level_5('Atx Example'), header.atx_level_6('Atx Example'),
header.setext_level_1('Setext Example'), header.setext_level_2('Setext Example')]
for x in range(8):
if x < 6:
title = 'Atx Example'
chosen_header = header.choose_header(level=x + 1, title=title, style='atx')
else:
title = 'Setext Example'
chosen_header = header.choose_header(level=x - 5, title=title, style='setext')
self.assertEqual(chosen_header, func_list[x])
61 changes: 61 additions & 0 deletions Test/test_tools/test_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from unittest import TestCase
from mdutils.tools.tools import Table
from mdutils.mdutils import MdUtils

__author__ = 'didix21'
__project__ = 'MdUtils'

class TestTable(TestCase):
def test_create_table(self):
md_file = MdUtils("file_name")
table = Table()
result_table = '\n|**Test**|**Descripción**|**Estado**|\n| :---: | :---: | :---: ' \
'|\n|Test 1|Carga de configuración correcta|<font color="green"> OK </font>|\n' \
'|Test 2|Lectura de Configuración|<font color="red"> NOK </font>|\n' \
'|Test 3|Lectura de Soporte|<font color="green"> OK </font>|\n' \
'|Test 4|Modificación de entradas y lectura de salidas de cantón|<font color="green"> ' \
'OK </font>|'\
'\n|Test 5|Lectura de estados de Pedal de Rearme y Aviso|<font color="green"> OK </font>|\n' \
'|Test 6|Actualización de datos de unidades de vía|<font color="green"> OK </font>|\n' \
'|Test 7|Fallos en carga de configuración - Campo IdApp Erróneo|<font color="green"> ' \
'OK </font>|' \
'\n' \
'|Test 8|Fallos en carga de configuración - Campo VersTAbla Erróneo' \
'|<font color="red"> NOK </font>|'\
'\n|Test 9|Fallos en carga de configuración - Campo IdUc Erróneo|<font color="red"> ' \
'NOK </font>|' \
'\n|Test 10|Fallos en carga de configuración - Campo Addresses Erróneo' \
'|<font color="red"> NOK </font>|\n' \
'|Test 11|Fallos en carga de configuración - Campo NumTc Erróneo' \
'|<font color="red"> NOK </font>|\n' \
'|Test 12|Fallos en carga de configuración - Campo NumUv Erróneo' \
'|<font color="red"> NOK </font>|\n' \
'|Test 13|Fallos en carga de configuración - Campo CRC Erróneo|<font color="red"> NOK </font>|\n'

text_array = ['**Test**', '**Descripción**', '**Estado**',
'Test 1', 'Carga de configuración correcta', md_file.textUtils.text_color("OK", 'green'),
'Test 2', 'Lectura de Configuración', md_file.textUtils.text_color("NOK", 'red'),
'Test 3', 'Lectura de Soporte', md_file.textUtils.text_color("OK", 'green'),
'Test 4', 'Modificación de entradas y lectura de salidas de cantón',
md_file.textUtils.text_color("OK", 'green'),
'Test 5', 'Lectura de estados de Pedal de Rearme y Aviso',
md_file.textUtils.text_color("OK", 'green'),
'Test 6', 'Actualización de datos de unidades de vía',
md_file.textUtils.text_color("OK", 'green'),
'Test 7', 'Fallos en carga de configuración - Campo IdApp Erróneo',
md_file.textUtils.text_color("OK", 'green'),
'Test 8', 'Fallos en carga de configuración - Campo VersTAbla Erróneo',
md_file.textUtils.text_color("NOK", 'red'),
'Test 9', 'Fallos en carga de configuración - Campo IdUc Erróneo',
md_file.textUtils.text_color("NOK", 'red'),
'Test 10', 'Fallos en carga de configuración - Campo Addresses Erróneo',
md_file.textUtils.text_color("NOK", 'red'),
'Test 11', 'Fallos en carga de configuración - Campo NumTc Erróneo',
md_file.textUtils.text_color("NOK", 'red'),
'Test 12', 'Fallos en carga de configuración - Campo NumUv Erróneo',
md_file.textUtils.text_color("NOK", 'red'),
'Test 13', 'Fallos en carga de configuración - Campo CRC Erróneo',
md_file.textUtils.text_color("NOK", 'red')]

self.assertEqual(table.create_table(columns=3, rows=13, text=text_array), result_table)

20 changes: 20 additions & 0 deletions Test/test_tools/test_tableOfContents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from unittest import TestCase
from mdutils.tools.tools import TableOfContents

__author__ = 'didix21'
__project__ = 'MdUtils'

class TestTableOfContents(TestCase):

def test_create_table_of_contents(self):
array_of_contents = ['Results Tests', [], 'Test Details', ['Test 1', [], 'Test 2', [],
'Test 3', [], 'Test 4', []]]
result = '\n* [Results Tests](#results-tests)\n' \
'* [Test Details](#test-details)\n\t' \
'* [Test 1](#test-1)\n\t' \
'* [Test 2](#test-2)\n\t' \
'* [Test 3](#test-3)\n\t' \
'* [Test 4](#test-4)\n'

table_of_contents = TableOfContents()
self.assertEqual(table_of_contents.create_table_of_contents(array_of_contents, depth=2), result)
47 changes: 47 additions & 0 deletions Test/test_tools/test_textUtils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from unittest import TestCase
from mdutils.tools.tools import TextUtils

__author__ = 'didix21'
__project__ = 'MdUtils'

class TestTextUtils(TestCase):
def test_bold(self):
expects = '**Bold Example**'
self.assertEqual(TextUtils().bold('Bold Example'), expects)

def test_italics(self):
expects = '_Italics Example_'
self.assertEqual(TextUtils().italics('Italics Example'), expects)

def test_inline_code(self):
expects = '`Inline Code Example`'
self.assertEqual(TextUtils().inline_code('Inline Code Example'), expects)

def test_center_text(self):
expects = '<center>Text Center Alignment Example</center>'
self.assertEqual(TextUtils().center_text('Text Center Alignment Example'), expects)

def test_text_color(self):
expects = '<font color="red"> Red Color Example </font>'
self.assertEqual(TextUtils().text_color('Red Color Example', 'red'), expects)

def test_text_external_link(self):
text = 'Text Example'
link = 'https://link.example.org'
expects = '[' + text + '](' + link + ')'
self.assertEqual(TextUtils().text_external_link(text, link), expects)

def test_text_format(self):
color = 'red'
text = 'Text Format'
text_color = TextUtils().text_color(text, color)
text_color_center = TextUtils().center_text(text_color)
text_color_center_b = TextUtils().bold(text_color_center)
text_color_center_bc = TextUtils().inline_code(text_color_center_b)
text_color_center_bci = TextUtils().italics(text_color_center_bc)

expects = text_color_center_bci
obtains = TextUtils().text_format(text, bold_italics_code='bci', color='red', align='center')

self.assertEqual(obtains, expects)

10 changes: 10 additions & 0 deletions Testing_md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from mdutils.mdutils import MdUtils

md_file = MdUtils("Testing_md", title="Testing Tables")
text_array = ["Test", "Description", "State", "Test 1", "Carga de configuración correcta", "OK"]

md_file.create_md_file()
md_file.markdown_file.append_end('\n\n')
md_file.create_table(3, 3, text_array)


3 changes: 3 additions & 0 deletions mdutils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from mdutils.mdutils import MdUtils
from mdutils.fileutils import fileutils
from mdutils.tools import tools
1 change: 1 addition & 0 deletions mdutils/fileutils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from mdutils.fileutils.fileutils import MarkDownFile
74 changes: 74 additions & 0 deletions mdutils/fileutils/fileutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Python
#
# This module implements a main class that allows to create markdown files, write in them or read.
#
# This file is part of mdutils. https://github.com/didix21/mdutils
#
# (C) 2018 Dídac Coll
#
# SPDX-License-Identifier: BSD-3-Clause


class MarkDownFile(object):
"""MarkDownFile class creates a new file of MarkDown extension.

Features available are:
- Create a file.
- Rewrite all the file with new data.
- Write at the end of the file."""

def __init__(self, name=''):
"""Creates a markdown file if name is not empty."""
if name:
self.file_name = name + '.md'
self.file = open(self.file_name, 'w+', encoding='UTF-8')
self.file.close()

def rewrite_all_file(self, data):
"""Rewrite all the data of a Markdown file by ``data``.

:param data: is a string containing all the data that is written in the markdown file."""
with open(self.file_name, 'w', encoding='utf-8') as self.file:
self.file.write(data)

def append_end(self, data):
"""Write at the last position of a Markdown file.

:param data: is a string containing all the data that is written in the markdown file."""
with open(self.file_name, 'a', encoding='utf-8') as self.file:
self.file.write(data)

def append_after_second_line(self, data):
"""Write after the file's first line.

:param data: is a string containing all the data that is written in the markdown file."""
with open(self.file_name, 'r+', encoding='utf-8') as self.file:
file_data = self.file.read() # Save all the file's content
self.file.seek(0, 0) # Place file pointer at the beginning
first_line = self.file.readline() # Read the first line
second_line = self.file.readline() # Read the second line
self.file.seek(len(first_line + second_line), 0) # Place file pointer at the end of the first line
self.file.write(data) # Write data
self.file.write('\n' + file_data[len(first_line + second_line):])

@staticmethod
def read_file(file_name):
"""Read a Markdown file using a file name. Not necessary to put *.md extension.

:param file_name: Markdown file's name.
:type file_name: str
:return: return all file's data.
:rtype: str"""

if file_name.find('.md') == -1:
file_name += '.md'

with open(file_name, 'r', encoding='utf-8') as file:
file_data = file.read()

return file_data


if __name__ == '__main__':
new_file = MarkDownFile('Example')
new_file.rewrite_all_file(data="# Some Text Example")
Loading