CodeWalrus

Development => PC, Mac & Vintage Computers => Topic started by: Unicorn on July 19, 2016, 05:38:29 PM

Title: BBCode to Wiki Markup - Name [Ruby]
Post by: Unicorn on July 19, 2016, 05:38:29 PM
I've found that we need a program to convert BBCode (The formatting that the forum uses) to Wiki Markup (The formatting that most of the community wikis use). It will make it easy to bring tutorials written on the forum into the wiki.

I will be using Ruby to write it, with Shoes (http://shoesrb.com/)for 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![/b]
Strike this text, it makes no sense!
And don't forget an image!
(https://codewalr.us/Themes/CodeWalrus/images/english/smflogo.png)
Lets indent this code, as well!
codecodecode codecodecode codecodecode
codecodecode codecodecode
codecodecode
codecodecode
codecodecode codecodecode codecodecode
---------------------------------------------------------------------
That was the post, here's the BBC:

[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://codewalr.us/Themes/CodeWalrus/images/english/smflogo.png[/img]
Lets indent this code, as well!
[list][code]codecodecode codecodecode codecodecode
codecodecode codecodecode
codecodecode
codecodecode
codecodecode codecodecode codecodecode

[/list][/code]
-------------------------------------------------------------------
And here is the Wiki Markup:

== BBCtoWiki Example ======

''Wassup! ''''This is an example!'''''
<strike>Strike this text, it makes no sense!</strike>
==== And don't forget an image! ======
https://codewalr.us/Themes/CodeWalrus/images/english/smflogo.png
Lets indent this code, as well!
<blockquote><pre>codecodecode codecodecode codecodecode
codecodecode codecodecode
codecodecode
codecodecode
codecodecode codecodecode codecodecode
</pre>
</blockquote>

----------------------------------------------
Go here to see an example of the Wiki Markup: https://www.cemetech.net/learn/Bbcodeconvertexample
Title: Re: BBCode to Wiki Markup - Name
Post by: Dream of Omnimaga on July 20, 2016, 03:49:11 AM
That would definitively be useful. I always wondered if such tool was available before, because I once wanted to convert a post to a TI-Story page and it was a major hassle.

I can't help, but hopefully someone can. Just make sure before copying tutorials to ask the author's permission before uploading it elsewhere, though.
Title: Re: BBCode to Wiki Markup - Name
Post by: Unicorn on July 21, 2016, 02:39:25 AM
Yup, that it exactly why, to lessen the hassle. Anyways, anyone have an idea for a name?
Title: Re: BBCode to Wiki Markup - Name [Ruby]
Post by: Dream of Omnimaga on July 21, 2016, 03:53:00 AM
BBCode2wiki?

Envoyé de mon Nexus 5 en utilisant Tapatalk

Title: Re: BBCode to Wiki Markup - Name
Post by: Unicorn on July 22, 2016, 04:08:09 AM
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:


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! "[scode]", "<code>"
        bbcode.gsub! "[s/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.

Download Below
Title: Re: BBCode to Wiki Markup - Name
Post by: Unicorn on July 22, 2016, 10:02:45 PM
So I've added text sizes and tweaked the code conversion, so check out the examples.

See the OP for an example! https://codewalr.us/index.php?topic=1467.msg41898#msg41898

Any more ideas for other tags? I could include smilies...

Download Below
Title: Re: BBCode to Wiki Markup - Name
Post by: Dream of Omnimaga on July 22, 2016, 10:59:34 PM
By the way, does this support Wikidot syntax too? It would be a nice addition for cross-posting BASIC tricks or posts into TI-BD wiki or to post TI community doc in TI-Story, which are both hosted on Wikidot.

Other than that, Does this need dependencies other than Shoes? Because when I run this, once Shoes is downloaded, it takes about 1 minute to load and it takes over 15% CPU (I have a quad-core) during that time.

EDIT: It doesn't seem to convert much so far. Does it only support PhpBB syntax? I tried converting this post, btw https://codewalr.us/index.php?topic=28.0
Title: Re: BBCode to Wiki Markup - Name
Post by: Unicorn on July 23, 2016, 12:13:02 AM
So yeah, urls, aren't implemented yet, and colors don't work. I also need to implement underlining.

It shouldn't take to long, I'm not sure, on linux its fast...
Title: Re: BBCode to Wiki Markup - Name
Post by: Dream of Omnimaga on July 23, 2016, 12:21:37 AM
I use Windows 7 64-bits. Maybe that's why?
Title: Re: BBCode to Wiki Markup - Name
Post by: Unicorn on July 23, 2016, 02:50:02 AM
Quote from: DJ Omnimaga on July 23, 2016, 12:21:37 AM
I use Windows 7 64-bits. Maybe that's why?

Does it open the window right away, but then freeze? It does that for me when on Windows 10. I guess I'll have to package it a different way.
Title: Re: BBCode to Wiki Markup - Name
Post by: Unicorn on July 23, 2016, 07:21:36 PM
OK, heres another thing to try, @DJ Omnimaga

Use the same .exe, but shoes is already included in the application, you won't have to download it. You also might want to uninstall shoes before running it. And I made urls work :P

http://www.mediafire.com/download/616o23g0c9hphsn/BBCtoWIKI.zip
Title: Re: BBCode to Wiki Markup - Name
Post by: aetios on July 23, 2016, 07:27:55 PM
How about BBC2WM for a name. BBCode to Wiki Markup.
Title: Re: BBCode to Wiki Markup - Name
Post by: Dream of Omnimaga on July 24, 2016, 12:46:13 AM
Quote from: Unicorn on July 23, 2016, 02:50:02 AM
Quote from: DJ Omnimaga on July 23, 2016, 12:21:37 AM
I use Windows 7 64-bits. Maybe that's why?

Does it open the window right away, but then freeze? It does that for me when on Windows 10. I guess I'll have to package it a different way.
YEs it opens a window right away. It just remains blank like if it had frozen for about a minute. I'll try your other download link now.

EDIT: The new version seems to open much faster now.
Title: Re: BBCode to Wiki Markup - Name
Post by: Unicorn on July 24, 2016, 05:42:26 PM
Good, I'm glad that's fixed. Now, is there anything else I should do?
Title: Re: BBCode to Wiki Markup - Name
Post by: Dream of Omnimaga on July 25, 2016, 07:38:29 AM
Maybe there could be options to choose the formating style, such as, for example, if the user wants underline-bold text to be converted to big text and bold text to medium text or if he prefers that they are converted to something else?
Title: Re: BBCode to Wiki Markup - Name
Post by: Unicorn on July 26, 2016, 06:57:34 AM
I could to that, maybe read info from a text file in the main directory that is easy for the user to changed.
Title: Re: BBCode to Wiki Markup - Name
Post by: Dream of Omnimaga on July 26, 2016, 03:21:05 PM
Ideally I don't think options should have to be changed via a text file like in some games, though. That's not that user-friendly, unless you thoroughly explain step by step what are each option.
Title: Re: BBCode to Wiki Markup - Name [Ruby]
Post by: garvalf on July 28, 2016, 09:41:55 AM
That's interesting, both the Shoes app and this script.

For all my documents, I'm using the txt2tags wiki markup langage. It's has a cool syntax (much better and logical than mediawiki).

http://txt2tags.org/

For example **bold** is for bold, //italic// for italic, __underline__ for underline, --strikeout-- for strikeout etc.
The advantage is you don't use extra letters (such as b for bold like in bbcode), and it's super fast to type (no need to use those [ ])

It can also export to several markup: markdown, mediawiki, bbcode, rtf (useful for making documents), laTeX, html etc

Some wiki such as dokuwiki, pmwiki and a few others can be adapted to use the txt2tags syntax.

Title: Re: BBCode to Wiki Markup - Name
Post by: Dream of Omnimaga on July 28, 2016, 12:14:36 PM
I kinda wish that forums went that route long ago. IIRC there are forum softwares that support wiki markup, but it would suck having to convert posts to support it.

That said, I guess I can understand that some people might have an hard time memorizing the syntax compared to some of the bbcode.
Title: Re: BBCode to Wiki Markup - Name [Ruby]
Post by: garvalf on July 28, 2016, 01:12:25 PM
I'm pretty sure it could allow both syntax (wiki and bbcode). Yet, I prefer to use the bbcode than the mediawiki (aka wikipedia) syntax, which is really one of the worst design ever made. For example, with '' for italic, ''' for bold, which mean you have ''''' for bold + italic.

But there is maybe worse, for dokuwiki, the heading is the opposite of the logic, for example heading level 1 is, instead of being one =, 4 or 5 = (or maybe 6?).

For converting between syntaxes, there is pandoc, which can input one markup, and output to an other one.
Title: Re: BBCode to Wiki Markup - Name
Post by: Unicorn on July 28, 2016, 11:40:12 PM
That is actually quite a nice markup syntax! But anyways, development is kind of halted right now, I'm going to continue work on that train game now.
Title: Re: BBCode to Wiki Markup - Name
Post by: Dream of Omnimaga on July 29, 2016, 01:03:48 AM
Quote from: garvalf on July 28, 2016, 01:12:25 PM
I'm pretty sure it could allow both syntax (wiki and bbcode). Yet, I prefer to use the bbcode than the mediawiki (aka wikipedia) syntax, which is really one of the worst design ever made. For example, with '' for italic, ''' for bold, which mean you have ''''' for bold + italic.

But there is maybe worse, for dokuwiki, the heading is the opposite of the logic, for example heading level 1 is, instead of being one =, 4 or 5 = (or maybe 6?).

For converting between syntaxes, there is pandoc, which can input one markup, and output to an other one.
WHat I dislike is when websites use syntaxes with no closing character. Imagine trying to make a post without a [/b] character and being only able to use 1 font weight or style at a time per paragraph.
Title: Re: BBCode to Wiki Markup - Name [Ruby]
Post by: garvalf on July 29, 2016, 07:04:41 AM
The good thing with txt2tags (and most other lightweight markup langages) is you don't really need closing characters, for example your can write this kind of thing in txt2tags:

I **enjoy** //Casio// calculators, but I **love even more** the //TI// ones.

and it correctly will convert to:

I enjoy Casio calculators, but I love even more the TI ones.

it will certainly not convert to something like:  I enjoy Casio calculators, but I love even more the TI[/i] ones.  (which the bbcode doesn't even handle well)

The only thing you can't do is using such marks accross several paragraphs. If you really need to do this you can just mark the beginning and the end of every single paragraph. But marking in bold several paragraphs is not very meaningful, in this case if you need such a thing it's better to create a new "class" ("code", "remark", "important", whatever) and use this new class across the paragraphs. Because the other good thing with txt2tags is you can redefine your own marks, and you can decide to use closing characters if you feel so. It's what I did for some documents, for example you define them this way:


%!preproc: '\{\+\+\}'     'CONVERTsizeincBEGIN'
%!preproc: '\{/\+\+\}'    'CONVERTsizeincEND'


%!postproc(xhtml): 'CONVERTsizeincBEGIN' '<span class="big">'
%!postproc(xhtml): 'CONVERTsizeincEND' '</span>'


So I can use the {++}bigger font{/++} marks to make a part with this new style (I can do the same for bold or italic, for marking a whole area).

You can make whole books with that, for example:
https://mega.nz/#F!00Ix1TZA!Yj-GM6alhJplzLgS5K8_fw

(it's a choose your own adventure, in French, which I converted to epub, pdf and html using this syntax. If you can read French you can play it, it's a very good story, with a lovecraftian background)
Title: Re: BBCode to Wiki Markup - Name
Post by: Dream of Omnimaga on July 29, 2016, 07:13:50 AM
Hm I see. That might take me a while to get used to if I use this syntax actually, though, since I am not used to inserting custom styles in each of my text files. :P

Thanks for the thorough explanation, though @garvalf . :)


Also regarding Choose Your Own Adventure books, I used to read Un Livre Dont Vous Êtes le Héros way back in the 90's and it was very fun, like an ancestor of video game-based RPGs. The only thing I hated is that most battles were luck-based and your attacks missed a lot, not to mention having to restart from scratch all the time (not that we followed the rules to the letter, but if they ever made those books into visual novels or actual text-based games then it would be like playing Final Fantasy with no save feature. O.O I also made two comic books in 2000-01 that were actual choose your own adventure books, but they worked closer to actual JRPGs with experience, leveling up and all, so you needed a calculator all the time. There were even board game style maps in some comic strips where you moved around and the dice roll told how many steps you could take before the next random enemy encounter. Maybe I should start a CYOA topic at some point?
Title: Re: BBCode to Wiki Markup - Name [Ruby]
Post by: garvalf on August 01, 2016, 10:28:59 PM
QuoteMaybe I should start a CYOA topic at some point?

yes, good idea!

I played/read many "livres dont vous êtes le héros" in my youth. I like that, but it's true the battles are not very interesting (I cheated every time I guess)
Title: Re: BBCode to Wiki Markup - Name
Post by: Dream of Omnimaga on August 01, 2016, 10:40:09 PM
Near the end I just played for the story lol. I still enjoyed reading the books. Also I hated writing stuff in my books so I just used a separate sheet of paper. I should scan my CYOA comics, but again I said that for 15 years already :P
Title: Re: BBCode to Wiki Markup - Name
Post by: Unicorn on August 08, 2017, 05:26:31 AM
So uh, I discovered Electron (https://electron.atom.io/) 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 (https://github.com/Unicorn808/bbcode-wiki-converter)

Now I just need to figure out how to package it so I can make a release :P Or maybe put it in a github website or something :P
Title: Re: BBCode to Wiki Markup - Name
Post by: Yuki on August 08, 2017, 05:32:55 AM
Ah yeah, Electron is pretty neat. Personally I just installed electron-builder (npm install electron-builder --dev --save), your package.json file should look like this (https://github.com/juju2143/7-segment-alarm-clock/blob/master/package.json), you type npm dist and there you go you have some apps packaged, ready for release.
Title: Re: BBCode to Wiki Markup - Name
Post by: Unicorn on August 08, 2017, 05:50:17 AM
Quote from: Juju on August 08, 2017, 05:32:55 AM
Ah yeah, Electron is pretty neat. Personally I just installed electron-builder (npm install electron-builder --dev --save), your package.json file should look like this (https://github.com/juju2143/7-segment-alarm-clock/blob/master/package.json), you type npm dist and there you go you have some apps packaged, ready for release.
Huh. And all the docs and tutorials didn't make it that easy :P

Well, npm dist is not recognized as a command, apparently. Is there some other dependency i need? oops npm run dist :P
Title: Re: BBCode to Wiki Markup - Name [Ruby]
Post by: kotu on August 08, 2017, 03:45:09 PM
"BTW"

(bb 2 wiki)

Title: Re: BBCode to Wiki Markup - Name
Post by: Unicorn on August 08, 2017, 09:36:04 PM
are you referring to that program on guthub? if so, it removes the h in https among  other things
Title: Re: BBCode to Wiki Markup - Name [Ruby]
Post by: kotu on August 08, 2017, 09:37:28 PM
i was suggesting a name for your conversion tool..
Title: Re: BBCode to Wiki Markup - Name
Post by: Unicorn on August 09, 2017, 05:02:26 AM
This is what i was refering to: https://github.com/chulup/bbcode_wiki
Anyways,
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! :P

https://github.com/Unicorn808/bbcode-wiki-converter
Title: Re: BBCode to Wiki Markup - Name [Ruby]
Post by: kotu on August 15, 2017, 06:28:56 AM
'bbTwik'