How to add 2 numbers display the result in HTML without Javascript - html

As the question, I'm coding such as (value x) * (value y) to directly display the result in HTML in software.
But the software doesn't support the script tag. can we simply use HTML tag achieve function.
In the software I have the subtotal example $55.25, but I want it shows $$65.00 (calculate by $55.25 / 0.85)
enter image description here

HTML cannot do math - it is a markup/layout language. Whatever logic you are using that is creating the items to add to the template will need to also do the math and send the result to the template.

Related

Replace Placeholder HTML comment with HTML element

I'm developing an iOS app that needs to display HTML content inside a HTML powered textview (DTCoreText).
For whatever reaso nthe client has decided to provide videos inside special HTML comments that I'm supposed to turn into a tag.
The comment format is as such
<!-- placeholder_video:url_of_video.mp4 -->
I was hoping I could write a regex to match the entire comment, extract the content and replace it with a element pointing to the correct URL through NSRegularExpression's stringByReplacingMatchesInString:options:range:withTemplate: but I can't for the life of me figure out Regular Expressions.
The best I could come up with is
(?<=<!-- placeholder_video:)(.*)(?=-->)
Which matches the comment's content (the mp4 URL), but I need it to match the entire comment instead and extract the content as a sub pattern (that I would later access through \1 if I understand correctly) so I can use a replace pattern to quickly replace the comment with the proper <video src="url_of_video.mp4"> string
Can it be done? Or am I better off trying to do it in two passes instead? (match the entire comment then run another regex on that comment to extract the URL and replace the former?
Based on the way your question looks right now (Having forgotten to paste the example of how the comment looks) it's hard to give a good answer.
But since you mention that this:
(?<=<!-- placeholder_video:)(.*)(?=-->)
will manage to fetch the content of the comment. And since you say all you want is to capture the entire comment.
Then if I understand this correctly I would say all you really need to do is add a capturing group around your entire expression and drop the lookback and lookahead.
(Maybe also avoid grabbing the leading and trailing spaces)
(<!-- placeholder_video:\s*(.*)\s*-->)
When testing with the following:
<!-- placeholder_video: url_of_video.mp4 -->
I will get 2 groups:
1: <!-- placeholder_video: url_of_video.mp4 -->
2: url_of_video.mp4
You can also give your groups names if you like, to make it easier to reference them:
(?<comment><!-- placeholder_video:\s*(?<url>.*)\s*-->)
It is also true that you can use \n to reference group n inside the regular expression.
If you plan to replace the first capturing group with the second one in a single regex, then how you do it would depend on the language. Some languages like C# will allow you to provide your own replacing method, which is one option. But I'm assuming you're not in C# here.
In Javascript you can simply use $n to reference the n'th matched group as the replaced value. (You can also provide a function, but you don't need to)
A full working example in JS (Using jQuery but not needed):
<div id="example">
<!-- placeholder_video: url_of_video.mp4 -->
</div>
<script>
var str = $("#example").html();
var str2 = str.replace(/(<!-- placeholder_video:\s*(.*)\s*-->)/g, "<video src=\"$2\">");
alert(str2);
</script>
You can see the working jsfiddle example here: http://jsfiddle.net/72WeZ/

Latex as copyable text not as image

