Skip to content

Commit

Permalink
v0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
treatmesubj committed Jan 19, 2024
1 parent 502f8d7 commit 87ae1a9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 61 deletions.
119 changes: 60 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
# Python Markdown-to-HTML Server

It's the standard Python [http.server module](https://docs.python.org/3/library/http.server.html) but via [markdown-it-py](https://github.com/executablebooks/markdown-it-py), requested Markdown files are rendered and served as HTML

The `http.server` module's `SimpleHTTPRequestHandler` class is inherited by a new class with its `do_GET` method overridden. [beautifulsoup](https://pypi.org/project/beautifulsoup4/) and [html5lib](https://pypi.org/project/html5lib/) add `<html>`, `<head>`, & `<body>` elements and I insert a `<style>` element with some personally preferred CSS styling. Optionally, a custom CSS file can be used to style instead.

It makes for a simple way to write up some Markdown with a terminal & a web browser

**TIP**: In most browsers, keyboard shortcut `Ctrl+Shift+R` will refresh the page and ignore cache

## Installation
- from [PyPI](https://pypi.org/project/httpmdhtml/): `pip install httpmdhtml`
- from [GitHub](https://github.com/treatmesubj/python-md-to-html-server): `pip install "git+https://github.com/treatmesubj/python-md-to-html-server"`

## Usage
### Markdown-to-HTML Server
```
python -m httpmdhtml.server -b 127.0.0.1 -d . --css_file ../mystyle.css -l 5000
---
usage: server.py [-h] [--cgi] [--bind ADDRESS] [--directory DIRECTORY] [--css_file CSS_FILE]
[--live_md_rr LIVE_MD_RR]
[port]
positional arguments:
port Specify alternate port [default: 8000]
optional arguments:
-h, --help show this help message and exit
--cgi Run as CGI Server
--bind ADDRESS, -b ADDRESS
Specify alternate bind address [default: all interfaces]
--directory DIRECTORY, -d DIRECTORY
Specify alternative directory [default:current directory]
--css_file CSS_FILE css-file-path whose content will be written to the <style> element. Can be "none"; do not
use any css
--live_md_rr LIVE_MD_RR, -l LIVE_MD_RR
Continuous refresh rate of MD page, in ms. Respects cache
```

### Markdown-to-HTML Out-File
```
python -m httpmdhtml.md_to_html -i in_file.md -o out_file.html --encode_local_images
---
usage: md_to_html.py [-h] [--in_file_path IN_FILE_PATH] [--out_file_path OUT_FILE_PATH] [--encode_local_images]
[--css_file CSS_FILE]
optional arguments:
-h, --help show this help message and exit
--in_file_path IN_FILE_PATH, -i IN_FILE_PATH
in-file-path; your existing markdown file
--out_file_path OUT_FILE_PATH, -o OUT_FILE_PATH
out-file-path; your HTML file to be created
--encode_local_images, -e
in HTML, embed base64-encoded data of local images linked to in your markdown; remove
dependency on presence of external local images
--css_file CSS_FILE css-file-path whose content will be written to the <style> element. Can be "none"; do not
use any css
```
![](<./scrot.png>)
# Python Markdown-to-HTML Server

It's the standard Python [http.server module](https://docs.python.org/3/library/http.server.html) but via [markdown-it-py](https://github.com/executablebooks/markdown-it-py), requested Markdown files are rendered and served as HTML

The `http.server` module's `SimpleHTTPRequestHandler` class is inherited by a new class with its `do_GET` method overridden. [beautifulsoup](https://pypi.org/project/beautifulsoup4/) and [html5lib](https://pypi.org/project/html5lib/) add `<html>`, `<head>`, & `<body>` elements and I insert a `<style>` element with some personally preferred CSS styling. Optionally, a custom CSS file can be used to style instead.\
[highlightjs](https://highlightjs.org) adds syntax highlighting to code blocks.

It makes for a simple way to write up some Markdown with a terminal & a web browser

**TIP**: In most browsers, keyboard shortcut `Ctrl+Shift+R` will refresh the page and ignore cache

## Installation
- from [PyPI](https://pypi.org/project/httpmdhtml/): `pip install httpmdhtml`
- from [GitHub](https://github.com/treatmesubj/python-md-to-html-server): `pip install "git+https://github.com/treatmesubj/python-md-to-html-server"`

## Usage
### Markdown-to-HTML Server
```
python -m httpmdhtml.server -b 127.0.0.1 -d . --css_file ../mystyle.css -l 5000
---
usage: server.py [-h] [--cgi] [--bind ADDRESS] [--directory DIRECTORY] [--css_file CSS_FILE]
[--live_md_rr LIVE_MD_RR]
[port]
positional arguments:
port Specify alternate port [default: 8000]
optional arguments:
-h, --help show this help message and exit
--cgi Run as CGI Server
--bind ADDRESS, -b ADDRESS
Specify alternate bind address [default: all interfaces]
--directory DIRECTORY, -d DIRECTORY
Specify alternative directory [default:current directory]
--css_file CSS_FILE css-file-path whose content will be written to the <style> element. Can be "none"; do not
use any css
--live_md_rr LIVE_MD_RR, -l LIVE_MD_RR
Continuous refresh rate of MD page, in ms. Respects cache
```

### Markdown-to-HTML Out-File
```
python -m httpmdhtml.md_to_html -i in_file.md -o out_file.html --encode_local_images
---
usage: md_to_html.py [-h] [--in_file_path IN_FILE_PATH] [--out_file_path OUT_FILE_PATH] [--encode_local_images]
[--css_file CSS_FILE]
optional arguments:
-h, --help show this help message and exit
--in_file_path IN_FILE_PATH, -i IN_FILE_PATH
in-file-path; your existing markdown file
--out_file_path OUT_FILE_PATH, -o OUT_FILE_PATH
out-file-path; your HTML file to be created
--encode_local_images, -e
in HTML, embed base64-encoded data of local images linked to in your markdown; remove
dependency on presence of external local images
--css_file CSS_FILE css-file-path whose content will be written to the <style> element. Can be "none"; do not
use any css
```
![](<./skrot.png>)
Binary file removed scrot.png
Binary file not shown.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

setup(
name="httpmdhtml",
version="0.1.3",
version="0.1.4",
license="gpl-3.0",
author="John Hupperts",
author_email="[email protected]",
description="HTTP server that converts markdown to HTML",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/treatmesubj/python-md-to-html-server",
download_url="https://github.com/treatmesubj/python-md-to-html-server/archive/refs/tags/v0.1.3.tar.gz",
download_url="https://github.com/treatmesubj/python-md-to-html-server/archive/refs/tags/v0.1.4.tar.gz",
packages=["httpmdhtml"],
package_dir={"python-md-to-html-server": "httpmdhtml"},
project_urls={
Expand Down
Binary file added skrot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 87ae1a9

Please sign in to comment.