Add center tag

This commit is contained in:
Bad Manners 2024-02-28 09:47:57 -03:00
parent 5abd2ae86b
commit 93fb55b53e
7 changed files with 24 additions and 6 deletions

View file

@ -24,6 +24,7 @@ DESCRIPTION_GRAMMAR = r"""
document: b_tag
| i_tag
| u_tag
| center_tag
| url_tag
| self_tag
| if_tag
@ -34,6 +35,7 @@ DESCRIPTION_GRAMMAR = r"""
b_tag: "[b]" [document_list] "[/b]"
i_tag: "[i]" [document_list] "[/i]"
u_tag: "[u]" [document_list] "[/u]"
center_tag: "[center]" [document_list] "[/center]"
url_tag: "[url" ["=" [URL]] "]" [document_list] "[/url]"
self_tag: "[self][/self]"
@ -156,6 +158,9 @@ class UploadTransformer(lark.Transformer):
def u_tag(self, _):
raise NotImplementedError('UploadTransformer.u_tag is abstract')
def center_tag(self, _):
raise NotImplementedError('UploadTransformer.center_tag is abstract')
def url_tag(self, _):
raise NotImplementedError('UploadTransformer.url_tag is abstract')
@ -261,6 +266,11 @@ class BbcodeTransformer(UploadTransformer):
return ''
return f'[u]{data[0]}[/u]'
def center_tag(self, data):
if data[0] is None or not data[0].strip():
return ''
return f'[center]{data[0]}[/center]'
def url_tag(self, data):
if data[0] is None or not data[0].strip():
return data[1].strip() if data[1] else ''
@ -297,6 +307,9 @@ class PlaintextTransformer(UploadTransformer):
def u_tag(self, data):
return str(data[0]) if data[0] else ''
def center_tag(self, data):
return str(data[0]) if data[0] else ''
def url_tag(self, data):
if data[0] is None or not data[0].strip():
return data[1] if data[1] and data[1].strip() else ''
@ -391,6 +404,11 @@ class WeasylTransformer(MarkdownTransformer):
def transformer_matches_site(site: str) -> bool:
return site == 'weasyl'
def center_tag(self, data):
if data[0] is None or not data[0].strip():
return ''
return f'<div class="align-center">{data[0]}</div>'
def user_tag_root(self, data):
user_data: SiteSwitchTag = data[0]
if user_data['weasyl']:

View file

@ -2,7 +2,7 @@
This is just a [u]simple[/u] test to show that basic functionality of [url=https://github.com/BadMannersXYZ/upload-generator]upload-generator[/url] [i]works[/i]. [if=define==test_parse_description]And this is running in a unit test.[/if][else]Why did you parse this outside of a unit test?![/else]
Reminder that I am [self][/self]!
[center]Reminder that I am [self][/self]![/center]
My friend: [user][sofurry=FriendSoFurry][fa=FriendFa][mastodon=@FriendMastodon@example.org]Friend123[/mastodon][/fa][/sofurry][/user][if=site in ib,aryion,weasyl] (I dunno his account here...)[/if]

View file

@ -2,7 +2,7 @@
This is just a [u]simple[/u] test to show that basic functionality of [url=https://github.com/BadMannersXYZ/upload-generator]upload-generator[/url] [i]works[/i]. And this is running in a unit test.
Reminder that I am :iconUserAryion:!
[center]Reminder that I am :iconUserAryion:![/center]
My friend: [url=https://example.org/@FriendMastodon]Friend123[/url] (I dunno his account here...)

View file

@ -2,7 +2,7 @@
This is just a [u]simple[/u] test to show that basic functionality of [url=https://github.com/BadMannersXYZ/upload-generator]upload-generator[/url] [i]works[/i]. And this is running in a unit test.
Reminder that I am :iconUserFuraffinity:!
[center]Reminder that I am :iconUserFuraffinity:![/center]
My friend: :iconFriendFa:

View file

@ -2,7 +2,7 @@
This is just a [u]simple[/u] test to show that basic functionality of [url=https://github.com/BadMannersXYZ/upload-generator]upload-generator[/url] [i]works[/i]. And this is running in a unit test.
Reminder that I am [iconname]UserInkbunny[/iconname]!
[center]Reminder that I am [iconname]UserInkbunny[/iconname]![/center]
My friend: [fa]FriendFa[/fa] (I dunno his account here...)

View file

@ -2,7 +2,7 @@
This is just a [u]simple[/u] test to show that basic functionality of [url=https://github.com/BadMannersXYZ/upload-generator]upload-generator[/url] [i]works[/i]. And this is running in a unit test.
Reminder that I am :iconUserSoFurry:!
[center]Reminder that I am :iconUserSoFurry:![/center]
My friend: :iconFriendSoFurry:

View file

@ -2,7 +2,7 @@
This is just a <u>simple</u> test to show that basic functionality of [upload-generator](https://github.com/BadMannersXYZ/upload-generator) *works*. And this is running in a unit test.
Reminder that I am <!~UserWeasyl>!
<div class="align-center">Reminder that I am <!~UserWeasyl>!</div>
My friend: <fa:FriendFa> (I dunno his account here...)