I created the below JavaScript Code Template in Netbeans 7.1.1
This is to generate code automatically in the editor, instead of typing it.
do_this('${selection}${cursor}',13)
which will result in the below code, with the cursor between quotes
do_this('',13)
The template automatically places the text I have highlighted, between quotes.
Now, the problem: I would like to replace any spaces within the selected/highlighted piece of code, with underscores. I think this may be possible with Regular Expressions (regex), however I am not sure how to go about it.
Thanks
Not sure about the Netbeans specific stuff, but once you have the selection you could do something like this:
selection = selection.split(" ").join("_");
This is not possible in NetBeans Code Templates, as they do not have any functions to manipulate the data in variables. If I have a work around for it, I will post it here.
Thanks.
Related
I am struggling with strange behavior of textarea... I am writing small snippet store for my own needs and I would like to paste a code fragment into textarea and then format it using jQuery library, but sometimes I get very strange output (jQuery library is turned off). Screenshot shows it all:
In notepad it looks the way I want it, but in pre tag first line is not indented... Could you explain me why? I am using Ruby and Ruby on Rails if it matters.
Thanks in advance!
So, you're populating the textarea from RoR, right?
I don't suppose it's as simple as your <% %> being on a new line, and then your code indenting adding extra spaces in?
I am trying to deploy my bookmarklet in public, but I am not sure what is the best way to do it. Suppose I have,
javascript:(function(){console.log("hello");}())
And I make it draggable to the bookmarklet by enclosing it within a href tag. The trouble is that HTML special characters are encoded like %07d for the above snippet. What's the conventional way to solve this problem?
Thank you!
It should work fine, till it is in the following format.
Bookmarklet
Note: I changed console.log() to alert() to make the result view able immediately.
Live Demo: http://jsfiddle.net/qyL4L/
So I'm working on a micro lib, html.js, and basically it creates text nodes with document.createTextNode but when I want to create a text node with a b I get a b so I'm wondering how to escape the & char, without using innerHTML ideally..
Javascript supports the \uXXXX notation, so in the case of a non-breaking space, that would be \u00A0.
document.createTextNode('a\u00A0b');
That's as far as you can get. It's a text node, consisting only of text, and there's no difference between texts created from entity references or from normal characters.
If that's not what you want, you should take a second look at innerHtml. Can't you read it, modify it and put it back?
There's not much functionality in js to encode/decode html entities. Seems like there some libraries out there, though, that can help you achieve this. Here is one I found on goodle.. haven't tried it, but you can check it out, or look for others.
http://www.strictly-software.com/htmlencode
Vim 7.0.237 is driving me nuts with indentexpr=HtmlIndentGet(v:lnum). When I edit JavaScript in a <script> tag indented to match the surrounding html and press enter, it moves the previous line to column 0. When I autoindent the whole file the script moves back to the right.
Where is vim's non-annoying JavaScript-in-HTML/XHTML indent?
Here is similar question with accepted answer with links to two vim plugins:
html improved indentation : A better indentation for HTML and embedded javascript mentioned by Manni.
OOP javascript indentation : This indentation script for OOP javascript (especially for EXTJS) .
One of them solved my problems with JavaScript scripts indention problems.
Have you tried this plugin?
I recommend installing vim-javascript.
It is an up-to-date plugin that properly indents javascript, including more recent developments like the syntax used in closures such as with jQuery.
Personally I toggle between :set ai and :set noai, but might be too tedious for you.
I have plugins for indenting HTML and JavaScript files. To indent JavaScript inside HTML, I temporarily change the file type, select and indent the lines, and then change the file type back.
:filetype javascript
(select lines)
=
:filetype html
It's a little tedious, but it always produces the results I expect.
Quick question,
If I want to document some code on a basic HTML and put that within a CODE tag, how can I quickly convert the code between those tags when the page renders to display properly? I know I can write a javascript find and replace and search through the string over and over until its done replacing all the characters, but is there a better way?
Or, is there a jQuery way to do it if I need to use javascript?
I think the <code> tag is more for displaying with a certain font, rather than layout. <code> seems to just use a monospaced font.
You might be looking for the <pre> tag (for pre formatted). That will preserve line breaks and spaces.
Unless the code you are trying to display is HTML code itself, then I think you'd have to change all the <'s to <'s ahead of time
Sounds like you may be looking for syntax highlighting. Take a look at google's syntax highlihter