Skip to content

Commit 16f8f52

Browse files
authored
feat: add CSS to HTML template (#12)
1 parent 9c8312f commit 16f8f52

8 files changed

+70
-27
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ __pycache__/
88

99
.idea/
1010

11+
src/slate3k/
12+
1113
# Distribution / packaging
1214
.Python
1315
build/

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ $ pip install pytest
5757
$ pytest tests/
5858

5959
# Run package locally
60-
$ python -m scripts.main.py [-s] [-o] [-h] input_directory
60+
$ python -m scripts.main [-s] [-o] [-h] input_directory
6161
```
6262

6363
**Recommandations**

pyproject.toml

Whitespace-only changes.

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
-e git+https://github.com/Wazzabeee/slate3k#egg=slate3k
12
beautifulsoup4==4.10.0
23
nltk==3.6.6
34
odfpy==1.4.1
45
pdfplumber==0.5.28
5-
slate3k==0.5.3
66
tabulate==0.8.9

scripts/html_utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ def writing_results(dir_name: str) -> str:
7474
def get_color_from_similarity(similarity_score: float) -> str:
7575
"""Return css style according to similarity score"""
7676

77-
if float(similarity_score) > 15:
77+
if similarity_score > 15:
7878
return "#990033; font-weight: bold"
79-
if float(similarity_score) > 10:
79+
if similarity_score > 10:
8080
return "#ff6600"
81-
if float(similarity_score) > 5:
81+
if similarity_score > 5:
8282
return "#ffcc00"
8383

8484
return "green"

scripts/html_writing.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
"""
99

10-
from os import fsync, rename, path
10+
from os import fsync, path
1111
from random import randint
1212
from shutil import copy
1313
from typing import Any, List
@@ -43,7 +43,7 @@ def add_links_to_html_table(html_path: str) -> None:
4343
"a",
4444
href="file:///" + html_path.replace("_results", str(file_ind)),
4545
target="_blank",
46-
style="color:" + get_color_from_similarity(td_tag.text),
46+
style="color:" + get_color_from_similarity(float(td_tag.text)),
4747
)
4848

4949
td_tag.string.wrap(tmp) # We wrap the td string between the hyperlink
@@ -114,15 +114,16 @@ def get_span_blocks(bs_obj: Bs, text1: list, text2: list, block_size: int) -> li
114114

115115
def papers_comparison(save_dir: str, ind: int, text1: list, text2: list, filenames: tuple, block_size: int) -> None:
116116
"""Write to HTML file texts that have been compared with highlighted similar blocks"""
117-
118-
copy(path.join("templates", "template.html"), save_dir) # Copy comparison template to curr dir
117+
template_path = path.join("templates", "template.html")
119118
comp_path = path.join(save_dir, str(ind) + ".html")
120-
rename(path.join(save_dir, "template.html"), comp_path)
119+
120+
# Copy the template to the save directory under a new name
121+
copy(template_path, comp_path)
121122

122123
with open(comp_path, encoding="utf-8") as html:
123124
soup = Bs(html, "html.parser")
124125
res = get_span_blocks(soup, text1, text2, block_size)
125-
blocks = soup.findAll(attrs={"class": "block"})
126+
blocks = [soup.find(id="leftContent"), soup.find(id="rightContent")]
126127

127128
# Append filename tags and span tags to html
128129
for i, filename in enumerate(filenames):
@@ -132,6 +133,7 @@ def papers_comparison(save_dir: str, ind: int, text1: list, text2: list, filenam
132133
for tag in res[i]:
133134
blocks[i].append(tag)
134135

136+
# Write the modified content back to the file
135137
with open(comp_path, "wb") as f_output:
136138
f_output.write(soup.prettify("utf-8"))
137139

setup.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ disable=C0103,C0114,R0913,R0914,C0200,C0301
44
[pep8]
55
max-line-length=120
66
ignore=E121,E123,E126,E226,E24,E704,E203,W503
7-
exclude=venv,test_env,test_venv
7+
exclude=venv,test_env,test_venv,slate3k
88

99
[flake8]
1010
max-line-length=120
1111
ignore=E121,E123,E126,E226,E24,E704,E203,W503
12-
exclude=venv,test_env,test_venv
12+
exclude=venv,test_env,test_venv,slate3k

templates/template.html

+53-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,54 @@
1-
<html>
2-
<head>
3-
<title>
4-
</title>
5-
</head>
6-
<body>
7-
<div style="width: 100%; overflow: hidden;">
8-
9-
<div style="width: 46%; float: left;" class="block"> </div>
10-
11-
<div style="margin-left: 50%;" class="block"> </div>
12-
13-
</div>
14-
</body>
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Plagiarism Detection Results</title>
7+
<style>
8+
body, html {
9+
margin: 0;
10+
padding: 0;
11+
font-family: Arial, sans-serif;
12+
}
13+
14+
.container {
15+
display: flex;
16+
justify-content: space-between;
17+
padding: 20px;
18+
}
19+
20+
.content {
21+
width: 48%;
22+
border: 1px solid #ddd;
23+
padding: 10px;
24+
overflow: auto;
25+
height: 90vh;
26+
}
27+
28+
h3 {
29+
color: #333;
30+
border-bottom: 1px solid #ddd;
31+
padding-bottom: 5px;
32+
}
33+
34+
span {
35+
display: block;
36+
}
37+
38+
a {
39+
color: #06c;
40+
text-decoration: none;
41+
}
42+
43+
a:hover {
44+
text-decoration: underline;
45+
}
46+
</style>
47+
</head>
48+
<body>
49+
<div class="container">
50+
<div class="content" id="leftContent"></div>
51+
<div class="content" id="rightContent"></div>
52+
</div>
53+
</body>
1554
</html>

0 commit comments

Comments
 (0)