Convert contents from HTML to BB? Topic is solved

Relax and enjoy The Lounge. For all Non-Joomla! topics or ones that don't fit anywhere else. Normal forum rules apply.
Locked
littlebigman
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Fri Mar 06, 2009 10:41 am

Convert contents from HTML to BB?

Post by littlebigman » Fri Jan 27, 2023 2:35 pm

Hello,

To retire an old blog written with Joomla, I need to export its contents, from HTML to BB.

Before I try to write a script, is there a known, reliable solution?

Thank you.
Last edited by toivo on Sat Jan 28, 2023 9:06 pm, edited 1 time in total.
Reason: mod note: moved from 4.x General Questions

User avatar
AMurray
Joomla! Exemplar
Joomla! Exemplar
Posts: 9745
Joined: Sat Feb 13, 2010 7:35 am
Location: Australia

Re: Convert contents from HTML to BB?

Post by AMurray » Sat Jan 28, 2023 6:30 am

The contents are in the database (e.g. in the #_articles table). You can just export the database - to a CSV, or SQL or other file format. By "BB" do you mean BB code? Why do you need to export to that format? BBCode is simply a simplified markup used in Bulletin Boards or forums (like this Joomla one), which in the background is translated back to HTML equivalent.

I've never seen any solution for Joomla as such but if you search google you'd find a solution easily.

Not sure how it would help really, given your content is stored in the site's database anyway.
Regards - A Murray
General Support Moderator

littlebigman
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Fri Mar 06, 2009 10:41 am

Re: Convert contents from HTML to BB?

Post by littlebigman » Sat Jan 28, 2023 5:13 pm

To avoid losing all the formatting. BBCode offers less options than HTML, but it's better than nothing.

I have to pre-format it in BBCode since injecting articles directly from one DB to the other isn't an option — too many tables with too many columns involved, about which I know nothing.

Turns out it's quite easy with BeautifulSoup, eg.

Code: Select all

soup = BeautifulSoup(row["article"], 'lxml')
for bold in soup("b","em","strong","u"): #shortcut for soup.find_all("b")
	bold.insert_before("[b]")
	bold.insert_after("[/b]")
for link in soup('a'):
	#[url=https://www.phpbb.com/]Visit phpBB![/url]
	link.string=f"[url={link.get('href')}]{link.get('href')}[/url]"


Locked

Return to “The Lounge”