Skip to content

Commit c3adaee

Browse files
committed
all the required program files for uploaded for markdown Viewer
1 parent b527368 commit c3adaee

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

markdownViewer/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+
```

markdownViewer/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

markdownViewer/markdown_viewer.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from tkinter import *
2+
from tkinter import font, filedialog, messagebox as mbox
3+
from markdown2 import Markdown
4+
from tkhtmlview import HTMLLabel
5+
#
6+
#python3 -m pip install --upgrade pip
7+
#python3 -m pip install --upgrade Pillow
8+
#tkhtmlview
9+
10+
11+
class Window(Frame):
12+
def __init__(self,master = None):
13+
Frame.__init__(self,master)
14+
self.master = master
15+
self.font = font.Font(family = "Helvetica", size=14)
16+
self.init_window()
17+
18+
def openfile(self):
19+
filename = filedialog.askopenfilename(filetypes=(("Markdown File", "*.md , *.mdown , *.markdown"),
20+
("Text file","*.txt"),
21+
("All files","*.*")))
22+
if filename:
23+
try:
24+
md2html = Markdown()
25+
self.outputbox.set_html(md2html.convert(open(filename,"r").read()))
26+
except:
27+
mbox.showerror("Error opening file","The selected file cannot be opened !".format(filename))
28+
29+
30+
def init_window(self):
31+
self.master.title("Mardown Viewer")
32+
self.pack(fill=BOTH, expand=1)
33+
34+
self.mainmenu = Menu(self)
35+
self.filemenu = 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", html="<h1>Welcome</h1>")
43+
self.outputbox.pack(fill=BOTH, expand=1, side=RIGHT)
44+
self.outputbox.fit_height()
45+
46+
47+
root = Tk()
48+
root.geometry("750x600")
49+
app = Window(root)
50+
app.mainloop()
51+
52+

markdownViewer/requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
certifi==2021.5.30
2+
charset-normalizer==2.0.6
3+
idna==3.2
4+
markdown2==2.4.1
5+
Pillow==8.3.2
6+
requests==2.26.0
7+
tkhtmlview==0.1.0.post1
8+
urllib3==1.26.7

0 commit comments

Comments
 (0)