diff --git a/ASCIIToSVG.php b/ASCIIToSVG.php
index 05884cc..644b446 100644
--- a/ASCIIToSVG.php
+++ b/ASCIIToSVG.php
@@ -2517,7 +2517,11 @@ public function render() {
$objW = $maxX - $minX;
$objH = $maxY - $minY;
-
+
+ if (isset($this->options['a2s:link'])) {
+ $out .="options['a2s:link']."\">";
+ }
+
$i = 0;
foreach ($object as $o) {
$id = self::$id++;
@@ -2552,6 +2556,11 @@ public function render() {
$out .= "\t" . $text->render() . "\n";
}
}
+
+ if (isset($this->options['a2s:link'])) {
+ $out .="";
+ }
+
$out .= "\n";
/* Bazinga. */
@@ -2677,22 +2686,32 @@ public function render() {
$this->options['fill'] = '#fff';
}
-
- $out .= "\tname}\" ";
+ $out_p = "\tname}\" ";
foreach ($this->options as $opt => $val) {
if (strpos($opt, 'a2s:', 0) === 0) {
- continue;
+ if ($opt=='a2s:link') {
+ $alnk = $val;
+ }
+ continue;
}
- $out .= "$opt=\"$val\" ";
+ $out_p .= "$opt=\"$val\" ";
+ }
+ if (isset($alnk)) {
+ $out_p = "\t".$out_p;
}
- $out .= "d=\"{$path}\" />\n";
+ $out_p .= "d=\"{$path}\" />\n";
if (count($this->text) > 0) {
foreach ($this->text as $text) {
- $out .= "\t" . $text->render() . "\n";
+ $out_p .= "\t" . $text->render() . "\n";
}
}
+ if (isset($alnk)) {
+ $out_p .= '';
+ }
+ $out .= $out_p;
+
$bound = count($this->ticks);
for ($i = 0; $i < $bound; $i++) {
$t = $this->ticks[$i];
@@ -2735,7 +2754,7 @@ private static function svgEntities($str) {
*
* We want to replace these in text without confusing SVG.
*/
- $s = array('&', '<', '>');
+ $s = array('&','<', '>');
$r = array('&', '<', '>');
return str_replace($s, $r, $str);
}
diff --git a/demo.txt b/demo.txt
index 847f318..85a096c 100644
--- a/demo.txt
+++ b/demo.txt
@@ -70,7 +70,7 @@ Install the plugin using the [[doku>plugin:plugin|Plugin Manager]]. It will inst
====>| (svg) World '------. / #------# .-------. |
| .-----# |==+ | | | | |
'----# '---------# #------# '-------'
-[0]: {"fill":"#CE3B83","stroke":"#F50078","stroke-dasharray":"5 5","stroke-width":4,"a2s:type":"cloud","a2s:delref":true}
+[0]: {"a2s:link":"https://github.com/schplurtz/a2s","fill":"#CE3B83","stroke":"#F50078","stroke-dasharray":"5 5","stroke-width":4,"a2s:type":"cloud","a2s:delref":true}
@@ -83,7 +83,7 @@ Install the plugin using the [[doku>plugin:plugin|Plugin Manager]]. It will inst
====>| (svg) World '------. / #------# .-------. |
| .-----# |==+ | | | | |
'----# '---------# #------# '-------'
-[0]: {"fill":"#CE3B83","stroke":"#F50078","stroke-dasharray":"5 5","stroke-width":4,"a2s:type":"cloud","a2s:delref":true}
+[0]: {"a2s:link":"https://github.com/schplurtz/a2s","fill":"#CE3B83","stroke":"#F50078","stroke-dasharray":"5 5","stroke-width":4,"a2s:type":"cloud","a2s:delref":true}
@@ -104,7 +104,7 @@ Please, note that the reference doc is on [[https://github.com/dhobsd/asciitosvg
- Identify the shape : In the **top left** angle of the shape, put some text between square bracket. example ''[0]'', ''[logo]'', ''[some text]''
- **At the bottom** of the drawing, for each identified shape, add a **single** line with the identifier and a JSON hash of property:value. See the section just below for details.
-==== Styling shapes ====
+==== Styling shapes and linking ====
Colors are expressed either
* In RGB with 3 or 6 hexdigits preceded by a sharp sign : ''#88d'', ''#F50078''
@@ -130,11 +130,18 @@ Available styling parametre :
* shape : ''"a2s:type":"shapename"'' where shapename is one of ''cloud'', ''computer'', ''diamond'', ''document'', ''storage'', ''printer''. Examples"a2s:type":"cloud"
"a2s:type":"storage"
+
+ * link : ''"a2s:link":"//linktext//"'' where //linktext// is either an internal wiki link, or a classic //%%protocol://server/resource%%// link. [[doku>interwiki|interwiki links]] cannot yet be used. Since SVG can be included in ODT file, a2s does not obey the [[doku>config:canonical|canonical]] setting and always generate absolute links.\\ Examples:
+"a2s:link":"[[.:]]"
+"a2s:link":"[[:start]]"
+"a2s:link":"[[:start|The start page]]"
+"a2s:link":"https://github.com/schplurtz/a2s"
+"a2s:link":"ftp://ftp.debian.org/debian/README"
* identifier removal. By default the id is left in the image. This is useful when you have enough room to use a meaningful word as id. However, it is possible to remove it using this code "a2s:delref":true
here is a full example :
-[0]: {"fill":"#d48","stroke":"#F50078","stroke-dasharray":"5 5","stroke-width":4,"a2s:type":"cloud","a2s:delref":true}
+[0]: {"fill":"#d48","stroke":"#F50078","stroke-dasharray":"5 5","stroke-width":4,"a2s:type":"cloud","a2s:delref":true,"a2s:link":"https://github.com/schplurtz/a2s"}
==== Alignment ====
diff --git a/syntax.php b/syntax.php
index a5a50ff..9cfc7a8 100644
--- a/syntax.php
+++ b/syntax.php
@@ -91,7 +91,7 @@ public function handle($match, $state, $pos, Doku_Handler $handler){
self::$align=$align; // needed to pass $align to ODT LEXER_MATCHED render
return array($state, $align, null); // odt renderer expects array size 3
case DOKU_LEXER_UNMATCHED :
- $o = new dokuwiki\plugin\a2s\ASCIIToSVG(trim($match, "\r\n"));
+ $o = new dokuwiki\plugin\a2s\ASCIIToSVG($this->_prepare($match));
$o->setDimensionScale(9, 16);
$o->parseGrid();
// save alignment for later use by ODT renderer
@@ -177,6 +177,28 @@ protected function _extract_XY_4svg( $svgtxt ) {
// assume a 96 dpi screen
return array_map( function($v) { return ($v/96.0)."in"; }, $sizes );
}
+ /**
+ * Prepare matched text for beeing parsed. Removes unnecessary blank lines
+ * expand wikilinks to http absolute links. (absolute links because of
+ * ODT export)
+ *
+ * @param String $text The matched a2s input string
+ * @return String the prepared string
+ */
+ protected function _prepare( $text ) {
+ return preg_replace_callback(
+ '/"a2s:link":"
+ \\[\\[
+ ([^]|]*) # The page_id
+ (\\|[^]]*)? # |description optional
+ ]]"
+ /x',
+ function( $match ) {
+ return '"a2s:link":"' . wl( cleanID($match[1]), '', true ) . '"';
+ },
+ trim($text, "\r\n")
+ );
+ }
}
// vim:ts=4:sw=4:et: