Skip to content

Commit

Permalink
Enable TOC plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusznowakdev committed May 18, 2024
1 parent cacf77f commit 0491806
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 105 deletions.
16 changes: 15 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import click
from jinja2 import Environment, FileSystemLoader
from mistune import create_markdown
from mistune.directives import RSTDirective, TableOfContents
from mistune.plugins.formatting import strikethrough, superscript
from mistune.plugins.table import table
from mistune.renderers.html import HTMLRenderer
from mistune.util import escape, safe_entity, striptags
from PIL import Image
from slugify import slugify
from yaml import safe_load

RE_FRONTMATTER = re.compile(
Expand Down Expand Up @@ -69,6 +73,11 @@ def image(self, text, url, title=None):
return "</p><figure>" + s + "</figure><p>"


class CustomTableOfContents(TableOfContents):
def generate_heading_id(self, token, index):
return slugify(token["text"])


def get_template(template_file):
env = Environment(
loader=FileSystemLoader(template_file.parent),
Expand Down Expand Up @@ -168,7 +177,12 @@ def convert_png_jpg_to_webp(img_file):
def transform_pages(site):
markdown = create_markdown(
renderer=CustomRenderer(escape=False),
plugins=("strikethrough", "superscript", "table"),
plugins=(
RSTDirective([CustomTableOfContents()]),
strikethrough,
superscript,
table
),
)

for page in site.pages:
Expand Down
Loading

0 comments on commit 0491806

Please sign in to comment.