MathJax with AsciiMath renders the expression 1,000/5 as 1, 000/5, where the numerator of the fraction just shows as 000 instead of 1,000.
JSFiddle: https://jsfiddle.net/kai100/wLhbqkru/
The MathJax documentation is silent about thousands separators.
The Stack Overflow answer below answers this question for TeX input, but I need it for input in AsciiMath format, and have not been able to make it work by changing "Tex" to "AsciiMath" in the config file:
mathjax commas in digits
Any help would be much appreciated. Thank you.
Setting
decimal: ','
tells AsciiMath to use the European number format, which uses a comma as the decimal place separator rather than a period. That is why you are not longer seeing "0.12" treated as a number. AsciiMath does not have a mechanism of parsing commas every three digits.
The best I can suggest is use a AsciiMath pre-filter to pre-process the AsciiMath to remove the commas before AsciiMath parses the expression. Adding something like
<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("AsciiMath Jax Ready", function () {
function removeCommas(n) {return n.replace(/,/g,'')}
MathJax.InputJax.AsciiMath.prefilterHooks.Add(function (data) {
data.math = data.math.replace(/\d{1,3}(?:\,\d\d\d)+/g,removeCommas);
});
});
</script>
to the page just before the script that loads MathJax.js should do the trick. Note that this will mean the commas don't appear in the output, either; there is no natural way to do that, unless you wanted to add commas to ALL numbers that have 4 or more digits (even if they didn't have commas to start with). That would require a post-filter to go back over the MathML that is produced and convert the numbers to having the commas. Something like:
MathJax.Hub.Register.StartupHook("AsciiMath Jax Ready", function () {
function removeCommas(n) {
return n.replace(/,/g,'');
}
function addCommas(n){
return n.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
function recursiveAddCommas(node) {
if (node.isToken) {
if (node.type === 'mn') {
node.data[0].data[0] = addCommas(node.data[0].data[0]);
}
} else {
for (var i = 0, m = node.data.length; i < m; i++) {
recursiveAddCommas(node.data[i]);
}
}
}
MathJax.InputJax.AsciiMath.prefilterHooks.Add(function (data) {
data.math = data.math.replace(/\d{1,3}(?:\,\d{3})+/g, removeCommas);
});
MathJax.InputJax.AsciiMath.postfilterHooks.Add(function (data) {
recursiveAddCommas(data.math.root);
});
});
should work.
The AsciiMath configuration options are unfortunately not properly documented.
You can specify this via
//...
AsciiMath: {
decimal: ","
},
//...
in your MathJax configuration block.
Note that this causes various parsing complications for (e.g., (1,2) ).
For completion, the documentation is at http://docs.mathjax.org/en/latest/options/input-processors/AsciiMath.html
Related
I'm trying to take an input from the user using an Input Text field, this data is a number. I want the user to input the correct number (in this case 1) and then print out yay.
However, i can't get it to work. Any help is much appreciated.
I assume the issue is to do with comparing an int and a string, but honestly im not sure anymore.
import flash.events.MouseEvent;
import flash.text.TextField;
var dayVar:String = dayInput.text;
var dayNum:Number = Number(dayVar);
stop();
button3.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler3);
function mouseDownHandler3(event:MouseEvent):void
{
if(dayNum == 1) {
trace("yay");
} else {
trace("nay");
}
}
You will have to update your dayVal and/or dayNum after user has given input. So in this minimal case you can simply:
function mouseDownHandler3(event:MouseEvent):void{
if(Number(dayInput.text)==1) {
trace("yay");
} else {
trace("nay");
}
}
Other possibilites would be listening Event.CHANGE for the text input, or KeyboardEvent to update your variables, but in this case the MouseEvent handler does the job easier.
You can use restriction property for text field input like this:
dayInput.restrict = "0-9";
This should omit to type only digits.
I'm new to Protractor and I'm trying to retrieve only the numeric values contained in the following element
<div class="balances">
<h3>Total Balance: EUR 718,846.67</h3>
</div>
I'm able to retrieve the whole text but would like to be able to print off just "718,846.67" (or should it be 718846.67") via my page object file
checkFigures (figures) {
browser.sleep(8000);
var checkBalance = element.all(by.css('balances'));
checkBalance.getText().then(function (text) {
console.log(text);
});
}
I came across this when someone posted a similar question but I have no idea how to implement it or what it is even doing
function toNumber(promiseOrValue) {
// if it is not a promise, then convert a value
if (!protractor.promise.isPromise(promiseOrValue)) {
return parseInt(promiseOrValue, 10);
}
// if promise - convert result to number
return promiseOrValue.then(function (stringNumber) {
return parseInt(stringNumber, 10);
});
}
This is just a javascript question, and easily acomplished with replace and a regular expression. This will remove all non numerics from the string. Alter the regular expression as needed.
checkFigures (figures) {
browser.sleep(8000);
var checkBalance = element.all(by.css('balances'));
checkBalance.getText().then(function (text) {
console.log(text.replace(/\D/g,''));
});
}
how can I tell "sanitize-html" to actually remove the html tags (keep only the content within)? currently if for example I set it to keep the div sections, in the output it writes also the <div>some content</div> - I want only the inside...('some content')
to make it short - I don't want the tags, attributes etc. - only the content of those elements..
var Crawler = require("js-crawler");
var download = require("url-download");
var sanitizeHtml = require('sanitize-html');
var util = require('util');
var fs = require('fs');
new Crawler().configure({depth: 1})
.crawl("http://www.cnn.com", function onSuccess(page) {
var clean = sanitizeHtml(page.body,{
allowedTags: [ 'p', 'em', 'strong','div' ],
});
console.log(clean);
fs.writeFile('sanitized.txt', clean, function (err) {
if (err) throw err;
console.log('It\'s saved! in same location.');
});
console.log(util.inspect(clean, {showHidden: false, depth: null}));
var str = JSON.stringify(clean.toString());
console.log(str);
/*download(page.url, './download')
.on('close', function () {
console.log('One file has been downloaded.');
});*/
});
I'm the author of sanitize-html.
You can set allowedTags to an empty array. sanitize-html does not discard the contents of a disallowed tag, only the tag itself (with the exception of a few tags like "script" and "style" for which this would not make sense). Otherwise it wouldn't be much use for its original intended purpose, which is cleaning up markup copied and pasted from word processors and the like into a rich text editor.
However, if you have markup like:
<div>One</div><div>Two</div>
That will come out as:
OneTwo
To work around that, you can use the textFilter option to ensure the text of a tag is always followed by at least one space:
textFilter: function(text) {
return text + ' ';
}
However, this will also introduce extra spaces in sentences that contain inline tags like "strong" and "em".
So the more I think about it, the best answer for you is probably a completely different npm module:
https://www.npmjs.com/package/html-to-text
It's widely used and much better suited than your use case. sanitize-html is really meant for situations where you want the tags... just not the wrong tags.
This only happens in IE.
I'm using swfobject and loading the flash vars as such
var flashVars = {
myVar:'{"url":"http://google.com/", "id":"9999"}',
};
var params = {
allowFullScreen:"true",
wmode:"transparent",
allowScriptAccess:'always'
};
swfobject.embedSWF("mySwf.swf", "mySwf", "512", "318", "10.0.0", "./js/swfobject/expressInstall.swf", flashVars, params);
Everything works perfectly in all browser but IE. I checked myVar and it comes into the swf as { and that's it. I know it's dying at the '. I've tried putting a \ infront, then tried \\ and kept adding one slash until I got to \\\\\\\\. I even inverted all the slashes and tried the same ritual. Nothing.
I can get the string to finally come through, with inverted quotes and using double slashes, but then my JSON parser gets mad about there being slashes in my string.
Here's an example of what works, but of what is invalid JSON:
"{\\'url\\':\\'http://google.com/\\', \\'id\\':\\'9999\\'}"
Yep IE treats flashVars differently to all the other major browsers, I believe you need to make use of the JavaScript encodeURIComponent method which will escape all reserved characters from your String, eg:
// Removing all reserved characters from the flashVar value.
var flashVars = {
myVar: encodeURIComponent('{"url":"http://google.com/", "id":"9999"}'),
};
If you are passing multiple values in the flashVars then you could iterate through them and encode all chars in a single pass:
var flashVars = {
myVar: '{"url":"http://google.com/", "id":"9999"}',
anotherVar: 42
};
// Escape all values contained in the flashVars object.
for (key in flashVars) {
if (flashVars.hasOwnProperty(key)) {
flashVars[key] = encodeURIComponent(flashVars[key]);
}
}
As #dgmdan and #bcmoney suggested, it would probably make your code easier to read if you made use of JSON.stringify - however, you need to bear in mind that IE8 and below do not have a native JSON object, so you will need to include Crockford's JS Library in your HTML page.
// Making use of a JSON library.
var flashVars = {
myVar: encodeURIComponent(JSON.stringify({ url: "http://google.com/", id: "9999"})),
};
Also, it's worth bearing in mind that flashVars are limited to ~64k; so if you are planning to pass a lot of data, it might be better to use an ExternalInterface call to pull them from the JavaScript instead.
Try this to replace your first 3 lines:
var subVars = { url: "http://google.com/", id: "9999" };
var flashVars = { myVar: JSON.stringify(subVars) };
I've tried looking this up and haven't come up with the answer I'm looking for; I've found what cannot be included in filenames, folder names, and site names... but nothing on actual fields in a list.
I noticed that the percent symbol (%) is one that's not allowed in files/sites/folders. But it also doesn't populate when I try to pro grammatically add the fields to the list. I am doing this by using a small C# application that sends the data via Sharepoint 2010's built-in web services. I can manually enter the character, but it messes up each field in the row if I try it through code.
I've tried some of the escape characters that I've found via Google (_x26), but these don't seem to work either. Has anyone else had an issue with this? If these characters are allowed, how can I escape them when sending the data through a web service call?
Thanks in advance!
Justin
Any characters that aren't allowed when you enter a field name get encoded in the internal name. The format is a little different to what you show - try "_x0026_".
I usually avoid issues with weird internal names by creating the field with no spaces or special characters in the name, then renaming it. When you rename a field, only the display name changes and you keep the simple internal name.
Characters not allowed in SharePoint file name:
~, #, %, & , *, {, }, \, :, <, >, ?, /, |, "
Pasted from http://chrisbarba.com/2011/01/27/sharepoint-filename-special-characters-not-allowed/
Am I saying something weird when I state that there usually is a reason for certain characters not being allowed. I don't know which or why, but there probably is a reason.
Since you control which fields need to be there you can also dictate their (internal) names. I'd say follow best practice and name your fields using Camel case. And because you created them, you can just map the fields to the according fields in your data source.
As a follow on to #Elisa's answer, here's some JavaScript / TypeScript code that helps to prevent users from uploading files into SharePoint with invalid characters in the file name implemented on Nintex forms.
Here's the gist of the JavaScript version (note you'll have to obviously adapt for your own needs since this was designed for Nintex) :
//------------------------------------------------------------------------
//JavaScript Version:
//Code from http://cc.davelozinski.com/tips-techniques/nintex-form-tips-techniques/javascript-typescript-for-nintex-forms-to-validate-file-names
//------------------------------------------------------------------------
function validateAttachmentNames(eventObject) {
var textbox$ = NWF$(this);
var attachrowid = this.id.substring(10, 47);
var fileUploadid = attachrowid;
var index = attachrowid.substring(36);
//console.log('index:' + index);
//console.log('attachrowid:' + attachrowid);
//console.log('fileUploadid:' + fileUploadid);
if (index == '') {
attachrowid += '0';
}
var fileName = NWF.FormFiller.Attachments.TrimWhiteSpaces(textbox$.val().replace(/^.*[\\\/]/, ''));
var match = (new RegExp('[~#%\&{}+\|]|\\.\\.|^\\.|\\.$')).test(fileName);
if (match) {
isValid = false;
setTimeout(function () {
NWF$("tr[id^='attachRow']").each(function () {
var arrParts = (NWF$(this).find(".ms-addnew")[0]).href.split('"');
var fileName = arrParts[5];
var attachRow = arrParts[1];
var fileUpload = arrParts[3];
var match = (new RegExp('[~#%\&{}+\|]|\\.\\.|^\\.|\\.$')).test(fileName);
if (match) {
console.log(fileName);
NWF.FormFiller.Attachments.RemoveLocal(attachRow, fileUpload, fileName);
alert('Invalid file: ' + fileName + ' You cannot attach files with the following characters ~ # % & * { } \ : < > ? / + | \n\nThe file has been removed.');
}
});
}, 500);
}
}