I have implemented the latest code mirror in our asp.net application. the editor allows to type javascript which has commented code and un commented code.
I want to know whether all the code written in the editor is commented or not.
Can anyone please advice.
You can fetch the document text, than pass it through a regex, filtering out all the comments:
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
lineNumbers: true
});
var out = document.getElementById('out');
out.textContent = editor.getValue()
.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:[\s;]+\/\/(?:.*)$)/gm, '');
Demo
Related
i was trying this code but getting error at run time. i want if IsUPS has true value then a new table row & table data will be added to table if IsUPS is false then table will have one table row and data? how to achieve this with razor template? please guide. thanks
string template = "<table><tr><td>This is my sample template,
Hello #Model.Name!</td></tr> #if (#Model.IsUPS) {<tr><td> it is ups</td></tr> }
</table>";
string result = Razor.Parse(template, new { Name = "World", IsUPS = true });
Assuming your "string result =" line works correctly;
There's quite a few things I would do differently here.
The error message (you should really have shared what the error is), related to your use of "#".
Try this:
#{
string template = #"<table><tr><td>This is my sample template, Hello" + this.Model.Name + #"!</td></tr>";
if (true)
{
template += #"<tr><td> it is ups</td></tr>";
}
template += #"</table>";
}
The "#{ }" block encapsulates the html in a razor block so the use of # for razor changes. Please note I have made the strings use #"" rather than "" so that if you want to split the html between lines you won't need to have string concatenation.
Firstly: I believe that an error produces a following statement:
#if (#Model.IsUPS)
it should rather be:
#if (Model.IsUPS)
after first # you should put server-side code, so another # is not neccessary when writing condition.
Secondly: Is the template pasted in one-line? If not, you need to use verbatim string:
string template = #"<table><tr><td>This is my sample template,
Hello #Model.Name!</td></tr> #if (Model.IsUPS) {<tr><td> it is ups</td></tr> }
</table>";
Thirdly: show us an error you get. Are you using RazorEngine library?
Fourth: after my fixes that code should work, checked myself.
I have pretty annoying problem. :)
visual = context.ActiveVisualReference;
TablePlot tablePlot = visual.As<TablePlot>();
colorings = tablePlot.Colorings;
categories = colorings.GetCategories();
coloring1 = colorings.GetColoringForCategory(categories[0]);
coloring2 = colorings.GetColoringForCategory(categories[1]);
coloring3 = colorings.GetColoringForCategory(categories[2]);
category2 = categories[2];
bool removed = colorings.Remove(coloring2);
This is the C# code I execute at the custom Tool level and the problem is that I do not see any effect within the Web Professional (using 5.5)
of the Remove method execution.
According to the documentation the method should remove the custom coloring from visualisation and it does NOT.
Perhaps it is needed to call some method that refreshes view but I didnt manage to locate it.
Please help. :)
http://stn.spotfire.com/dxp/html/M_Spotfire_Dxp_Application_Visuals_ConditionalColoring_ColoringCollection_Remove.htm
Have you tried tablePlot.Colorings = colorings at the end of your code ? What is the value of "removed" at the end of your code ?
In ironPython this one works:
from Spotfire.Dxp.Application.Visuals import TablePlot
print myVisual.Title
myTablePlot = myVisual.As[TablePlot]();
print myTablePlot.Title
myColorings = myTablePlot.Colorings;
myCategories = myColorings.GetCategories();
print myCategories.Count
myColorings.Remove(myColorings.GetColoringForCategory(myCategories[1]))
I meet a strange behavior. I dont understand my mistake.
I want to read a value from an HTML page. I can obtain it with :
JavaScript
function getSize() {
return (size.toString());
}
getSize();
Output (in Chrome console)
120
C#
// wBrowser is not null and the page is loaded
String o = wBrowser.InvokeScript("eval", "getSize();").ToString();
Debug.WriteLine(o);
Here o is empty.
I read the msdn doc and try some research without success. What am I missing?
Thank you.
Well ...
Just found my error.
My solution is working. Lukasz's solutions works too.
I just forgot to swith the run mode from Release to Debug ...
So working solutions are :
String o1 = wBrowser.InvokeScript("eval", "getSize();").ToString();
// Lukasz's 1st solution
String o2 = wBrowser.InvokeScript("getSize").ToString();
// Lukasz's 2nd solution
String o3 = wBrowser.InvokeScript("eval", "size.toString();").ToString();
Both print the right size.
Maybe it could be helpful for someone else ...
I want to achieve functionality to store adsense code into sql database. For that I have used ajax:HtmlEditorExtender on a textbox. now I am typing this code
<script type="text/javascript"><!-- google_ad_client = "ca-pub-*****"; /* 728x90, created 6/12/02 */ google_ad_slot = "****"; google_ad_width = 728; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead.googlesyndicaon.com/pead/show_ad.js"> </script>
now the problem is when the code is inserted to database, above code is converted as below.
<pre><<span>script</span> <span>type</span>="<a>text/javascript</a>"><!--
<span></span>google_ad_client = "ca-pub-*****";
<span></span>/* 728x90, created 6/12/02 */
<span></span>google_ad_slot = "****";
<span></span>google_ad_width = 728;
<span></span>google_ad_height = 90;
<span></span>//-->
<span></span></<span>script</span>>
<span></span><<span>script</span> <span>type</span>="<a>text/javascript</a>"
<span></span><span>src</span>="<a href="view-source:http://pagead.googlesyndicaon.com/pead/show_ad.js">
http://pagead.googlesyndicaon.com/pead/show_ad.js</a>">
<span></span></<span>script</span>></pre>
Please help me out:
what should I do so that i can store the upper code as it is to database.
when the code is properly stored to database, which control is best suitable to show this ad.(I mean I want to show ad on another page.)
Thanks in advance.
RE issue2: You could use a normal textbox and just decode the string, or put it back into a ajax:HtmlEditorExtender textbox, and use the following code (sanitizer has probably encoded all the tag start and ends etc...
Server.HtmlDecode(TextBox_Editor.Text)
In response to your comment: Try putting the decoded text into a asp:label OnPreRender
EDIT: Try using HtmlAgilityPackSanitizerProvider, the latest pack which resolves some 'bugs' surrounding the sanitizer... have a read of this page, by Stephen Walters own admission the default sanitizer is far too aggressive in what it strips.
I'm relatively new to Javascript, and although I know how to use it, I don't really understand the mechanics behind it. Bear with me here.
I need to write a small app that creates a chart (in SVG) based on data I take in as an XML file. I found PlotKit, which does exactly what I need, except that it's written in Javascript, while my current program is written in c#. I did some googling and found a few articles which explain how to evaluate simple Javascript code using the .NET VsaEngine class. Unfortunately, I have absolutely no idea how to use the VsaEngine to execute more complicated Javascript that requires references to other files. Basically, all I want is for c# to be able to call something like this as Javascript:
var layout = new PlotKit.Layout("bar", {});
layout.addDataset("data", [[0, 0], [1, 1], [2, 2]]);
layout.evaluate();
var canvas = MochiKit.DOM.getElement("graph");
var plotter = new PlotKit.SVGRenderer(canvas, layout, {});
var svg = SVGRenderer.SVG();
And get back the SVG string for the chart. I have no idea how to make it so that the above script knows where to look for all of the necessary objects. If I were to make a web page to do this, I would just add a few script headers referencing /plotkit/Layout.js, /plotkit/Canvas.js, etc., the Javascript would work fine.
If anyone could explain exactly how I would use PlotKit through C#, or could explain a more effective way to do this, I would really appreciate it.
EDIT: I realize I wasn't too clear with this question - I need my c# program to emulate a Javascript engine and use the PlotKit library without actually running a web browser. Is there any way to do this?
PlotKit is a JavaScript library that is intended to execute in the Client's Web Browser. C# is executed on the Server. To go about communicating between the two, you would render whatever data you wish to pass to PlotKit on the server and then output it in the HTML you send to the client.
So in your C# codebehind you would construct the JSON object that would be passed to PlotKit's addDataset method.
...
public partial class Default : System.Web.UI.Page
{
protected string PlotKitData = "[]";
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack) PlotKitData = GenerateJSON();
...
Then in your ASPX codefront you would have something like this.
<script>
var layout = new PlotKit.Layout("bar", {});
layout.addDataset("data", <%=PlotKitData%>);
layout.evaluate();
var canvas = MochiKit.DOM.getElement("graph");
var plotter = new PlotKit.SVGRenderer(canvas, layout, {});
var svg = SVGRenderer.SVG();
</script>
Perhaps ZedGraph might suit your needs instead?