DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:asciisvg

asciisvg plugin

Compatible with DokuWiki

Lemming, Anteater, Rincewind

plugin Plugin for displaying good looking diagrams on wiki pages

Last updated on
2011-06-25
Provides
Syntax

The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Tagged with diagram, images, media, svg

Description

ASCIIsvg is a layer of JavaScript functions that can be used in any HTML document to produce inline Scalable Vector Graphics viewable with both Internet Explorer+ Adobe SVGviewer and Firefox 1.5 and later. ASCIIsvg has been developed by Prof. Peter Jipsen at the university of Chapman. This plugin integrates ASCIIsvg into DokuWiki.

Installation

  1. Download the source archive (~11k)from asciisvg
  2. Unpack it in your Doku­Wiki plugins directory {dokuwiki}/lib/plugins (make sure, in­clu­ded sub­di­rec­to­ries are un­packed cor­rect­ly); this will create the following following folder:
    1. {dokuwiki}/lib/plugins/asciisvg.

with the following files

  1. ASCIIsvg127.js
  2. d.svg
  3. script.js
  4. syntax.php

Thats it!

Usage/Syntax

 <asvg  width/height> ASCIIsvg notation goes here </asvg>

Example

<asvg 117/117>
initPicture(0,1,0)
a=[0,0]; b=[1,1]
rect(a,b)
stroke='red'
ellipse([.5,.5],.5,.25)
stroke='blue'
ellipse([.5,.5],.25,.5)
</asvg>

plugin codes

syntax.php

<?php
/**
 * Plugin Color: Sets new colors for text and background.
 *
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 * @author  Mohammad Rahmani <m [dot] rahmani [at] aut [dot] ac [dot] ir>
 
 *  Rev. 0.20: Some bugs fixed, support for DokuWiki 2011-05-25a
 *  Date: Thursday, June 23, 2011
 
 */
 
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
 
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_asciisvg extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Mohammad Rahmani',
            'email'  => 'm.rahmani@aut.ac.ir',
            'date'   => '2008-08-03',
            'name'   => 'ASCIIsvg Plugin',
            'desc'   => 'Translating ASCII math notation to SVG graphics',
            'url'    => 'http://wiki.splitbrain.org/plugin:asciisvg',
                     );
    }
 
    function getType(){ return 'formatting'; }
    function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
    function getSort(){ return 158; }
    function connectTo($mode) { $this->Lexer->addEntryPattern('<asvg.*?>(?=.*?</asvg>)',$mode,'plugin_asciisvg'); }
    function postConnect() { $this->Lexer->addExitPattern('</asvg>','plugin_asciisvg'); }
 
/**
     * Handle the match
     */
    public function handle($match, $state, $pos, &$handler){
        switch ($state) {
        case DOKU_LEXER_ENTER :
            list($width, $height) = preg_split("/\//u", substr($match, 6, -1), 2);
//            if ($width="") $width="200";
//            if ($height="") $height="200";
            break;
        case DOKU_LEXER_UNMATCHED :
            return array($state, $match);
            break;
        case DOKU_LEXER_EXIT :
            return array($state, '');
            break;
        }
        return array($state, array($width, $height));
    }
 
    /**
     * Create output
     */
     public function render($mode, &$renderer, $data) {
        if($mode != 'xhtml') return false;
        list($state, $match) = $data;
        switch ($state) {
        case DOKU_LEXER_ENTER :
            list($width, $height) = $match;
            $renderer->doc .= "<embed  src='d.svg' width='$width' height='$height'  script='";
            break;
        case DOKU_LEXER_MATCHED :
            break;
         case DOKU_LEXER_UNMATCHED :
            $renderer->doc .= $renderer->_xmlEntities($match);
            break;
         case DOKU_LEXER_EXIT :
            $renderer->doc .="'>";
            break;
        case DOKU_LEXER_SPECIAL :
            break;
        }
    }
}
?>

script.js

/*
 This script installs the ASCIIsvg JavaScript
 to be used through "asciisvg" plugin in Dokuwiki
 @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 @author  Mohammad Rahmani <m [dot] rahmani [at] aut [dot] ac [dot] ir>
 
  Date: Sunday, 03 Aug. 2008  14:46:45
  Rev. 0: exprimental
 
 Rev. 0.2: Some bugs fixed
 Date: Thursday, June 23, 2011
   - all function in the previos script.js was deleted!
   - support for the latest version of Dokuwiki (2011-5-25a)
*/
 
// full address to ASCIIsvg main script
document.write('<script type="text/javascript" src="' + DOKU_BASE + '/lib/plugins/asciisvg/ASCIIsvg127.js' + '"></script>');

Samples

Here are some examples tested under DokuWiki. Simply copy paste them into a wiki page with installed asciisvg plugin.

Example 1
    <asvg 117/117>
 
    initPicture(-2.2,2.2,-2.2)
    line([-2,-2],[2,2])
    marker = 'arrowdot'
    line([-2,2],[2,-2])
 
    </asvg>
Example 2
    <asvg 250/250>
    initPicture(-1,6,-1,6)
     axes()
     a = [0,0]
     b = [5,5]
     marker = 'dot'
     line(a,b)
     text(a,'a',belowright)
     text(b,'g',above)
     text(b,'b',right)
     text(b,'b',left)
     text(b,'b',below)
     text(b,'b',aboveleft)
     text(b,'b',aboveright)
     text(b,'b',belowleft)
     text(b,'b',belowright)
     stroke = 'red'
     path([a,[0,5],b,[5,0]])
     stroke = 'green'
     marker = 'none'
     curve([a,[.25,0],[.5,.5],[1,1],[1.5,1.5]])
     stroke = 'blue'
     circle([5,0],1)
     ellipse([0,5],1,2)
     stroke = 'purple'
     rect([0,0],[2,2],null,.5,1)
     marker = 'arrowdot'
     line(a,[5,0])
    </asvg>

ToDo

  • Interested developers are invited to correct/modify the code to obey the DokuWiki rules. FIXME
  • This plugin supports ASCIIsvg 1.2.7. The newer version is included in ASCIIMatML and does not supported by this plugin :!:.

Issues

  1. There is a conflict with jsmath. When asciisvg is installed jsMath does not work anymore.

Discussion

plugin/asciisvg.txt · Last modified: 2022-07-29 23:27 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