added config for ignore-list (html parser)
This commit is contained in:
parent
af589847e7
commit
3607295b9e
@ -9,6 +9,8 @@ relative_css=["./style.css", "./timeline.css"]
|
||||
accepted_images= ["jpg", "JPG", "png", "PNG"]
|
||||
# true = add <p></p> tags to each line.
|
||||
tag_paragraphs=true
|
||||
# apply <p> tags even if a line contains the following
|
||||
inline_tags = ["i", "em", "b", "strong","u", "s", "a", "span"]
|
||||
# adds <br> or user defined string between each line
|
||||
# line_separator="<br>"
|
||||
format="""
|
||||
|
13
microblog.py
13
microblog.py
@ -56,18 +56,18 @@ def make_gallery(indices, w, conf=None):
|
||||
# apply basic HTML formatting - only div class here is gallery
|
||||
from html.parser import HTMLParser
|
||||
class My_Html_Parser(HTMLParser):
|
||||
def __init__(self):
|
||||
def __init__(self, ignore_list):
|
||||
super().__init__()
|
||||
self.stack = []
|
||||
self.completed_by = ""
|
||||
# ignore common inline tags
|
||||
self.ignore = ignore_list
|
||||
|
||||
def handle_starttag(self, tag, attrs):
|
||||
self.stack.append(tag)
|
||||
self.is_completed_by = ""
|
||||
|
||||
def handle_endtag(self, tag):
|
||||
# ignore common inline tags
|
||||
ignore = ["i", "em", "b", "strong","u", "s", "a", "span"]
|
||||
# remove an item == tag from the end of the list
|
||||
i = len(self.stack) - 1
|
||||
last = self.stack[i]
|
||||
@ -77,7 +77,7 @@ class My_Html_Parser(HTMLParser):
|
||||
break
|
||||
i -= 1
|
||||
last = self.stack[i]
|
||||
if self.stack == [] and tag not in ignore:
|
||||
if self.stack == [] and tag not in self.ignore:
|
||||
self.completed_by = "</%s>" % tag
|
||||
|
||||
from html import escape
|
||||
@ -127,8 +127,11 @@ def markup(message, config):
|
||||
output = []
|
||||
gallery = []
|
||||
ptags = config["tag_paragraphs"]
|
||||
ignore = []
|
||||
if "inline_tags" in config:
|
||||
ignore = config["inline_tags"]
|
||||
parser = My_Html_Parser(ignore)
|
||||
sep = ""
|
||||
parser = My_Html_Parser()
|
||||
if "line_separator" in config:
|
||||
sep = config["line_separator"]
|
||||
for line in message:
|
||||
|
Loading…
x
Reference in New Issue
Block a user