Any good javascript BBCode parser? [closed]
Asked Answered
S

3

11

Currently i'm parsing bbcode server side but i'd like to show a preview just like this site does.

If I process the bbcode serverside using ajax it's a bit laggy, so i thought doing it client side, to just show the preview.

Do you guys know any bbcode parser written in javascript?

Signorelli answered 3/12, 2009 at 22:10 Comment(0)
H
5

I haven't personally used any Javascript BBcode parsers, but the top two Google results (bbcodejs and this blog post) seem pretty weak. The former only seems to support simple find-and-replace, and the latter seems to have pre-set BBcode built in, so you'd probably have to hack it a bit if you chose that solution.

Your best options are probably to roll your own solution (possibly basing your work off one of the two links here), or just use AJAX and move on. That's probably the best way to ensure that previews are accurate, and previewing doesn't have to be real-time on every keypress, anyway; a delay before even sending the request is acceptable.

Hatchel answered 3/12, 2009 at 22:18 Comment(6)
Yup, I saw both links before posting, but i was looking for something a bit more popular, just like the library i'm using now (bbcode.codeplex.com). So, probably I will just port it to JS. Seems that there is not muchSignorelli
Are you relly recommending something, that has eval("/"+obj[k].tmatch[tm]+"/gi.test(tag[tm])" in it?Persevere
@Matchu: I think these arrogant "Let me Google that for you" comments are unnecessary on Stack Overflow (and they also decrease the chance to get upvotes). Stack Overflow is like a huge knowledge base which is easy to find using Google (!), so it's really good to see useful answers without obnoxious comments. :)Woodrum
@Sk8erPeter: Fair point. 2009 wasn't my best year ;PHatchel
@Matchu: no problem, you can still edit your answer :DWoodrum
@Sk8erPeter: Similarly fair point. Desnarkified.Hatchel
P
8

It is a bit late, and the question has certainly been answered. However if you are still open to suggestions, and have not yet spent your time converting the indicated parser from C# to JavaScript, I have written a parser (originally in PHP) which I converted myself[2] to JavaScript. It is available at bitbucket under the 3-clause BSD license. The parser seems to be reasonably fast, but I haven't performed any analysis on its speed.

It may not be as flexible in some ways as other possible projects out there, but it does allow defining your own codes ("bb-code" or not, with quite a few properties), and is also all contained within the one file. This is not a simple find-and-replace parser, and is not based on regex.

If this is of any interest to you, it might save you from having to convert that other library. Technically, I'm a relative "unknown", but that's the great things about JS/OSS: you can check out the source to see what I've done.

[2] As a result, there are a few remaining "compatibility functions", but I rewrote things which had native equivalents available.

Pandowdy answered 15/1, 2010 at 4:3 Comment(4)
@ArtMcBain: project not found on bitbucket -1Breadboard
+1. Oh and bitbucket.org/AMcBain/bb-code-parser would be the link to the actual repository.Okelley
I'm not very active here and I didn't know whether updating so long after would be "wrong", then I forgot. I figured at the very least the repo was linked from my site. Thanks @Okelley for posting the link, I updated my comment with it.Pandowdy
@ArtMcBain Looks good (and howdy!)Salisbury
H
5

I haven't personally used any Javascript BBcode parsers, but the top two Google results (bbcodejs and this blog post) seem pretty weak. The former only seems to support simple find-and-replace, and the latter seems to have pre-set BBcode built in, so you'd probably have to hack it a bit if you chose that solution.

Your best options are probably to roll your own solution (possibly basing your work off one of the two links here), or just use AJAX and move on. That's probably the best way to ensure that previews are accurate, and previewing doesn't have to be real-time on every keypress, anyway; a delay before even sending the request is acceptable.

Hatchel answered 3/12, 2009 at 22:18 Comment(6)
Yup, I saw both links before posting, but i was looking for something a bit more popular, just like the library i'm using now (bbcode.codeplex.com). So, probably I will just port it to JS. Seems that there is not muchSignorelli
Are you relly recommending something, that has eval("/"+obj[k].tmatch[tm]+"/gi.test(tag[tm])" in it?Persevere
@Matchu: I think these arrogant "Let me Google that for you" comments are unnecessary on Stack Overflow (and they also decrease the chance to get upvotes). Stack Overflow is like a huge knowledge base which is easy to find using Google (!), so it's really good to see useful answers without obnoxious comments. :)Woodrum
@Sk8erPeter: Fair point. 2009 wasn't my best year ;PHatchel
@Matchu: no problem, you can still edit your answer :DWoodrum
@Sk8erPeter: Similarly fair point. Desnarkified.Hatchel
A
2

I encountered the same problem, so I wrote my own. That supports BBCode -> AST Array -> any kind of markup, now supports HTML and React. And has plugins and presets support

https://github.com/JiLiZART/bbob

Acerose answered 18/6, 2019 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.