Skip to content

Commit 89ce782

Browse files
authored
Merge pull request #567 from kaliappan01/markdown_viewer
all the required program files for uploaded for markdown Viewer
2 parents a7ef7a2 + 1f63bfc commit 89ce782

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

markdown_viewer/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#Markdown Viewer
2+
3+
Markdown viewer using python tkinter library.
4+
5+
#modules used
6+
7+
- Tkinter
8+
- markdown2
9+
- tkhtmlview
10+
11+
12+
## Setup and activate virtual environment :
13+
For Unix based systems please execute the following command to create venv and install requirements.
14+
```
15+
make init
16+
source .venv/bin/activate
17+
```
18+
For Windows based system
19+
```
20+
pip install -r /path/to/requirements.txt
21+
```
22+
23+
## How to Use
24+
25+
```
26+
python3 markdown_viewer.py
27+
```

markdown_viewer/makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
VENV ?= .venv
2+
REQUIREMENTS_FILE ?= requirements.txt
3+
4+
init:
5+
python3 -m venv $(VENV)
6+
$(VENV)/bin/python -m pip install --upgrade pip
7+
if [ -f $(REQUIREMENTS_FILE) ]; \
8+
then $(VENV)/bin/python -m pip install -r $(REQUIREMENTS_FILE); \
9+
fi

markdown_viewer/markdown_viewer.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import tkinter as tk
2+
from tkinter import Tk
3+
from tkinter import font, filedialog, messagebox as mbox
4+
from markdown2 import Markdown
5+
from tkhtmlview import HTMLLabel
6+
7+
8+
class Window(tk.Frame):
9+
10+
def __init__(self, master=None):
11+
tk.Frame.__init__(self, master)
12+
self.master = master
13+
self.font = font.Font(family='Helvetica', size=14)
14+
self.init_window()
15+
16+
def openfile(self):
17+
filename = \
18+
filedialog.askopenfilename(filetypes=(('Markdown File',
19+
'*.md , *.mdown'),
20+
('Text file', '*.txt')))
21+
if filename:
22+
try:
23+
md2html = Markdown()
24+
self.outputbox.set_html(md2html.convert(open(filename,
25+
'r').read()))
26+
except Exception:
27+
mbox.showerror('Error opening file',
28+
'The selected file cannot be opened !')
29+
30+
def init_window(self):
31+
self.master.title('Mardown Viewer')
32+
self.pack(fill=tk.BOTH, expand=1)
33+
34+
self.mainmenu = tk.Menu(self)
35+
self.filemenu = tk.Menu(self.mainmenu)
36+
self.filemenu.add_command(label='Open', command=self.openfile)
37+
self.filemenu.add_separator()
38+
self.filemenu.add_command(label='Exit', command=self.quit)
39+
self.mainmenu.add_cascade(label='File', menu=self.filemenu)
40+
self.master.config(menu=self.mainmenu)
41+
42+
self.outputbox = HTMLLabel(self, width='1', background='white',
43+
html='<h1>Welcome</h1>')
44+
self.outputbox.pack(fill=tk.BOTH, expand=1, side=tk.RIGHT)
45+
self.outputbox.fit_height()
46+
47+
48+
root = Tk()
49+
root.geometry('750x600')
50+
app = Window(master=root)
51+
app.mainloop()

markdown_viewer/requirements.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
certifi==2021.5.30
2+
charset-normalizer==2.0.6
3+
flake8==3.9.2
4+
idna==3.2
5+
markdown2==2.4.1
6+
mccabe==0.6.1
7+
Pillow==8.3.2
8+
pycodestyle==2.7.0
9+
pyflakes==2.3.1
10+
requests==2.26.0
11+
tkhtmlview==0.1.0.post1
12+
urllib3==1.26.7

0 commit comments

Comments
 (0)