Commit 2f4f5d6d authored by ammongit's avatar ammongit

Use markdown module instead of a command.

parent a4746d34
## Blog
Contains blog entries, as well as a small "build" system to create HTML files.
Requires Python 3.5+, and [`markdown`](https://www.pell.portland.or.us/~orc/Code/discount/)
somewhere on your `$PATH`.
Requires Python 3.5+.
Setup:
```sh
......
......@@ -18,9 +18,9 @@ import argparse
import itertools
import os
import re
import subprocess
import sys
import markdown
import yaml
# Configurable constants
......@@ -37,6 +37,8 @@ POST_TEMPLATE_HTML_PATH = 'post-template.html'
INDEX_SIZE = 20
DATE_FORMAT = '%A, %B %-m %Y'
MARKDOWN_EXTENSIONS = ['extra', 'codehilite', 'nl2br', 'sane_lists', 'smarty']
# Other constants
MARKDOWN_REGEX = re.compile(r'(.*)\.(?:markdown|md)', re.IGNORECASE)
YAML_REGEX = re.compile(r'(.*)\.(?:yaml|yml)', re.IGNORECASE)
......@@ -89,8 +91,15 @@ class Post:
return max(cfg_mtime, md_mtime) > out_mtime
def generate(self):
# Convert Markdown
with open(self.markdown_path, 'r') as fh:
md_html = markdown.markdown(
fh.read(),
extensions=MARKDOWN_EXTENSIONS,
output_format='html5',
)
# Format HTML
md_html = subprocess.check_output(["markdown", self.markdown_path]).decode('utf-8')
kwargs = self.metadata_dict()
kwargs['content'] = md_html
html = POST_TEMPLATE_HTML.format(**kwargs)
......
......@@ -2,10 +2,10 @@
Lorem ipsum dolor sit amet, **consectetur adipiscing** elit. Fusce _sit_ amet rhoncus neque.
Nunc at finibus lacus. Nullam pretium massa non pulvinar convallis. Proin ac egestas enim.
Fusce eget:
* turpis eget
* velit tincidunt posuere
* nulla pharetra mi sit amet
* turpis malesuada
- turpis eget
- velit tincidunt posuere
- nulla pharetra mi sit amet
- turpis malesuada
[Morbi volutpat](https://example.com) at elit at lacinia. In _mattis_ mi sed ultrices rutrum.
Ut tempus, odio nec egestas laoreet, ex nisi congue est, a placerat ipsum quam nec nulla. Vestibulum mi odio, finibus eu felis vitae, mattis tincidunt leo. **Suspendisse** potenti. Nunc vel commodo elit. Nullam vestibulum nulla purus, sed laoreet leo commodo imperdiet. Etiam arcu tortor, interdum sed sapien quis, feugiat tempus quam.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment