Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Can i use regex? if yes, how do i replace every match with a span tag? if no what can i use? a dictionary with all possible html tags? This is for solely educational purposes so please don't refer me to a JavaScript library.
It's similar to how you would do syntax highlighting in any other language. Typically, you would implement a tokenizer which breaks the html snippet into individual tokens (e.g. using regular expressions), and then you would apply styling rules to the tokens.
I would look at Prism. Its code is pretty simple. The core is here:
https://github.com/LeaVerou/prism/blob/gh-pages/components/prism-core.js
This contains the tokenization and highlighting functions. The regular expressions for HTML/XML are in this file:
https://github.com/LeaVerou/prism/blob/gh-pages/components/prism-markup.js
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
For my project I am not allowed to write any JavaScript into my HTML according to my teacher. That would mean that I am not allowed to write features like onClick in my HTML. I want to check a answer with the if statement by giving my buttons value's, but isn't that also seen as writing JavaScript into HTML?
I know the best thing to do would be contact my mentor, but I want to know your answer/opinion on this.
you can use JS function to get elements from the HTML such as document.getElementById or document.querySelector and bind them an event listener.
you can read more about on MDN
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I would love to learn how to do javascript obfuscation. I have been searching through the web but I have not found anything to start with. Only posts about tools and more tools...
Is there any book?
What techinques are there?
Can someone show me some link to understand javascript obfuscation?
There are several ways to do it?
Is this explained in the javascript or ecmascript documentation?
I'm not looking for any tool. I only want to understand it and learn it.
The most comprehensive obfuscation method is converting all JavaScript code to non-alphanumeric characters. This blog post covers how it works and links to a converter tool in case you change your mind.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a lot of elements that are created on the fly from data received on the server, as JSON. To create these elements a lot of HTML is going inside my JavaScript code. Is there any solution to this problem? The JavaScript code is polluted and writing HTML tags becomes harder and less maintainable.
Templating tools such as handlebars, mustache and dust.js were designed to solve this very problem.
Ember.js is another alternative that allows you to remove HTML from your JavaScript through their templating tool called HTMLBars.
Check it out!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Both seem to be doing very similar things, in a similar way.
Both let you embed javascript into the templates, and have the same 3
types of tags -unescaped replace, escaped replace, embed js-.
Both have the ability to 'precomile' the template by creating the
generator function.
Also, both can be used as the template engine
for express/node.js. (and in the browser, and everywhere else that supports js).
So when having to choose beween EJS and underscore.js templates: what things should be taken into account? Are they the same thing with just different name? If this is the case, why is it that there are 2 template engines so similar?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I cant use the script tags
It alerts when I do , which is only useful for testing.
It filters them out:
script > *
SCRIPT > SCRIPT
sCriPt > sCriPt
so, i try to use capital script tags
but it turns to:
*CRIPT>alert(1)</SCRIPT>
I have tried using multiple tags.
How can I inject regular javascript with this?
Oh, and I cant use quotes.
Just so you know, there is an XSS Cheat Sheet you can refer to.