According to https://chemistry.meta.stackexchange.com/a/88, Stack Exchange sites use MathJax to format math equations.
When I looked at the demo page (http://www.mathjax.org/demos/tex-samples/), the source code for the first example is:
\[\begin{aligned}
\dot{x} & = \sigma(y-x) \\
\dot{y} & = \rho x - y - xz \\
\dot{z} & = -\beta z + xy
\end{aligned} \]
Since the result is text, I am assuming that some fancy CSS makes it look nice like that. My question is can someone help me find a way to get that CSS and convert that code to raw HTML that looks the same?
If you are using Firefox, you can install a browser AddOn called "Web Developer" which will give you an added menu bar. One of the commands available from this bar is CSS/Display Style Information. You can then select any element on the page and the styling for the element will be shown in separate window at the bottom of the page. By using this, you can potentially reconstruct from scratch the HTML styling for a particular element or set of elements.

How to generate hash from ~200k text/html that would match/compare to similar text?

I would like to make a sort of hash key out of a text (in my case html) that would match/compare to the hash of other similar text
ex of matching texts:
"2012/10/01 This is my webpage #1"+ 100k_of_same_text + random_words_1 + ..
"2012/10/02 This is my webpage #2"+ 100k_of_same_text + random_words_2 + ..
...
"2012/10/02 This is my webpage #2"+ 100k_of_same_text + random_words_3 + ..
So far I've thought of removing numbers and tags but that wold still leave the random words.
Is there anything out there that dose this?
I have root access to the server so I can add any UDF that is necesare and if needed I can do the processing in c or other languages.
The ideal would be a function like generateSimilarHash(text) and an other function compareSimilarHashes(hash1,hash2) that would return the procent of matching text.
Any function like compare(text1,text2) would not work as in my case as I have many pages to compare (~20 mil at the moment)
Any advice is welcomed!
UPDATE:
I'm refering to ahash function as it is described on wikipedia:
A hash function is any algorithm or subroutine that maps large data
sets of variable length to smaller data sets of a fixed length.
the fixed length part is not necessary in my case.
It sounds like you need to utilize a program like diff.
If you are just trying to compare text a hash is not the way to go because slight differences in input cause total and complete differnces in output. (Thus the reason why they are used to encode passwords, and secure text). Character difference programs are pretty complicated, unless you really are interested in how they work and are trying to write your own I would just use a solution like the one that is shown here using sdiff to get a percentage.
Percentage value with GNU Diff
You could use some sort of Levenshtein distance algoritm. this works for small pieces of text, but I'm rather sure that something similar can be applied to large chunks of text.
Ref: http://en.m.wikibooks.org/wiki/Algorithm_implementation/Strings/Levenshtein_distance
I've found out that tag order in webpages can create a very distinctive pattern, that remains the same even if portions of text / css / script change. So I've made a string generated by the tag order (ex: html head meta title body div table tr td span bold... => "hhmtbdttsb...") and then I just do exact matches between these strings. I can even apply the Levenshtein distance algorithm and get accurate results.
If I didn't have html, I would have used the punctuation/end-lines for splitting, or something similar.

How to check if html contains a certain number with iMacros

I would like to use iMacros to check a html site if it contains certain numbers. if it does, then I would like to assign a variable according to a number that has been found.
Like if the html contains 112233 then I woul like to assing Var1 to be 123
if the html contains 223344 then I want Var1 to be 645
What would be the way to do this?
Thanks!
Wow! That is a typical case for iMacros EVAL!
Extract the element's text with TAG and assign the value to !VAR1, using EVAL for the conditional.
If the text is not inside an html element (it could be in a comment, for instance) and so, not reachable by the TAG command, sou can try with SEARCH, which does offer some regular expression facility as well.

Converting digits, generated by weblog service, to Arabic form

sorry if this is irrelevance :-)
I need to write something in my html code to convert digits of form 0123456789 to ۰۱۲۳۴۵۶۷۸۹ (Persian digits uni06F0..uni06F9).
the number of visitors is generated by blog service. and I want to convert its digits to Arabic.
Counter:
تعداد بازدیدکنندگان : <BlogSky:Weblog Counter /> نفر
the Persian part of above code mean 'Number of visitors' and 'Persons' (from left to right). but digits are represented in latin (0123...).
Is it possible to write something like a function in html? i want it to be a global one for using in weblogs.
Note: I don't know anything about web programming languages. I'm not sure about language of above code. (html?)
HTML only describes the structure of the document. You'll have to use JavaScript - a client-side language that allows you to do what you need, ie manipulate DOM tree - in that case.
Here you've got an example of code that replaces 0...9 into ۰...۹ in given String:
myString.replace(/\d/g, function(matches) {
return String.fromCharCode("\u06F0".charCodeAt(0) + (matches[0] * 1));
})
So basically what you need now is to fetch text from document and replace it by itself but modified with above code:
//HTML
<p id="digits">0123456789</p>
//JavaScript:
var text = document.getElementById("digits").firstChild;
text.nodeValue = text.nodeValue.replace(/\d/g, function(matches) {
return String.fromCharCode("\u06F0".charCodeAt(0) + (matches[0] * 1));
});