Discord does not support tables so we remove them
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
			
		||||
import urllib.parse
 | 
			
		||||
 | 
			
		||||
from markdownify import markdownify
 | 
			
		||||
from reader import Entry, Reader
 | 
			
		||||
 | 
			
		||||
from discord_rss_bot.filter.blacklist import has_black_tags, should_be_skipped
 | 
			
		||||
@@ -52,3 +53,8 @@ def entry_is_blacklisted(entry_to_check: Entry) -> bool:
 | 
			
		||||
 | 
			
		||||
    """
 | 
			
		||||
    return bool(has_black_tags(reader, entry_to_check.feed) and should_be_skipped(reader, entry_to_check))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def convert_to_md(thing: str) -> str:
 | 
			
		||||
    """Discord does not support tables so we need to remove them from the markdown."""
 | 
			
		||||
    return markdownify(thing, strip=["table", "thead", "tbody", "tr", "th", "td"])
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
from markdownify import markdownify
 | 
			
		||||
from reader import Entry, Feed, Reader, TagNotFoundError
 | 
			
		||||
 | 
			
		||||
from discord_rss_bot.custom_filters import convert_to_md
 | 
			
		||||
from discord_rss_bot.settings import get_reader
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -45,9 +45,9 @@ def replace_tags(feed: Feed, entry: Entry) -> str:
 | 
			
		||||
    summary = ""
 | 
			
		||||
    content = ""
 | 
			
		||||
    if entry.summary:
 | 
			
		||||
        summary: str = markdownify(entry.summary)
 | 
			
		||||
        summary: str = entry.summary
 | 
			
		||||
    if entry.content:
 | 
			
		||||
        content: str = markdownify(entry.content[0]["value"])
 | 
			
		||||
        content: str = entry.content[0]["value"]  # type: ignore
 | 
			
		||||
 | 
			
		||||
    list_of_replacements = [
 | 
			
		||||
        {"{{feed_author}}": feed.author},
 | 
			
		||||
@@ -64,16 +64,16 @@ def replace_tags(feed: Feed, entry: Entry) -> str:
 | 
			
		||||
        {"{{feed_version}}": feed.version},
 | 
			
		||||
        {"{{entry_added}}": entry.added},
 | 
			
		||||
        {"{{entry_author}}": entry.author},
 | 
			
		||||
        {"{{entry_content}}": content},
 | 
			
		||||
        {"{{entry_content_raw}}": entry.content[0]["value"]},
 | 
			
		||||
        {"{{entry_content}}": convert_to_md(content)},
 | 
			
		||||
        {"{{entry_content_raw}}": content},
 | 
			
		||||
        {"{{entry_id}}": entry.id},
 | 
			
		||||
        {"{{entry_important}}": str(entry.important)},
 | 
			
		||||
        {"{{entry_link}}": entry.link},
 | 
			
		||||
        {"{{entry_published}}": entry.published},
 | 
			
		||||
        {"{{entry_read}}": str(entry.read)},
 | 
			
		||||
        {"{{entry_read_modified}}": entry.read_modified},
 | 
			
		||||
        {"{{entry_summary}}": summary},
 | 
			
		||||
        {"{{entry_summary_raw}}": entry.summary},
 | 
			
		||||
        {"{{entry_summary}}": convert_to_md(summary)},
 | 
			
		||||
        {"{{entry_summary_raw}}": summary},
 | 
			
		||||
        {"{{entry_title}}": entry.title},
 | 
			
		||||
        {"{{entry_updated}}": entry.updated},
 | 
			
		||||
    ]
 | 
			
		||||
 
 | 
			
		||||
@@ -8,11 +8,10 @@ from fastapi import FastAPI, Form, Request
 | 
			
		||||
from fastapi.responses import HTMLResponse
 | 
			
		||||
from fastapi.staticfiles import StaticFiles
 | 
			
		||||
from fastapi.templating import Jinja2Templates
 | 
			
		||||
from markdownify import markdownify
 | 
			
		||||
from reader import Entry, EntryCounts, EntrySearchCounts, EntrySearchResult, Feed, FeedCounts, Reader, TagNotFoundError
 | 
			
		||||
from starlette.responses import RedirectResponse
 | 
			
		||||
 | 
			
		||||
from discord_rss_bot.custom_filters import encode_url, entry_is_blacklisted, entry_is_whitelisted
 | 
			
		||||
from discord_rss_bot.custom_filters import convert_to_md, encode_url, entry_is_blacklisted, entry_is_whitelisted
 | 
			
		||||
from discord_rss_bot.custom_message import get_custom_message
 | 
			
		||||
from discord_rss_bot.feeds import send_to_discord
 | 
			
		||||
from discord_rss_bot.filter.blacklist import get_blacklist_content, get_blacklist_summary, get_blacklist_title
 | 
			
		||||
@@ -31,7 +30,7 @@ reader: Reader = get_reader()
 | 
			
		||||
templates.env.filters["encode_url"] = encode_url
 | 
			
		||||
templates.env.filters["entry_is_whitelisted"] = entry_is_whitelisted
 | 
			
		||||
templates.env.filters["entry_is_blacklisted"] = entry_is_blacklisted
 | 
			
		||||
templates.env.filters["discord_markdown"] = markdownify
 | 
			
		||||
templates.env.filters["discord_markdown"] = convert_to_md
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.post("/add_webhook")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user