path markdown html; table mod #35

Merged
PlexSheep merged 1 commits from blog-style into devel 2023-10-02 21:41:32 +02:00
4 changed files with 30 additions and 2 deletions
Showing only changes of commit 64f84d58bc - Show all commits

View File

@ -9,3 +9,4 @@ favicon>=0.7.0
markdown>=3.4.4
Pygments>=2.16.1
toml>=0.10
beautifulsoup4>=4.12.2

View File

@ -9,6 +9,11 @@ markdown rendering.
[TOC]
| very | important | table |
|--------|-----------|-----------|
| v | i | t |
| yes | super | important |
| really | really | really |
## Wait, but why?

View File

@ -8,6 +8,11 @@ markdown rendering.
[TOC]
| very | important | table |
|--------|-----------|-----------|
| v | i | t |
| yes | super | important |
| really | really | really |
## Wait, but why?

View File

@ -4,6 +4,7 @@ import re
import os
import pathlib
import markdown
from bs4 import BeautifulSoup
from django.db import models
from django.utils.translation import gettext as _
from start.models import Keyword, Searchable
@ -111,6 +112,22 @@ class BlogPost(Searchable):
# redundand vvvv
self.save()
@staticmethod
def __patch_html(html: str) -> str:
soup = BeautifulSoup(html)
# add bootstrap classes to regular tables
tables = soup.select("table")
for table in tables:
if 'class' in table.attrs and "codehilitetable" in table.attrs['class']:
# table has at least one class already AND
# this table is a codehighlighting table,
# not a regular one
continue
# set the bootstrap classes for tables
table.attrs['class'] = 'table table-striped border'
return soup.prettify()
def sync_file(self):
"""
generate an article fromm it's original markdown file
@ -155,12 +172,12 @@ class BlogPost(Searchable):
self.title_en = data['lang'][lang]["title"]
self.subtitle_en = data['lang'][lang]["subtitle"]
self.desc_en = data['lang'][lang]["desc"]
self.body_en = MD.convert(body)
self.body_en = BlogPost.__patch_html(MD.convert(body))
case "de":
self.title_de = data['lang'][lang]["title"]
self.subtitle_de = data['lang'][lang]["subtitle"]
self.desc_de = data['lang'][lang]["desc"]
self.body_de = MD.convert(body)
self.body_de = BlogPost.__patch_html(MD.convert(body))
case _:
logger.error(
f"unknown language '{lang}' in meta file for '{self}'")