Skip to content

Commit 92f31b5

Browse files
Refactor package structure: rename to md2all and update imports
1 parent 25b4b04 commit 92f31b5

9 files changed

Lines changed: 64 additions & 53 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# 📝 Mdconvertor Tools
1+
# 📝 md2all
22

33
A minimal Python package to convert Markdown files to clean, responsive **HTML** with **Tailwind CSS**, **MathJax**, and beautiful typography.
44

55
> Ideal for note-taking, documentation, and publishing markdown content as styled web pages.
66
7-
![PyPI](https://img.shields.io/pypi/v/mdconvertor-tools)
8-
![Python Version](https://img.shields.io/pypi/pyversions/mdconvertor-tools)
9-
![License](https://img.shields.io/github/license/codeperfectplus/mdconvertor-tools)
7+
![PyPI](https://img.shields.io/pypi/v/md2all)
8+
![Python Version](https://img.shields.io/pypi/pyversions/md2all)
9+
![License](https://img.shields.io/github/license/codeperfectplus/md2all)
1010

1111
---
1212

@@ -23,7 +23,7 @@ A minimal Python package to convert Markdown files to clean, responsive **HTML**
2323
## 📦 Installation
2424

2525
```bash
26-
pip install mdconvertor-tools
26+
pip install md2all
2727
```
2828

2929

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from mdconvertor_tools import transform
2+
from md2all import transform
33

44
md_path = "test.md"
55
transform(md_path, output_format="html")

md2all/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from md2all.md_to_html import transform
2+
3+
__all__ = [
4+
"transform",
5+
]
Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from bs4 import BeautifulSoup
77

88
ROOT_DIR = Path(__file__).resolve().parent
9-
print("Root Directory:", ROOT_DIR)
10-
# Get full path to user's home and centralized .lib directory
119
home_dir = os.path.expanduser("~")
1210
lib_dir = os.path.join(home_dir, ".lib")
1311

@@ -88,43 +86,44 @@ def read_markdown_file(file_path):
8886
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
8987
return f.read()
9088

91-
def transform(md_path, output_dir="", output_format=""):
92-
"""Convert Markdown text to HTML with Tailwind CSS classes and MathJax setup."""
93-
print("Processing Markdown file:", md_path)
89+
import os
90+
import shutil
91+
from pathlib import Path
92+
import markdown
93+
94+
def transform(md_path, output_dir="", output_format="pdf"):
95+
"""Convert Markdown to HTML (optionally PDF), save results in appropriate location."""
96+
# get full path if not absolute
97+
if not os.path.isabs(md_path):
98+
md_path = os.path.abspath(md_path)
9499
markdown_text = read_markdown_file(md_path)
95100
markdown_text = convert_latex_format(markdown_text)
96101

97-
if output_dir:
98-
setup_directory(output_dir)
99-
output_dir = os.path.join(output_dir, os.path.basename(md_path).replace(".md", f".{output_format}"))
100-
else:
101-
output_dir = md_path.replace(".md", f".{output_format}")
102+
# Prepare file names and paths
103+
base_name = os.path.basename(md_path).replace(".md", "")
104+
temp_html_path = os.path.join("/tmp", f"{base_name}.html")
105+
final_output_path = os.path.join(output_dir, f"{base_name}.{output_format}") if output_dir else md_path.replace(".md", f".{output_format}")
102106

103-
html_content = markdown.markdown(markdown_text, extensions=['md_in_html', 'fenced_code', 'codehilite', 'toc', 'attr_list'])
107+
# Convert to HTML content
108+
html_content = markdown.markdown(
109+
markdown_text,
110+
extensions=['md_in_html', 'fenced_code', 'codehilite', 'toc', 'attr_list']
111+
)
104112
html_content = modify_classes(html_content)
105-
106-
html_template = """
113+
114+
# Inject into template
115+
html_template = f"""
107116
<!DOCTYPE html>
108117
<html lang="en" class="scroll-smooth bg-gray-50 text-gray-900 antialiased">
109118
<head>
110119
<meta charset="UTF-8">
111120
<meta name="viewport" content="width=device-width, initial-scale=1.0">
112-
113-
<title>{title}</title>
114-
115-
<!-- Tailwind CSS -->
116-
<link href="{centralized_tailwind_path}" rel="stylesheet">
117-
118-
<!-- MathJax -->
119-
<script type="text/javascript" id="MathJax-script" async
120-
src="{centralized_mathjax_path}"></script>
121-
122-
<!-- Custom CSS -->
123-
<link rel="stylesheet" href="{centralized_css_path}" />
121+
<title>{base_name}</title>
122+
<link href="{Path(setup_tailwind()).as_uri()}" rel="stylesheet">
123+
<script type="text/javascript" id="MathJax-script" async src="{Path(setup_mathjax()).as_uri()}"></script>
124+
<link rel="stylesheet" href="{Path(setup_custom_css()).as_uri()}" />
124125
</head>
125126
<body for="html-export" class="min-h-screen flex flex-col justify-between">
126-
127-
<!-- Main content -->
128127
<main class="flex-1">
129128
<div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8 prose prose-lg prose-slate">
130129
{html_content}
@@ -133,13 +132,25 @@ def transform(md_path, output_dir="", output_format=""):
133132
</body>
134133
</html>
135134
"""
136-
137-
html_template = html_template.replace("{title}", "Markdown to HTML Conversion")
138-
html_template = html_template.replace("{html_content}", html_content)
139-
html_template = html_template.replace("{centralized_mathjax_path}", Path(setup_mathjax()).as_uri())
140-
html_template = html_template.replace("{centralized_css_path}", Path(setup_custom_css()).as_uri())
141-
html_template = html_template.replace("{centralized_tailwind_path}", Path(setup_tailwind()).as_uri())
142135

143-
144-
with open(output_dir, "w", encoding="utf-8") as f:
136+
# Save temporary HTML to /tmp
137+
with open(temp_html_path, "w", encoding="utf-8") as f:
145138
f.write(html_template)
139+
140+
# If output format is .html, copy to output directory
141+
if output_format == ".html":
142+
if output_dir:
143+
setup_directory(output_dir)
144+
shutil.copy(temp_html_path, final_output_path)
145+
else:
146+
shutil.copy(temp_html_path, final_output_path)
147+
148+
# If output format is .pdf, delegate to PDF converter
149+
elif output_format == ".pdf":
150+
if output_dir:
151+
setup_directory(output_dir)
152+
# Here, you'd use `temp_html_path` for PDF conversion
153+
# and save the PDF to `final_output_path`
154+
pass # Replace with PDF conversion logic
155+
156+
return final_output_path # Optional: return for chaining or logging

mdconvertor_tools/__init__.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

setup.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@
1111

1212
# Setting up the package
1313
setuptools.setup(
14-
name="mdconvertor-tools",
15-
version="0.0.5",
14+
name="md2all",
15+
version="0.0.2",
1616
author="Deepak Raj",
1717
author_email="deepak008@live.com",
1818
description="convertor is a simple and easy to use library for converting markdown files to various formats.",
1919
long_description=long_description,
2020
long_description_content_type="text/markdown",
21-
url="https://github.com/codeperfectplus/mdconvertor-tools",
22-
data_files=[('assets', glob('mdconvertor_tools/libs/*'))],
21+
url="https://github.com/codeperfectplus/md2all",
22+
data_files=[('assets', glob('md2all/libs/*'))],
2323
keywords=[
2424

2525
],
2626
install_requires=requirements,
2727
packages=setuptools.find_packages(),
2828
project_urls={
29-
"Documentation": "https://mdconvertor-tools.readthedocs.io/en/latest/",
30-
"Source": "https://github.com/codeperfectplus/mdconvertor-tools",
31-
"Tracker": "https://github.com/codeperfectplus/mdconvertor-tools/issues"
29+
"Documentation": "https://md2all.readthedocs.io/en/latest/",
30+
"Source": "https://github.com/codeperfectplus/md2all",
31+
"Tracker": "https://github.com/codeperfectplus/md2all/issues"
3232
},
3333
classifiers=[
3434
"Development Status :: 5 - Production/Stable",

0 commit comments

Comments
 (0)