DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:chem

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
plugin:chem [2010-12-06 22:50] – recovered broken links iobatayaplugin:chem [2022-07-06 13:21] – Igor tested saggi
Line 1: Line 1:
-====== Chem plugin ======+====== Chem Plugin ======
  
 ---- plugin ---- ---- plugin ----
Line 6: Line 6:
 email      : i.obataya@gmail.com email      : i.obataya@gmail.com
 type       : syntax type       : syntax
-lastupdate : 2008-09-29 +lastupdate : 2017-10-19 
-compatible : 2006/11/06 or later+compatible : 2009-12-25 or later, "Frusterick Manners", "Greebo",Hogfather,Igor
 depends    :  depends    : 
 conflicts  conflicts 
 similar    :  similar    : 
 tags       : formula chemistry science tags       : formula chemistry science
 +
 +downloadurl: https://github.com/iobataya/dokuwiki-plugin-chem/zipball/master
 +sourcerepo : https://github.com/iobataya/dokuwiki-plugin-chem
 ---- ----
- 
-[[http://symplus.edu-wiki.org/en/chem_plugin|Details and Download]] page 
- 
-^  ZIP file  ^ 
-|{{http://symplus.edu-wiki.org/_media/computer/source/chem.zip|chem.zip}} (1KB)| 
  
 This DokuWiki plugin formats a molecular formula easily.  This DokuWiki plugin formats a molecular formula easily. 
Line 27: Line 25:
 The latest version supports to export Open Document format using [[plugin:odt|ODT]] plugin. The latest version supports to export Open Document format using [[plugin:odt|ODT]] plugin.
  
-=====Examples===== +===== Examples =====
-C<sub>2</sub>H<sub>6</sub> +
-<code><chem>C2H6</chem></code>+
  
-Na<sub>2</sub>HPO<sub>4</sub> 12H<sub>2</sub>+|  C<sub>2</sub>H<sub>6</sub>  | ''%%<chem>C2H6</chem>%%'' 
-<code><chem>Na2HPO4 12H2O</chem></code>+|  Na<sub>2</sub>HPO<sub>4</sub> 12H<sub>2</sub> | ''%%<chem>Na2HPO4 12H2O</chem>%%''  | 
 +|  C<sub>2</sub>H<sub>5</sub>O<sub>2</sub><sup>-</sup>Na<sup>+</sup>  | ''%%<chem>C2H5O2|-Na+</chem>    // | is a splitter.%%'' 
 +|  Cl<sub>2</sub>H<sub>6</sub>N<sub>2</sub>Pt<sup>2+</sup>  | ''%%<chem>Cl2H6N2Pt2+</chem>%%'' 
 +|  Al<sub>2</sub>(SO<sub>4</sub>)<sub>3</sub>  | ''%%<chem>Al2(SO4)3</chem>%%''  |
  
-C<sub>2</sub>H<sub>5</sub>O<sub>2</sub><sup>-</sup>Na<sup>+</sup>  +====== Another Version ======
-<code><chem>C2H5O2|-Na+</chem>    // | is a splitter.</code> +
- +
-Cl<sub>2</sub>H<sub>6</sub>N<sub>2</sub>Pt<sup>2+</sup>  +
-<code><chem>Cl2H6N2Pt2+</chem></code> +
- +
-Al<sub>2</sub>(SO<sub>4</sub>)<sub>3</sub> +
-<code><chem>Al2(SO4)3</chem></code> +
- +
-====== another Version ======+
  
 The original plugin works very fine. The original plugin works very fine.
Line 68: Line 58:
 </code> </code>
 What do you think ? What do you think ?
- --- //[[ikuo_obataya@symplus.co.jp|iobataya]] 2010/04/21 05:45//+ --- //iobataya 2010/04/21 05:45//
  
-__syntax.php__: +My server moved to new place
-<code php> + --- [[user>iobataya]] //2010/12/06 22:50//
-<?php +
-/* +
-description : Plugin Chem: formatting chemical format +
-author      : Ikuo Obataya +
-email       : ikuo_obataya@symplus.co.jp +
-lastupdate  : 2008-09-29 +
-license     : GPL 2 (http://www.gnu.org/licenses/gpl.html) +
-*/ +
-if(!defined('DOKU_INC')) die(); +
-if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +
-require_once(DOKU_PLUGIN.'syntax.php'); +
-class syntax_plugin_chem extends DokuWiki_Syntax_Plugin { +
-  function getInfo(){ +
-    return array( +
-        'author' => 'Ikuo Obataya', +
-        'email'  => 'I.Obataya@gmail.com', +
-        'date'   => '2008-9-29', +
-        'name'   => 'Chemical Formula Plugin', +
-        'desc'   => 'Format chemical formula', +
-        'url'    => 'http://wiki.symplus.co.jp/computer/en/chem_plugin', +
-    ); +
-}+
  
-  function getType(){ return 'formatting'; } 
-  function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }    
-  function getSort(){ return 158; } 
-  function connectTo($mode) { $this->Lexer->addEntryPattern('<chem>(?=.*?</chem>)',$mode,'plugin_chem'); } 
-  function postConnect() { $this->Lexer->addExitPattern('</chem>','plugin_chem'); } 
-  
-  function handle($match, $state, $pos, &$handler){ 
-    switch ($state) { 
-        case DOKU_LEXER_ENTER     :return array($state, ''); 
-        case DOKU_LEXER_UNMATCHED :return array($state, $match); 
-        case DOKU_LEXER_EXIT      :return array($state, ''); 
-    } 
-    return array(); 
-  } 
  
-  function render($mode, &$renderer, $data) { +Source code was moved to GitHub  --- [[user>iobataya|iobataya]] //2013/01/20 15:39//
-    if($mode == 'xhtml' || $mode=='odt'){ +
-      list($state, $match) = $data; +
-      switch ($state) { +
-        case DOKU_LEXER_ENTER:break; +
-        case DOKU_LEXER_UNMATCHED: +
-          if($mode=='xhtml'){ +
-            // xhtml +
-            $renderer->doc .= $this->getChemFormat($match); +
-          } +
-   if($mode == 'odt'){ +
-            // Open document format +
-            $renderer->doc.= $this->getOdtChemFormat($match); +
-          } +
-          break; +
-        case DOKU_LEXER_EXIT:break; +
-      } +
-      return true; +
-    } +
-    return false; +
-  +
-  +
-   function getChemFormat($raw){ +
-    $pattern = array( "/([A-Z][a-z]?|\)|\])([1-9][0-9]*)[\|](([\-\+][0-9]*)|([0-9]*[\-\+]))/", /* sub+ sup: Al2|2+ , H2 , )2 , ]2 */ +
- "/([A-Ze][a-z]?|\)|\])(([\-\+][0-9]*)|([0-9]*[\-\+]))/", /* only supAl2- , H2+ , )2+ , ]2- */ +
- "/([A-Z][a-z]?|\)|\])([1-9][0-9]*)/", /* only sub: Al2 , H2 , )2 , ]2 */ +
- "/([0-9]*)[\|]([0-9]*)([A-Z][a-z]?)/", /* sup + sub: 92|235U */ +
- "/([0-9]*)([A-Z][a-z]?)/", /* only sup: 235U */ +
-  +
- "/Neutron/", +
- "/Elektron/", +
- "/Proton/", +
- +
- "/alpha/", +
- "/beta/", +
- "/gamma/"); +
-    $replace = array( "\${1}<sub style='position: relative; font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>\${2}</sub><sup style='position: relative; left: -0.5em;font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>\${3}</sup>", +
- "\${1}<sup>\${2}</sup>", +
- "\${1}<sub>\${2}</sub>", +
- "<sup style='position: relative; right: -1.0em;font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>\${2}</sup><sub style='position: relative; font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>\${1}</sub>\${3}", +
- "<sup>\${1}</sup>\${2}", +
-  +
- "<sup style='position: relative; right: -0.5em;font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>1</sup><sub style='position: relative; font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>0</sub>n", +
- "<sup style='position: relative; right: -1.0em;font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>0</sup><sub style='position: relative; font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>-1</sub>e", +
- "<sup style='position: relative; right: -1.0em;font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>0</sup><sub style='position: relative; font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>+1</sub>p", +
- +
- "<sub style='position: relative; right: -0.5em;font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>2</sub><sup style='position: relative; font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>4</sup>He", +
- "e<sup>-</sup>", +
- "&gamma;"); +
-    return preg_replace($pattern,$replace,$raw); +
-  } +
- +
- +
-  function getOdtChemFormat($raw){ +
-    $c = $this->getChemFormat($raw); +
-    $pattern = array( "/<sup([^>]*)>([^<]+)<\/sup>/", +
- "/<sub([^>]*)>([^<]+)<\/sub>/"); +
-    $replace = array( "<text:span text:style-name=\"sup\">\${2}</text:span>", +
- "<text:span text:style-name=\"sub\">\${2}</text:span>");  +
-    return preg_replace($pattern,$replace,$c); +
-  } +
- +
- +
- } +
-?> +
-</code>+
  
 +SS 2015-12-13: Doesn't work all that well. A simple formula of calcium carbonate CaCO3 shows as CaCo3 (lower case oxygen)
  
 +This tool is simply great! Love it:) Just a small suggestion, can we have a button in the toolbar in forum posts? I mean a small button in the toolbar with italic/bold. just like what this [[plugin:highlight]]tool has --- [[user>EpsilonC|EpsilonC]] //2017/10/06 10:24//
 +>Now you can find a benzene button in a tool bar ;-)
 +>Clear cache of web browser after update the plugin. Cache of javascripts are sticky.
 +> --- [[user>iobataya|iobataya]] //2017-10-19 00:18//
plugin/chem.txt · Last modified: 2023-10-30 23:38 by Klap-in

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki