## Tuesday, January 02, 2007

### Chemistry in HTML: JavaScript from the server

Recently I blogged about a Greasemonkey script to take advantage of semantic markup of chemistry in blogs (and HTML in general), and later made some plans how this can be extended. One of the ideas was to make this userscript available from the server, instead of having people need to install Greasemonkey and the script separately. So, here it is.

sechemtic.js

Consider this (X)HTML:
<html xmlns="http://www.w3.org/1999/xhtml"      xmlns:chem="http://www.blueobelisk.org/chemistryblogs/"><head> <title>m1</title> <script type="text/javascript" src="sechemtic.js" /></head><body onload="addGoogleAndPubChemLinks(1,1)">  <h1>The Output</h1>  <p>This article is about <span class="chem:compound">m1</span>   (SMILES:<span class="chem:smiles">CCCOC</span>).</p></body></html>

I think the above example shows the simple setup of the Sechemtic Web script (please forgive me my habit to use bad linguistic mashups ;). Just load the script in the HTML <head>, and add in the onload="addGoogleAndPubChemLinks(1,1)" attribute to the <body> element. With blogs these bits would be part of the template, and, therefore, need to be installed once. From then on, just use the semantic markup as explained earlier. Both the microformat and the RDFa method are supported. In case of the latter, I recommend to define the chem namespace in the template of webpages too, instead of in the <span> elements.

<html><head> <title>m1</title> <script type="text/javascript" src="sechemtic.js" /></head><body onload="addGoogleAndPubChemLinks(1,1)">  <h1>The Output</h1>  <p>This article is about <span class="compound">m1</span>   (SMILES:<span class="smiles">CCCOC</span>).</p></body></html>