Return to the Web Authoring Forum | Post a Follow-Up

 o
bbcode2html

Posted by chuggerguy (My Page) on
Sat, Jan 25, 14 at 1:40

A post elsewhere got me playing around with the stream editor sed in a bash script trying to convert existing text files containing bbcode into text files containing html code.

So, despite probable easier pre-made solutions, seeing it as an opportunity to learn at least a little sed/regex, I decided to throw something together, just for the fun of it.

Assume there exists a collection of "how-to" type text files, used as templates to copy/paste as needed, and containing a few bbc tags. Not too many though, I don't want to spend too much time on this.

The setup:

You have a folder containing the necessary script files and a directory full of "how-to" text files containing bbc tags. Ordinarily you post the how-tos in forums where bbcode is used, but you'd also like to occasionally make use of them on a site that uses html. You have too many to manually convert or even to use an online converter. So you've decided to try batch converting them. Of course, these are not your only copies, just in case. :)

The contents of the two script files...

bbc2html.sed:

convertALL:

The first file does the substitutions using sed, the second file passes all the text(.txt) files in the toConvert directory to/through the sed file and saves the result in a directory(created if it doesn't exist) called "converted" using a slightly modified name to indicate they now contain html. Hopefully they do... although with my limited expertise I'd not count on it. I suspect the input files had better not contain invalid(improper nesting?) bbcode or anything too complex.

Using this text file as a test input file

and executing "convertALL" creates a folder named "converted" and within that folder is a newly created file called testingAfewTags.html.txt.

The contents of the testingAfewTags.html.txt:

Posting the result here on gardenweb.com gives:

bold

italic

underline

strikethrough

centered text

http://google.com

red text

green underlined text

bold blue underlined text

It appears to work, at least in this limited case.

I got it started... someone else can extend it if they'd like. :)

Edit1: Added "strike-through" and "center" tags.
Edit2: Using this as a starting point, I threw together an online version. Probably will never be complete, it was/is just a learning project. bbc2html It may be useful for someone familiar with bbc but not html. Unlike the batch script, it only does one at a time, you have to paste the code in, and you get no previews.

This post was edited by chuggerguy on Mon, Jan 27, 14 at 22:28


Follow-Up Postings:

 o
Apply my theme bookmarklet

Apply my style to this page?

Contents of the above bookmarklet:

<a href="javascript:var $ = document;var cssId = 'myCss';var head = $.getElementsByTagName('head')[0];var link = $.createElement('link');link.id = cssId;link.rel = 'stylesheet';link.type = 'text/css';link.href = 'http://www.chuggerguy.com/pub/css/myTheme.css';link.media = 'all';head.appendChild(link);void(0)">Apply my style to this page?</a>

This post was edited by chuggerguy on Mon, Mar 3, 14 at 1:56


 o
RE: bbcode2html

Partly putting this here so I can easily find it next time I want it...


Are you running Windows, Mac or Linux?:

What operating system are you running?(XP, Vista, 7, 8 etc.):

Computer make? (Dell, HP, etc):

Computer model?:

A brief description of the problem:

The intent is to make it more likely that a user, esp. a novice user, knows what type of info to include when doing a web search to fix a problem.

Honestly though, although Google is a powerful tool that can solve almost any problem, I suspect it gets as many people in trouble as it helps. Google is only a tool... Google is not your friend! :)

Always use WOT or a similar web trust/rating tool or you're liable to end up exploring dangerous search results.

Probably more fields could be added to the form such as browser but...


 o
dual displays

I just realized, doing a full screen capture with two displays gets the whole thing...



The second display, running Windows in a virtual machine, really is smaller.


 o
A Linux renaming session

Partly just to see how it will post. Partly to remind myself that a problem doesn't have to be tackled in one go. It's okay to chip away at it bit by bit.


