ezKit 1.11.8__tar.gz → 1.11.10__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ezKit
3
- Version: 1.11.8
3
+ Version: 1.11.10
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -3,9 +3,11 @@ import csv
3
3
  import hashlib
4
4
  import json
5
5
  import os
6
+ import re
6
7
  import subprocess
7
8
  import time
8
9
  import tomllib
10
+ from ast import literal_eval
9
11
  from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
10
12
  from copy import deepcopy
11
13
  from datetime import date, datetime, timedelta, timezone
@@ -16,6 +18,7 @@ from typing import Any, Callable
16
18
  from urllib.parse import ParseResult, urlparse
17
19
  from uuid import uuid4
18
20
 
21
+ import markdown
19
22
  from loguru import logger
20
23
 
21
24
  # --------------------------------------------------------------------------------------------------
@@ -73,11 +76,11 @@ def check_arguments(data: list) -> bool:
73
76
 
74
77
  try:
75
78
  if not isTrue(data, list):
76
- logger.error(f"argument type error: data {type(data)}")
79
+ logger.error(f"argument error: data {type(data)}")
77
80
  return False
78
- for arg, arg_type, arg_name in data:
81
+ for arg, arg_type, info in data:
79
82
  if not isTrue(arg, arg_type):
80
- logger.error(f"argument type error: {arg_name} {type(arg)}")
83
+ logger.error(f"argument error: {info} {type(arg)}")
81
84
  return False
82
85
  return True
83
86
  except Exception as e:
@@ -1440,3 +1443,55 @@ def url_parse(
1440
1443
  # logger.exception(exception)
1441
1444
  # else:
1442
1445
  # logger.error(exception)
1446
+
1447
+
1448
+ # --------------------------------------------------------------------------------------------------
1449
+
1450
+
1451
+ def markdown_to_html(markdown_file: str, html_file: str, title: str) -> bool:
1452
+
1453
+ info: str = "将 Markdown 转换为 HTML"
1454
+
1455
+ try:
1456
+
1457
+ logger.info(f"{info} [开始]")
1458
+
1459
+ if not check_arguments([
1460
+ (markdown_file, str, "markdown_to_html -> markdown_file"),
1461
+ (html_file, str, "markdown_to_html -> html_file"),
1462
+ (title, str, "markdown_to_html -> title"),
1463
+ ]):
1464
+ return False
1465
+
1466
+ # 读取 HTML模版 文件
1467
+ logger.info(f"{info} [读取 HTML模版 文件]")
1468
+ html_template_file = f"{current_dir(__file__)}/markdown_to_html.template"
1469
+ with open(html_template_file, "r", encoding="utf-8") as _:
1470
+ html_template = _.read()
1471
+
1472
+ # 读取 Markdown 文件
1473
+ logger.info(f"{info} [读取 Markdown 文件: {markdown_file}]")
1474
+ with open(markdown_file, "r", encoding="utf-8") as _:
1475
+ markdown_content = _.read()
1476
+
1477
+ # 将 Markdown 转换为 HTML
1478
+ logger.info(f"{info} [将 Markdown 转换为 HTML]")
1479
+ html_body = markdown.markdown(markdown_content, extensions=['tables'])
1480
+
1481
+ # 构造完整的 HTML
1482
+ logger.info(f"{info} [构造完整的 HTML]")
1483
+ html_content = re.sub(r"\{title\}", title, html_template)
1484
+ html_content = re.sub(r"\{body\}", html_body, html_content)
1485
+
1486
+ # 保存为 HTML 文件
1487
+ logger.info(f"{info} [保存为 HTML 文件: {html_file}]")
1488
+ with open(html_file, "w", encoding='utf-8') as _:
1489
+ _.write(html_content)
1490
+
1491
+ logger.success(f"{info} [成功]")
1492
+ return True
1493
+
1494
+ except Exception as e:
1495
+ logger.error(f"{info} [错误]")
1496
+ logger.error(e)
1497
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ezKit
3
- Version: 1.11.8
3
+ Version: 1.11.10
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -3,7 +3,7 @@ from setuptools import find_packages, setup
3
3
 
4
4
  setup(
5
5
  name='ezKit',
6
- version='1.11.8',
6
+ version='1.11.10',
7
7
  author='septvean',
8
8
  author_email='septvean@gmail.com',
9
9
  description='Easy Kit',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes