@@ -90,30 +90,30 @@ def html_to_bbcode(html: str) -> str:
9090 return ""
9191
9292 for linkusername in body .select ("a.linkusername" ):
93- linkusername .replaceWith (f"@{ linkusername .text .strip ()} " )
93+ linkusername .replace_with (f"@{ linkusername .text .strip ()} " )
9494
9595 for iconusername in body .select ("a.iconusername,a.usernameicon" ):
9696 username : str = iconusername .text .strip () or iconusername .attrs .get ('href' , '' ).strip ('/' ).split ('/' )[- 1 ]
9797 if icon := iconusername .select_one ("img" ):
9898 username = icon .attrs .get ('alt' , '' ).strip () or username
99- iconusername .replaceWith (f":icon{ username } :" if iconusername .text .strip () else f":{ username } icon:" )
99+ iconusername .replace_with (f":icon{ username } :" if iconusername .text .strip () else f":{ username } icon:" )
100100
101101 for img in body .select ("img" ):
102- img .replaceWith (f"[img={ img .attrs .get ('src' , '' )} /]" )
102+ img .replace_with (f"[img={ img .attrs .get ('src' , '' )} /]" )
103103
104104 for hr in body .select ("hr" ):
105- hr .replaceWith ("-----" )
105+ hr .replace_with ("-----" )
106106
107107 for smilie in body .select ("i.smilie" ):
108108 smilie_class : list [str ] = list (smilie .attrs .get ("class" , []))
109109 smilie_name : str = next (filter (lambda c : c not in ["smilie" , "" ], smilie_class ), "" )
110- smilie .replaceWith (f":{ smilie_name or 'smilie' } :" )
110+ smilie .replace_with (f":{ smilie_name or 'smilie' } :" )
111111
112112 for span in body .select ("span.bbcode[style*=color]" ):
113113 if m := match (r".*color: ?([^ ;]+).*" , span .attrs ["style" ]):
114- span .replaceWith (f"[color={ m [1 ]} ]" , * span .children , "[/color]" )
114+ span .replace_with (f"[color={ m [1 ]} ]" , * span .children , "[/color]" )
115115 else :
116- span .replaceWith (* span .children )
116+ span .replace_with (* span .children )
117117
118118 for nav_link in body .select ("span.parsed_nav_links" ):
119119 a_tags = nav_link .select ("a" )
@@ -123,37 +123,37 @@ def html_to_bbcode(html: str) -> str:
123123 a_prev = a_prev_tag .attrs .get ("href" , "" ).strip ("/" ).split ("/" )[- 1 ] if a_prev_tag else ""
124124 a_frst = a_frst_tag .attrs .get ("href" , "" ).strip ("/" ).split ("/" )[- 1 ] if a_frst_tag else ""
125125 a_next = a_next_tag .attrs .get ("href" , "" ).strip ("/" ).split ("/" )[- 1 ] if a_next_tag else ""
126- nav_link .replaceWith (f"[{ a_prev or '-' } ,{ a_frst or '-' } ,{ a_next or '-' } ]" )
126+ nav_link .replace_with (f"[{ a_prev or '-' } ,{ a_frst or '-' } ,{ a_next or '-' } ]" )
127127
128128 for a in body .select ("a.auto_link_shortened:not(.named_url), a.auto_link:not(.named_url)" ):
129- a .replaceWith (a .attrs .get ('href' , '' ))
129+ a .replace_with (a .attrs .get ('href' , '' ))
130130
131131 for a in body .select ("a" ):
132132 href_match : Optional [Match ] = relative_url .match (a .attrs .get ('href' , '' ))
133- a .replaceWith (
133+ a .replace_with (
134134 f"[url={ href_match [1 ] if href_match else a .attrs .get ('href' , '' )} ]" ,
135135 * a .children ,
136136 "[/url]"
137137 )
138138
139139 for yt in body .select ("iframe[src*='youtube.com/embed']" ):
140- yt .replaceWith (f"[yt]https://youtube.com/embed/{ yt .attrs .get ('src' , '' ).strip ('/' ).split ('/' )} [/yt]" )
140+ yt .replace_with (f"[yt]https://youtube.com/embed/{ yt .attrs .get ('src' , '' ).strip ('/' ).split ('/' )} [/yt]" )
141141
142142 for quote_name_tag in body .select ("span.bbcode.bbcode_quote > span.bbcode_quote_name" ):
143143 quote_author : str = quote_name_tag .text .strip ().removesuffix ('wrote:' ).strip ()
144144 quote_tag = quote_name_tag .parent
145145 if not quote_tag :
146- quote_name_tag .replaceWith (quote_author )
146+ quote_name_tag .replace_with (quote_author )
147147 continue
148148 quote_name_tag .decompose ()
149- quote_tag .replaceWith (
149+ quote_tag .replace_with (
150150 f"[quote{ ('=' + quote_author ) if quote_author else '' } ]" ,
151151 * quote_tag .children ,
152152 "[/quote]"
153153 )
154154
155155 for quote_tag in body .select ("span.bbcode.bbcode_quote" ):
156- quote_tag .replaceWith ("[quote]" , * quote_tag .children , "[/quote]" )
156+ quote_tag .replace_with ("[quote]" , * quote_tag .children , "[/quote]" )
157157
158158 for [selector , bbcode_tag ] in (
159159 ("i" , "i" ),
@@ -175,19 +175,19 @@ def html_to_bbcode(html: str) -> str:
175175 ("h6" , "h6" ),
176176 ):
177177 for tag in body .select (selector ):
178- tag .replaceWith (f"[{ bbcode_tag } ]" , * tag .children , f"[/{ bbcode_tag } ]" )
178+ tag .replace_with (f"[{ bbcode_tag } ]" , * tag .children , f"[/{ bbcode_tag } ]" )
179179
180180 for br in body .select ("br" ):
181- br .replaceWith ("\n " )
181+ br .replace_with ("\n " )
182182
183183 for p in body .select ("p" ):
184- p .replaceWith (* p .children )
184+ p .replace_with (* p .children )
185185
186186 for tag in body .select ("*" ):
187187 if not (div_class := tag .attrs .get ("class" , None )):
188- tag .replaceWith (f"[tag={ tag .name } ]" , * tag .children , "[/tag.{tag.name}]" )
188+ tag .replace_with (f"[tag={ tag .name } ]" , * tag .children , "[/tag.{tag.name}]" )
189189 else :
190- tag .replaceWith (
190+ tag .replace_with (
191191 f"[tag={ tag .name } .{ ' ' .join (div_class ) if isinstance (div_class , list ) else div_class } ]" ,
192192 * tag .children ,
193193 "[/tag]"
@@ -245,12 +245,12 @@ def parse_extra(page: BeautifulSoup) -> BeautifulSoup:
245245 if m_ := match (rf"(.*):({ '|' .join (smilie_icons )} ):(.*)" , child ):
246246 has_match = True
247247 child_new = Tag (name = "i" , attrs = {"class" : f"smilie { m_ [2 ]} " })
248- child .replaceWith (m_ [1 ], child_new , m_ [3 ])
248+ child .replace_with (m_ [1 ], child_new , m_ [3 ])
249249 elif m_ := match (r"(.*)(?:@([a-zA-Z0-9.~_-]+)|:link([a-zA-Z0-9.~_-]+):)(.*)" , child ):
250250 has_match = True
251251 child_new = Tag (name = "a" , attrs = {"class" : "linkusername" , "href" : f"/user/{ m_ [2 ] or m_ [3 ]} " })
252252 child_new .insert (0 , m_ [2 ] or m_ [3 ])
253- child .replaceWith (m_ [1 ], child_new , m_ [4 ])
253+ child .replace_with (m_ [1 ], child_new , m_ [4 ])
254254 elif m_ := match (r"(.*):(?:icon([a-zA-Z0-9.~_-]+)|([a-zA-Z0-9.~_-]+)icon):(.*)" , child ):
255255 has_match = True
256256 user : str = m_ [2 ] or m_ [3 ] or ""
@@ -265,7 +265,7 @@ def parse_extra(page: BeautifulSoup) -> BeautifulSoup:
265265 child_new .insert (0 , child_new_img )
266266 if m_ [2 ]:
267267 child_new .insert (1 , f"\xA0 { m_ [2 ]} " )
268- child .replaceWith (m_ [1 ], child_new , m_ [4 ])
268+ child .replace_with (m_ [1 ], child_new , m_ [4 ])
269269 elif m_ := match (r"(.*)\[ *(?:(\d+)|-)?, *(?:(\d+)|-)? *, *(?:(\d+)|-)? *](.*)" , child ):
270270 has_match = True
271271 child_new = Tag (name = "span" , attrs = {"class" : "parsed_nav_links" })
@@ -286,10 +286,10 @@ def parse_extra(page: BeautifulSoup) -> BeautifulSoup:
286286 child_new .insert (2 , child_new_2 )
287287 child_new .insert (3 , "\xA0 |\xA0 " )
288288 child_new .insert (4 , child_new_3 )
289- child .replaceWith (m_ [1 ], child_new , m_ [5 ])
289+ child .replace_with (m_ [1 ], child_new , m_ [5 ])
290290
291291 for p in page .select ("p" ):
292- p .replaceWith (* p .children )
292+ p .replace_with (* p .children )
293293
294294 return page
295295
0 commit comments