chugger@gigabyte:~/Desktop/season 1$ ls
History.Ch.How.the.Earth.Was.Made.Complete.Season.1.01of13.San.Andreas.Fault.XviD.AC3.MVGroup.org.avi
History.Ch.How.the.Earth.Was.Made.Complete.Season.1.02of13.The.Deepest.Place.on.Earth.XviD.AC3.MVGroup.org.avi
History.Ch.How.the.Earth.Was.Made.Complete.Season.1.03of13..Krakatoa.XviD.AC3.MVGroup.org.avi
History.Ch.How.the.Earth.Was.Made.Complete.Season.1.04of13.Lock.Ness.XviD.AC3.MVGroup.org.avi
History.Ch.How.the.Earth.Was.Made.Complete.Season.1.05of13.New.York.XviD.AC3.MVGroup.org.avi
History.Ch.How.the.Earth.Was.Made.Complete.Season.1.06of13.Driest.Place.On.Earth.XviD.AC3.MVGroup.org.avi
History.Ch.How.the.Earth.Was.Made.Complete.Season.1.07of13.Great.Lakes.XviD.AC3.MVGroup.org.avi
History.Ch.How.the.Earth.Was.Made.Complete.Season.1.08of13.Yellowstone.XviD.AC3.MVGroup.org.avi
History.Ch.How.the.Earth.Was.Made.Complete.Season.1.09of13.Tsunami.XviD.AC3.MVGroup.org.avi
History.Ch.How.the.Earth.Was.Made.Complete.Season.1.10of13.Asteroids.XviD.AC3.MVGroup.org.avi
History.Ch.How.the.Earth.Was.Made.Complete.Season.1.11of13.Iceland.XviD.AC3.MVGroup.org.avi
History.Ch.How.the.Earth.Was.Made.Complete.Season.1.12of13.Hawaii.XviD.AC3.MVGroup.org.avi
History.Ch.How.the.Earth.Was.Made.Complete.Season.1.13of13.The.Alps.XviD.AC3.MVGroup.org.avi
chugger@gigabyte:~/Desktop/season 1$ rename 's/History.Ch.How.the.Earth.Was.Made.Complete.Season.1.//' *.avi
chugger@gigabyte:~/Desktop/season 1$ ls
01of13.San.Andreas.Fault.XviD.AC3.MVGroup.org.avi 08of13.Yellowstone.XviD.AC3.MVGroup.org.avi
02of13.The.Deepest.Place.on.Earth.XviD.AC3.MVGroup.org.avi 09of13.Tsunami.XviD.AC3.MVGroup.org.avi
03of13..Krakatoa.XviD.AC3.MVGroup.org.avi 10of13.Asteroids.XviD.AC3.MVGroup.org.avi
04of13.Lock.Ness.XviD.AC3.MVGroup.org.avi 11of13.Iceland.XviD.AC3.MVGroup.org.avi
05of13.New.York.XviD.AC3.MVGroup.org.avi 12of13.Hawaii.XviD.AC3.MVGroup.org.avi
06of13.Driest.Place.On.Earth.XviD.AC3.MVGroup.org.avi 13of13.The.Alps.XviD.AC3.MVGroup.org.avi
07of13.Great.Lakes.XviD.AC3.MVGroup.org.avi
chugger@gigabyte:~/Desktop/season 1$ rename 's/.XviD.AC3.MVGroup.org//' *.avi
chugger@gigabyte:~/Desktop/season 1$ ls
01of13.San.Andreas.Fault.avi 05of13.New.York.avi 09of13.Tsunami.avi 13of13.The.Alps.avi
02of13.The.Deepest.Place.on.Earth.avi 06of13.Driest.Place.On.Earth.avi 10of13.Asteroids.avi
03of13..Krakatoa.avi 07of13.Great.Lakes.avi 11of13.Iceland.avi
04of13.Lock.Ness.avi 08of13.Yellowstone.avi 12of13.Hawaii.avi
chugger@gigabyte:~/Desktop/season 1$ ls : sed -E 's/(..)(of13)(.*)/mv "&" \"s01e\1 - \3\"/'
mv "01of13.San.Andreas.Fault.avi" "s01e01 - .San.Andreas.Fault.avi"
mv "02of13.The.Deepest.Place.on.Earth.avi" "s01e02 - .The.Deepest.Place.on.Earth.avi"
mv "03of13..Krakatoa.avi" "s01e03 - ..Krakatoa.avi"
mv "04of13.Lock.Ness.avi" "s01e04 - .Lock.Ness.avi"
mv "05of13.New.York.avi" "s01e05 - .New.York.avi"
mv "06of13.Driest.Place.On.Earth.avi" "s01e06 - .Driest.Place.On.Earth.avi"
mv "07of13.Great.Lakes.avi" "s01e07 - .Great.Lakes.avi"
mv "08of13.Yellowstone.avi" "s01e08 - .Yellowstone.avi"
mv "09of13.Tsunami.avi" "s01e09 - .Tsunami.avi"
mv "10of13.Asteroids.avi" "s01e10 - .Asteroids.avi"
mv "11of13.Iceland.avi" "s01e11 - .Iceland.avi"
mv "12of13.Hawaii.avi" "s01e12 - .Hawaii.avi"
mv "13of13.The.Alps.avi" "s01e13 - .The.Alps.avi"
chugger@gigabyte:~/Desktop/season 1$ ls : sed -E 's/(..)(of13)(.*)/mv "&" \"s01e\1 - \3\"/' : sh
chugger@gigabyte:~/Desktop/season 1$ ls
s01e01 - .San.Andreas.Fault.avi s01e05 - .New.York.avi s01e09 - .Tsunami.avi s01e13 - .The.Alps.avi
s01e02 - .The.Deepest.Place.on.Earth.avi s01e06 - .Driest.Place.On.Earth.avi s01e10 - .Asteroids.avi
s01e03 - ..Krakatoa.avi s01e07 - .Great.Lakes.avi s01e11 - .Iceland.avi
s01e04 - .Lock.Ness.avi s01e08 - .Yellowstone.avi s01e12 - .Hawaii.avi
chugger@gigabyte:~/Desktop/season 1$ rename 's/\.\.//g' *.avi
chugger@gigabyte:~/Desktop/season 1$ ls
s01e01 - .San.Andreas.Fault.avi s01e05 - .New.York.avi s01e09 - .Tsunami.avi s01e13 - .The.Alps.avi
s01e02 - .The.Deepest.Place.on.Earth.avi s01e06 - .Driest.Place.On.Earth.avi s01e10 - .Asteroids.avi
s01e03 - Krakatoa.avi s01e07 - .Great.Lakes.avi s01e11 - .Iceland.avi
s01e04 - .Lock.Ness.avi s01e08 - .Yellowstone.avi s01e12 - .Hawaii.avi
chugger@gigabyte:~/Desktop/season 1$ rename 's/\./ /g' *.avi
chugger@gigabyte:~/Desktop/season 1$ ls
s01e01 - San Andreas Fault avi s01e05 - New York avi s01e09 - Tsunami avi s01e13 - The Alps avi
s01e02 - The Deepest Place on Earth avi s01e06 - Driest Place On Earth avi s01e10 - Asteroids avi
s01e03 - Krakatoa avi s01e07 - Great Lakes avi s01e11 - Iceland avi
s01e04 - Lock Ness avi s01e08 - Yellowstone avi s01e12 - Hawaii avi
chugger@gigabyte:~/Desktop/season 1$ rename 's/ / /g' *
chugger@gigabyte:~/Desktop/season 1$ ls
s01e01 - San Andreas Fault avi s01e05 - New York avi s01e09 - Tsunami avi s01e13 - The Alps avi
s01e02 - The Deepest Place on Earth avi s01e06 - Driest Place On Earth avi s01e10 - Asteroids avi
s01e03 - Krakatoa avi s01e07 - Great Lakes avi s01e11 - Iceland avi
s01e04 - Lock Ness avi s01e08 - Yellowstone avi s01e12 - Hawaii avi
chugger@gigabyte:~/Desktop/season 1$ rename 's/avi/.avi/' *
chugger@gigabyte:~/Desktop/season 1$ ls
s01e01 - San Andreas Fault .avi s01e05 - New York .avi s01e09 - Tsunami .avi s01e13 - The Alps .avi
s01e02 - The Deepest Place on Earth .avi s01e06 - Driest Place On Earth .avi s01e10 - Asteroids .avi
s01e03 - Krakatoa .avi s01e07 - Great Lakes .avi s01e11 - Iceland .avi
s01e04 - Lock Ness .avi s01e08 - Yellowstone .avi s01e12 - Hawaii .avi
chugger@gigabyte:~/Desktop/season 1$

Edit: Vertical bars (pipe symbols) get changed to colons. :(

Edit2: Also, "white-space:pre;" style seems to break out of the 550px gardenweb imposed max width. Suppose it would look even worse if it wrapped.

This post was edited by chuggerguy on Mon, Apr 21, 14 at 2:36


 o Post a Follow-Up

Please Note: Only registered members are able to post messages to this forum.

    If you are a member, please log in.

    If you aren't yet a member, join now!


Return to the Web Authoring Forum

Information about Posting

  • You must be logged in to post a message. Once you are logged in, a posting window will appear at the bottom of the messages. If you are not a member, please register for an account.
  • Posting is a two-step process. Once you have composed your message, you will be taken to the preview page. You will then have a chance to review your post, make changes and upload photos.
  • After posting your message, you may need to refresh the forum page in order to see it.
  • Before posting copyrighted material, please read about Copyright and Fair Use.
  • We have a strict no-advertising policy!
  • If you would like to practice posting or uploading photos, please visit our Test forum.
  • If you need assistance, please Contact Us and we will be happy to help.


Learn more about in-text links on this page here