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?
Related
I'm working on an extension and I would like to add some functionality so that I can search for a chunk of code and highlight it so that I can then call collapseSelectedCodeFragment on it and automatically collapse said code (just to keep everything organized).
However, I'm not sure how to go about finding and highlighting the code chunk in the code viewer.
This is how I ended up doing this for anyone wondering:
dreamweaver.setUpFind({searchString: newString, searchWhat: "document", searchSource: true});
dreamweaver.canFindNext(true);
dreamweaver.findNext();
dom.collapseSelectedCodeFragment(false);
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.
I am using SyntaxHighlighter on my website and it is acting very strange. I put my codes in <pre>s and used SyntaxHighlighter.all(), and what I got are in every single codes, it inserted 1~2 extra lines.
Where's the problem? I checked everything and everything is fine. Please help.
I don't know about SyntaxHighlighter, but in general, the <pre> tag works effective immediately, LF and CR everything. When Syntax Highlighter does its conversion, it might be respecting these line feeds as well. For example:
<pre>
There will be a line before and after this
</pre>
vs.
<pre>There will be no lines</pre>
We're used to writing well-formatted and well-indented code, but with pre tags you have to make an exception. Looking at your source code, I think you're doing it the top way.
I have been looking around for a HTML formatter to incorporate with a project I am doing. I need it to be written in Javascript since I want the formatting done on the client side.
The problem is, the few that I have tried don't work very well... For example:
http://www.davidpirek.com/blog/html-beautifier-jquery-plugin : Has a problem with one of the For loops (in the cleanAsync function). Chrome says "unexpected token ILLEGAL"
JS Beautifier on GitHub : When I have links in the HTML it will put a newline character after it. The problem is, I have a period directly after the link in some cases and it will add a space between the link text and the period in the sentence. I tried poking around to fix it but I could not.
Are there any others, or does anyone have recommendations to fix the above two?
EDIT:
This is for editing code, so I just need something to tab in the lines, etc. The code output will go in a textarea.
A few to look at, all have working demos:
http://alexgorbatchev.com/SyntaxHighlighter/
http://shjs.sourceforge.net/
http://jush.sourceforge.net/
http://dojotoolkit.org/reference-guide/dojox/highlight.html
use https://github.com/beautify-web/js-beautify and pass your code to html_beautify() method.
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.