import bbcode # init parser parser = bbcode.Parser() parser.add_simple_formatter('hr', '
', standalone=True) parser.add_simple_formatter('hl', '%(value)s') parser.add_simple_formatter('sub', '%(value)s') parser.add_simple_formatter('sup', '%(value)s') parser.add_simple_formatter( 'iframe', '') parser.add_simple_formatter( 'showhide', '--- 隐藏内容 ---
%(value)s
----------------') def render_color(tag_name, value, options, parent, context): colors = "#0099ff" if 'color' in options: colors = options['color'] return f'{value}' def render_bgcolor(tag_name, value, options, parent, context): colors = "#0099ff" if 'bgcolor' in options: colors = options['bgcolor'] return f'{value}' def render_size(tag_name, value, options, parent, context): if 'size' in options: sizes = options['size'] else: return value return f'{value}' parser.add_formatter("color", render_color) parser.add_formatter("bgcolor", render_bgcolor) parser.add_formatter("size", render_size)