forked from rDrama/rDrama
sdf
parent
5dcad173a5
commit
143019a6ec
|
@ -5,14 +5,13 @@ from flask import g
|
||||||
from .markdown import *
|
from .markdown import *
|
||||||
from .sanitize import *
|
from .sanitize import *
|
||||||
from .const import *
|
from .const import *
|
||||||
from mistletoe.html_renderer import HTMLRenderer
|
|
||||||
|
|
||||||
def create_comment(text, autojanny=False):
|
def create_comment(text, autojanny=False):
|
||||||
if autojanny: author_id = AUTOJANNY_ID
|
if autojanny: author_id = AUTOJANNY_ID
|
||||||
else: author_id = NOTIFICATIONS_ID
|
else: author_id = NOTIFICATIONS_ID
|
||||||
|
|
||||||
text = text.replace('r/', 'r\/').replace('u/', 'u\/')
|
text = text.replace('r/', 'r\/').replace('u/', 'u\/')
|
||||||
text_html = sanitize(HTMLRenderer().render(mistletoe.Document(text)))
|
text_html = sanitize(Renderer2().render(mistletoe.Document(text)))
|
||||||
new_comment = Comment(author_id=author_id,
|
new_comment = Comment(author_id=author_id,
|
||||||
parent_submission=None,
|
parent_submission=None,
|
||||||
distinguish_level=6,
|
distinguish_level=6,
|
||||||
|
|
|
@ -120,4 +120,12 @@ class Renderer(HTMLRenderer):
|
||||||
def render_redditor_mention(self, token):
|
def render_redditor_mention(self, token):
|
||||||
space = token.target[0]
|
space = token.target[0]
|
||||||
target = token.target[1]
|
target = token.target[1]
|
||||||
return f'{space}<a href="https://old.reddit.com/u/{target}" rel="nofollow noopener noreferrer" class="d-inline-block">u/{target}</a>'
|
return f'{space}<a href="https://old.reddit.com/u/{target}" rel="nofollow noopener noreferrer" class="d-inline-block">u/{target}</a>'
|
||||||
|
|
||||||
|
class Renderer2(HTMLRenderer):
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
for i in kwargs:
|
||||||
|
self.__dict__[i] = kwargs[i]
|
Loading…
Reference in New Issue