bbcode2html

Richard (chuggerguy)January 25, 2014

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 ...

Thank you for reporting this comment. Undo
Richard (chuggerguy)

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

    Bookmark   March 2, 2014 at 12:33AM
Thank you for reporting this comment. Undo
Richard (chuggerguy)

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...

    Bookmark   March 17, 2014 at 2:54AM
Thank you for reporting this comment. Undo
Richard (chuggerguy)

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.

    Bookmark   March 29, 2014 at 1:41AM
Thank you for reporting this comment. Undo
Richard (chuggerguy)

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...

    Bookmark   April 21, 2014 at 2:13AM
Sign Up to comment
More Discussions
Bonsai
GardenWeb I hope this post finds you well. I have acquired...
olindha
Checking for the presence of adblocker.
Asteroids This post was edited by chuggerguy on Fri,...
Richard (chuggerguy)
How to embed animated Gifs onto GW?
I tried posting the way chuggeryguy which worked for...
ladyrose65
People viewed this after searching for:
© 2015 Houzz Inc. Houzz® The new way to design your home™