Commit 8ff1c4cb authored by jepso's avatar jepso

Fixed interdocumentation linking feature

parent d8525ca0
...@@ -32,8 +32,11 @@ class Text_Wiki_Parse_Doclink extends Text_Wiki_Parse { ...@@ -32,8 +32,11 @@ class Text_Wiki_Parse_Doclink extends Text_Wiki_Parse {
if (isset($matches[2])) { if (isset($matches[2])) {
$options['text'] = $matches[2]; $options['text'] = $matches[2];
$options['text'] = str_replace(':index', $section->getIndex(), $options['text']);
$options['text'] = str_replace(':name', $section->getName(), $options['text']);
$options['text'] = str_replace(':fullname', $section->getName(true), $options['text']);
} else { } else {
$options['text'] = $section->getIndex() . ' ' . $section->getName(true); $options['text'] = $section->getIndex();
} }
return $this->wiki->addToken($this->rule, $options); return $this->wiki->addToken($this->rule, $options);
......
<?php
class Text_Wiki_Render_Latex_Doclink extends Text_Wiki_Render {
function token($options)
{
return '\ref{' . $options['path'] . '}';
}
}
...@@ -4,12 +4,19 @@ class Text_Wiki_Render_Latex_Heading extends Text_Wiki_Render { ...@@ -4,12 +4,19 @@ class Text_Wiki_Render_Latex_Heading extends Text_Wiki_Render {
function token($options) function token($options)
{ {
static $label = array();
// get nice variable names (type, level) // get nice variable names (type, level)
extract($options); extract($options);
if ($type == 'start') { if ($type == 'start') {
switch ($level)
{ while (count($label) >= $level) {
array_pop($label);
}
$label[] = Sensei_Doc_Section::convertNameToPath($text);
switch ($level) {
case '1': case '1':
return '\chapter{'; return '\chapter{';
case '2': case '2':
...@@ -22,12 +29,13 @@ class Text_Wiki_Render_Latex_Heading extends Text_Wiki_Render { ...@@ -22,12 +29,13 @@ class Text_Wiki_Render_Latex_Heading extends Text_Wiki_Render {
return '\paragraph{'; return '\paragraph{';
case '6': case '6':
return '\subparagraph{'; return '\subparagraph{';
} }
} }
if ($type == 'end') { if ($type == 'end') {
return "}\n"; return "}\n\label{" . implode(':', $label) . "}\n";
} }
} }
} }
?> ?>
\ No newline at end of file
...@@ -187,12 +187,17 @@ class Sensei_Doc_Renderer_Xhtml extends Sensei_Doc_Renderer ...@@ -187,12 +187,17 @@ class Sensei_Doc_Renderer_Xhtml extends Sensei_Doc_Renderer
return $output; return $output;
} }
public function makeUrl(Sensei_Doc_Section $section) public function makeUrl($section)
{ {
if ($section instanceof Sensei_Doc_Section) {
$path = $section->getPath();
} else {
$path = $section;
}
$url = $this->_options['url_prefix']; $url = $this->_options['url_prefix'];
if ($this->_options['section'] instanceof Sensei_Doc_Section) { if ($this->_options['section'] instanceof Sensei_Doc_Section) {
$path = $section->getPath();
$level = $this->_options['section']->getLevel(); $level = $this->_options['section']->getLevel();
$url .= implode(':', array_slice(explode(':', $path), 0, $level)); $url .= implode(':', array_slice(explode(':', $path), 0, $level));
} }
...@@ -205,9 +210,13 @@ class Sensei_Doc_Renderer_Xhtml extends Sensei_Doc_Renderer ...@@ -205,9 +210,13 @@ class Sensei_Doc_Renderer_Xhtml extends Sensei_Doc_Renderer
return $url; return $url;
} }
public function makeAnchor(Sensei_Doc_Section $section) public function makeAnchor($section)
{ {
$path = $section->getPath(); if ($section instanceof Sensei_Doc_Section) {
$path = $section->getPath();
} else {
$path = $section;
}
if ($this->_options['section'] instanceof Sensei_Doc_Section) { if ($this->_options['section'] instanceof Sensei_Doc_Section) {
$level = $this->_options['section']->getLevel(); $level = $this->_options['section']->getLevel();
......
...@@ -114,9 +114,9 @@ class Sensei_Doc_Section implements Countable ...@@ -114,9 +114,9 @@ class Sensei_Doc_Section implements Countable
public function getIndex($separator = '.') public function getIndex($separator = '.')
{ {
if ($this->_parent->_name !== null) { if ($this->_parent->_name !== null) {
return $this->_parent->getIndex($separator) . ($this->_index + 1) . $separator; return $this->_parent->getIndex($separator) . $separator . ($this->_index + 1);
} else { } else {
return ($this->_index + 1) . $separator; return ($this->_index + 1);
} }
} }
...@@ -136,7 +136,7 @@ class Sensei_Doc_Section implements Countable ...@@ -136,7 +136,7 @@ class Sensei_Doc_Section implements Countable
$path = preg_replace($patterns, $replacements, strtolower($this->_name)); $path = preg_replace($patterns, $replacements, strtolower($this->_name));
return $path; return self::convertNameToPath($this->_name);
} }
} }
...@@ -385,4 +385,22 @@ class Sensei_Doc_Section implements Countable ...@@ -385,4 +385,22 @@ class Sensei_Doc_Section implements Countable
} }
} }
} }
}
\ No newline at end of file /**
* Converts section name to section path.
*
* Section path is generated from section name by making section name
* lowercase, replacing all whitespace with a dash and removing all
* characters that are not a letter, a number or a dash.
*
* @param $name string section name
* @return section path
*/
public static function convertNameToPath($name)
{
$patterns = array('/\s/', '/[^a-z0-9-]/');
$replacements = array('-', '');
return preg_replace($patterns, $replacements, strtolower($name));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment