Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
I've found that we need a program to convert BBCode (The formatting that the forum uses) to Wiki Markup (The formatting that mediawiki uses, in turn, Learn @ Cemetech). It will make it easy to bring tutorials written on the forum into the wiki.

So uh, I discovered Electron and decided to move this app over to it to kinda learn how electron goes. Anyways, I moved everything to Javascript and learned a little regex, as well as implemented html support. Check it out!
BBCode to Wiki Markup Converter


OLD
-------------------------------
I will be using Ruby to write it, with Shoesfor a gui. It will not support images, tables, lists, fonts, and colors right away, if ever. It will definitely support code, bold, italics, underlines, and urls.

The one problem I have is figuring out how to distribute it. Using Ocra, the gem that lets you package your script into a .exe file doesn't quite work, and I'm unsure how I would be able to host it online.

Here's an example that uses all of the converted functions:

BBCtoWiki Example

Wassup! This is an example!
[s]Strike this text, it makes no sense![/s]
And don't forget an image!

Lets indent this code, as well!

    Code:
    codecodecode codecodecode codecodecode
    codecodecode codecodecode
    codecodecode
    codecodecode
    codecodecode codecodecode codecodecode

google
---------------------------------------------------------------------
That was the post, here's the BBC:


Code:
[size=24]BBCtoWiki Example[/size]

[i]Wassup! [b]This is an example![/i][/b]
[s]Strike this text, it makes no sense![/s]
[size=12]And don't forget an image![/size]
[img]https://www.cemetech.net/forum/templates/Cemetech6/images/logo.png[/img]
Lets indent this code, as well!
[list][code]codecodecode codecodecode codecodecode
codecodecode codecodecode
codecodecode
codecodecode
codecodecode codecodecode codecodecode
[/code]
[/list][url=http://www.google.com]google[/url]

-------------------------------------------------------------------
And here is the Wiki Markup:

Code:

== BBCtoWiki Example ======

''Wassup! ''''This is an example!'''''
<strike>Strike this text, it makes no sense!</strike>
==== And don't forget an image! ======
https://www.cemetech.net/forum/templates/Cemetech6/images/logo.png
Lets indent this code, as well!
<blockquote><pre>codecodecode codecodecode codecodecode
codecodecode codecodecode
codecodecode
codecodecode
codecodecode codecodecode codecodecode
</pre>
</blockquote>[http://www.google.com google]

----------------------------------------------
Go here to see an example of the Wiki Markup: https://www.cemetech.net/learn/Bbcodeconvertexample
Oh yes, anyone have an idea for a name?

So I've made alot of progress. I have something of a gui, and teh program supports converting Bold text, strikethroughs, italics, images, lists (they get turned into those lines "----"), and code.

Here's the code:


Code:

require 'shoes'
Shoes.app(title: "BBCode to Wiki Markup", width: 1000, height: 750, resizable: true) do
  background white
  @BBC = edit_box top: 60, left: 35, width: 940, height: 250
  @Convert = button "Convert", top: 340, left: 450
  @Convert.click do
    bbcode = @BBC.text
        bbcode.gsub! "[b]", "''''"
        bbcode.gsub! "[/b]", "'''"
        bbcode.gsub! "[i]", "''"
        bbcode.gsub! "[/i]", "''"
        bbcode.gsub! "[code]", "<code>"
        bbcode.gsub! "[/code]", "</code>"
        bbcode.gsub! "[s]", "<strike>"
        bbcode.gsub! "[/s]", "</strike>"
        bbcode.gsub! "[img]", ""
        bbcode.gsub! "[/img]", ""
        bbcode.gsub! "[list]", "----"
        bbcode.gsub! "[/list]", ""
    edit_box "#{bbcode}", top:400, left: 35, width: 940, height: 250
  end
  @quitB = button "Quit", top: 700, left: 455
  @quitB.click {exit}
  end


EDIT: I fixed it! I had to use gsub! instead of sub!.

A video, converting Bold text: https://usercontent.irccloud-cdn.com/file/irXNiRHG/Screencast%202016-07-21%2017%3A10%3A23.mp4

It can convert the entirety of this post: https://www.cemetech.net/forum/viewtopic.php?t=12725&highlight=
Example: https://www.cemetech.net/learn/Bbcodeconvertexample

I'm going to work on headers, and maybe change up the list tag a little.
Uhh.... Pandoc?
oldmud0 wrote:
Uhh.... Pandoc?

Where does this program support BBCode? I couldn't find it... Rolling Eyes
Also:

Oh yes, anyone have an idea for a name?

So I've made alot of progress. I have something of a gui, and teh program supports converting Bold text, strikethroughs, italics, images, lists (they get turned into those lines "----"), and code.

Here's the code:


Code:

require 'shoes'
Shoes.app(title: "BBCode to Wiki Markup", width: 1000, height: 750, resizable: true) do
  background white
  @BBC = edit_box top: 60, left: 35, width: 940, height: 250
  @Convert = button "Convert", top: 340, left: 450
  @Convert.click do
    bbcode = @BBC.text
        bbcode.gsub! "[b]", "''''"
        bbcode.gsub! "[/b]", "'''"
        bbcode.gsub! "[i]", "''"
        bbcode.gsub! "[/i]", "''"
        bbcode.gsub! "[code]", "<code>"
        bbcode.gsub! "[/code]", "</code>"
        bbcode.gsub! "[s]", "<strike>"
        bbcode.gsub! "[/s]", "</strike>"
        bbcode.gsub! "[img]", ""
        bbcode.gsub! "[/img]", ""
        bbcode.gsub! "[list]", "----"
        bbcode.gsub! "[/list]", ""
    edit_box "#{bbcode}", top:400, left: 35, width: 940, height: 250
  end
  @quitB = button "Quit", top: 700, left: 455
  @quitB.click {exit}
  end


EDIT: I fixed it! I had to use gsub! instead of sub!.

A video, converting Bold text: https://usercontent.irccloud-cdn.com/file/irXNiRHG/Screencast%202016-07-21%2017%3A10%3A23.mp4

It can convert the entirety of this post: https://www.cemetech.net/forum/viewtopic.php?t=12725&highlight=
Example: https://www.cemetech.net/learn/Bbcodeconvertexample

I'm going to work on headers, and maybe change up the list tag a little.
I'm not sure about this, but what happens if you don't close the tags? If there isn't, Cemetech will display the starting tag, and no other style. Maybe, in the Wiki that if you start it, it will still make it another style, whether or not there is a closing tag?
PT_ wrote:
I'm not sure about this, but what happens if you don't close the tags? If there isn't, Cemetech will display the starting tag, and no other style. Maybe, in the Wiki that if you start it, it will still make it another style, whether or not there is a closing tag?

I'm not sure how I could make that work,so I think you will just have to close tags, unless MediaWiki supports open tags...
Instead of using simple find and replace, use a stack of tags, pushing a tag when its opened (ex "[c]") and popping a tag when it's closed (ex "[/c]). closing.
=====
If you come to the end of the text, and the stack still has tags, push those tags, appending their MediaWiki equivalent to the end of a file.
=====
If the input tries to open a tag that is already open, pop all tags upto and including the that tag, and then push that tag again.
======
Here is an example:
Eg, input=

Code:

[img]https://foo.com/cat_837.png //Replace the "[img]" with the MediaWiki eqivelent. Push "[img]" to the stack.
[b]more cats  //Can't have a bold inside an image tag, close the image tag, poping "[img]" from the stack. Then, open the "[b]" tag in MediaWiki and push "[b]" to the stack
[img]https:foo.com/cat_838.png //Cant have an image in a bold tag. Close/Pop the "[b]" from stack and open/push the "[img]" tag.
[img]htttps:foo.com/cat_839.png[/img] //Cant have an image tag within an image tag so close last image tag, then open this one, then close it ("[/img]") etc...
[b]bold   //open bold tag, push to stack
[i]and italics   //you *can* have an italics within a bold, push to stack.
//End of file, since there are two items on the stack, "[b]" and "[i"] we pop them, closing first the [i] image and then the [b]
Ok, so I've added support for Text Sizes as well, but there are currently extra == signs left after the changed text, I'm going to try and fix that.

Any other commands I should include?

EDIT: And I've uploaded to the archives!

EDIT2: Check the OP to see a good example: https://www.cemetech.net/forum/viewtopic.php?p=250838#250838
To get around the not closing tags I would indeed suggest, like c4ooo, you a stack. If you encounter an open tag push it somehow and if you see the closing tag replace the both tags. I see some issues though:
* What if you have two times the opening tag of the same style? Such as [b] text . Just curious how you will handle this.
* What in this case: [bold]Abcdefghijklmnopqrstuvwxyz[/bold]?
So uh, I discovered Electron and decided to move this app over to it to kinda learn how electron goes. Anyways, I moved everything to Javascript and learned a little regex, as well as implemented html support. Check it out!
BBCode to Wiki Markup Converter
Now I just need to figure out how to package it so I can make a release Razz Or maybe put it in a github website or something Razz
More!

I figured out why building with electron-builder didn't include all my bootstrap stuff and scripts. Apparently, devDependencies and Dependencies aren't the same thing.

But anyways, got a custom icon, a Setup binary that makes a desktop shortcut and a unpackaged binary. I even learned what .gitignore does! Razz

https://github.com/Unicorn808/bbcode-wiki-converter
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement