Any good javascript BBCode parser? [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
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?

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.

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.

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

Related

How to Remove Unused javascript From Website [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I'm trying to speed up my website. I used www.unused-css.com/ to trim away excess CSS, but I cannot find anything similar for JavaScript. Is there an online service that can detect the js code being used and then trim away the unused code?
Here is the website with the problem: IQ Tests for Kids
I'm using bootstrap code and it is very bloated. I'm sure that I'm only using a fraction of js because I trimmed down my HTML as well.
The best you are going to get is running the JavaScript itself through a dead code removal process, such as the one provided by the Google Closure Compiler with ADVANCED_OPTIMIZATIONS enabled or Uglify's dead_code option. Some people even combine both of these.
Tree shaking is an even better process you will hear people talk about. But this is more difficult to achieve in your case, because tree shaking involves using ES6 modules, which the code you are dealing with almost certainly is not. Thus it would be a lot of work to get that going, as you would have to modify the code.
Don't know any online tool for that, but there are techniques to do what is called "tree shaking". You can google about it more.
Best my used tools to have it working are webpack and Flow
Webpack is quite general tool to make all kind of magic with JS, while Flow is type checking tool which, if you have type checking active can provide very good tree shaking.
But as you mentioned, you are using Bootstrap, so best place to start looking at would be customize your build:
http://getbootstrap.com/customize/

How to validate javascript and html code? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
In our application end users are provided with a textbox where they can paste their html or javascript code to create advertisement much like Google advertisement , so I need to validate these html and js source code against malicious code and also proper syntax .
So are there any API's available in java to do the same ?
Thanks in advance
Ali.
Validating JS client-side is only useful to your nice users - since malicious users can bypass any client-side validation code anyway (by messing with the JS that is supposed to do the validation).
Validating JS server-side to look for "maliciousness" is, in the general sense, impossible unless you have a very restrictive white-list to check against. It is better to execute things in a sandbox that protects against bad things, and avoid validation (= checking for validity in advance of execution) altogether.
So, JavaScript Sandboxes. The most used is probably Google Caja - also protects against bad html/css. Sandboxing is not easy - in particular, Caja needs a server-side part to "cajole" the files and protect the host page; and any parts of the host-page outside the cajoled div need to be identified up-front.
See also some alternatives from another SO question. Note that many of them do not allow DOM access from protected code, and therefore not useful for JS that actually has to show things on screen.
You can find a lot of sources on the Internet if you search it. Here are a few: Java Encoder Project and Java HTML Sanitizer. I've never used them, but it's a starting point. You can learn a lot if you do the research yourself.
Edit: It's unclear if you're looking for a Java API or a JavaScript API. They're quite different.

Javascript library for graphs (in the mathematical sense) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Are there any significant Javascript libraries for graph and network representation, with common algorithms, optimization, etc.? I'm imagining something like the C++ lemon library, with graph search, shortest path, maximum flow, and so on.
Google draws a blank, because the results are completely flooded with graph- and chart-drawing libraries.
Take a look at http://www.graphdracula.net/
It's got a number of algorithms including:
bellman-ford
dijkstra
floyd-warshall
You may be interested in Cytoscape.js, an open-source JS graph theory library. It can be run headlessly or with an interactive visualisation. It is styleable via CSS-like files, has built in gestures, support for touch devices, node.js, etc.
There's a bunch of algorithms now, and there will be many more shortly -- i.e. more complex algorithms like PageRank etc.
http://cytoscape.github.io/cytoscape.js/
Disclaimer: I work on the project
node-dijkstra
A NodeJS implementation of Dijkstra's algorithm
Study a graph, generally require a lot of computer effort, expecially for large graph (I don't know what kind of graph you are trying to analyze) but if it is simple, probably you didn't need libraries. You will never find what you're looking for... it's even difficult to find something like that for the common languages, I don't think that a scripting language studied to render HTML page can help you, expecially because it lives embedded in a browser that is neither studied nor capable to have the proper performance to your purposes.
I'm sure that you're only way is programming and perform analyzes on your graph through a server side programming language, in this case you will have a dedicated machine that performs operation on a graph and it has more sense.
I suggest you .NET because you can use your lemon library ... By the way have you ever tried SNAP http://snap.stanford.edu/ it's the best library you will ever find, I really suggest as a C++ library... take care that it lacks on documentation.
I'm sorry for javascript, but you will realize that I'm right

Tutorial or Book on implementing a metalanguage in Javascript [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I've been working in Javascript and PHP but I find that the hardest part isn't the implementation but the design of the webapp architecture [as usual . . .] In that direction, I wanted to create a sort of meta-language that takes PHP code as input but outputs JavaScript code thus making the design and implementation phase less painful [s.t. similar to GWT, Google Web Toolkit]. I found writing the this interpreter from scratch [parser, lexer, . . .] a viable option but an long one. Then I came across Processing.js [a library created by John Resig] where the user actually write java-like code that is transformed in Javascript by Processing.js then evaluated. I've searched the web for tutorials that introduces this powerful Javascript capability but didn't find even one! Can anyone PLEASE help me with any link, book title where I can get a least an intorduction? Thanx for your response!!!!
I would say your best deal would be to go with Haxe.
Haxe is a language that is designed to target (be exported) into the following platforms:
JavaScript
Flash
PHP
C++
Making it a very powerfull resource when creating web Apps as you can write in Haxe and have all your code ported to JavaScript, Flash, PHP or C++ without hassle.
Honestly, I think processing.js is not suitable for what you want, it was made to deal with the new canvas element, not the webpage.
Also, I think (honestly) think it sucks. They parse processing using Regex, it is totally wrong, you can't parse a programming language using Regex.
There is a javascript compiler compiler, called JS/CC, it is very easy to use, just learn the grammar and you can make a simple programming language.
But if you wanna make a complicated language (like processing, or php) by yourself, get ready for the nightmares.
PS: You'll need to know Javascript to implement a programming language in Javascript...
How about creating some PHP-functions that generate JavaScript-code? I do not think that you really need to write an interpreter for a custom script language. Ruby on Rails used to generate some JavaScript with simple Ruby-code, for example.

Source code annotation tool [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm looking for a tool with which I can annotate source code.
I have some 3rd party source code (JavaScript) I need to understand and I don't want to change it (add inline comments) so that
line numbers can stay intact (for communication with others),
I can avoid accidentally changing something and
my annotations stand out compared to the authors comments.
Normally I would print the whole thing out an scribble on it, but the code is too long for that and I need to share it per email. I would be great if one could do some like that including being able to create "links" between so places in the code, possibly even visually with a lines or arrows.
If you would usually print it (if it were shorter), why not print it to a PDF and then use a PDF viewer that supports comments, like Foxit Reader? :)
I would use email to comment and pastebin to host and highlight #h# lines with links in the email text.
OR
some code-review tool (like codestricker or reviewboard for example)
You can certainly do what you want to with LaTeX and its listings package. But if you are not already a LaTeX user you might think that a hard way to go.
start a github project and post the code there, github includes annotation abilities OOB.
You have difficult requirements. I don't know of such tool. Nevertheless as a more general purpose tool, I can recommend Yui Doc (download here).
I'd build a glamour browser for it. (If spending half a day building it wouldn't be too much).
[edit]
Glamour is a toolkit for building browsers on a model. The model would here consist of the various parts of the file(s) and the comments and attributes you'd like to add. This would allow you to easily navigate through the source and comments, to select only parts with (or without) certain attributes. There is a video and slides. Official page, Source
How about using google wave with syntaxy (http://wave-samples-gallery.appspot.com/about_app?app_id=14008) bot?

Categories

Resources