Skip to content

Commit ea54ac6

Browse files
committed
support pixelate bbcode
1 parent 8496273 commit ea54ac6

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

bb_codes.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,18 @@
4040
<replace_html_email><![CDATA[]]></replace_html_email>
4141
<replace_text><![CDATA[]]></replace_text>
4242
</bb_code>
43+
<bb_code bb_code_id="pixelate" bb_code_mode="replace" has_option="no" trim_lines_after="0" plain_children="0" disable_smilies="0" disable_nl2br="0" disable_autolink="0" allow_empty="0" allow_signature="1" editor_icon_type="fa" editor_icon_value="game-console-handheld" title="Pixelate">
44+
<desc><![CDATA[The image is scaled with an algorithm such as "nearest neighbor" that preserves contrast and edges in the image. Generally intended for upscaled pixel art or line drawings, no blurring or color smoothing occurs.]]></desc>
45+
<example><![CDATA[Using pixelate:
46+
47+
[pixelate][img alt="an image without anti-aliasing"]https://ectunnel.com/community/styles/default/xenforo/logoblue.gif[/img][/pixelate]
48+
49+
Normal:
50+
51+
[img alt="an image with anti-aliasing"]https://ectunnel.com/community/styles/default/xenforo/logoblue.gif[/img]]]></example>
52+
<output><![CDATA[]]></output>
53+
<replace_html><![CDATA[<span class="pixelate">{text}</span>]]></replace_html>
54+
<replace_html_email><![CDATA[]]></replace_html_email>
55+
<replace_text><![CDATA[]]></replace_text>
56+
</bb_code>
4357
</bb_codes>

src/md2bbcode/renderers/bbcode.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ def link(self, text: str, url: str, title=None) -> str:
5656

5757
def image(self, text: str, url: str, title=None) -> str:
5858
alt_text = f' alt="{text}"' if text else ''
59-
return f'[img{alt_text}]' + self.safe_url(url) + '[/img]'
59+
img_tag = f'[img{alt_text}]' + self.safe_url(url) + '[/img]'
60+
# Check if alt text starts with 'pixel' and treat it as pixel art
61+
if text and text.lower().startswith('pixel'):
62+
return f'[pixelate]{img_tag}[/pixelate]'
63+
return img_tag
6064

6165
def codespan(self, text: str) -> str:
6266
return '[icode]' + text + '[/icode]'

0 commit comments

Comments
 (0)