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

View File

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

View File

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

View File

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

View File

@ -4,6 +4,7 @@ import re
import os import os
import pathlib import pathlib
import markdown import markdown
from bs4 import BeautifulSoup
from django.db import models from django.db import models
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from start.models import Keyword, Searchable from start.models import Keyword, Searchable
@ -111,6 +112,22 @@ class BlogPost(Searchable):
# redundand vvvv # redundand vvvv
self.save() 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): def sync_file(self):
""" """
generate an article fromm it's original markdown file generate an article fromm it's original markdown file
@ -155,12 +172,12 @@ class BlogPost(Searchable):
self.title_en = data['lang'][lang]["title"] self.title_en = data['lang'][lang]["title"]
self.subtitle_en = data['lang'][lang]["subtitle"] self.subtitle_en = data['lang'][lang]["subtitle"]
self.desc_en = data['lang'][lang]["desc"] self.desc_en = data['lang'][lang]["desc"]
self.body_en = MD.convert(body) self.body_en = BlogPost.__patch_html(MD.convert(body))
case "de": case "de":
self.title_de = data['lang'][lang]["title"] self.title_de = data['lang'][lang]["title"]
self.subtitle_de = data['lang'][lang]["subtitle"] self.subtitle_de = data['lang'][lang]["subtitle"]
self.desc_de = data['lang'][lang]["desc"] self.desc_de = data['lang'][lang]["desc"]
self.body_de = MD.convert(body) self.body_de = BlogPost.__patch_html(MD.convert(body))
case _: case _:
logger.error( logger.error(
f"unknown language '{lang}' in meta file for '{self}'") f"unknown language '{lang}' in meta file for '{self}'")