From 8ff1c4cb202eaa83bfc03c4c83145c344994f511 Mon Sep 17 00:00:00 2001 From: jepso Date: Sun, 23 Sep 2007 21:38:11 +0000 Subject: [PATCH] Fixed interdocumentation linking feature --- .../new/lib/Text/Wiki/Parse/Doc/Doclink.php | 5 +++- .../lib/Text/Wiki/Render/Latex/Doclink.php | 8 ++++++ .../lib/Text/Wiki/Render/Latex/Heading.php | 18 +++++++++---- vendor/Sensei/Sensei/Doc/Renderer/Xhtml.php | 17 +++++++++--- vendor/Sensei/Sensei/Doc/Section.php | 26 ++++++++++++++++--- 5 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 manual/new/lib/Text/Wiki/Render/Latex/Doclink.php diff --git a/manual/new/lib/Text/Wiki/Parse/Doc/Doclink.php b/manual/new/lib/Text/Wiki/Parse/Doc/Doclink.php index d75c98235..a110b6c4b 100644 --- a/manual/new/lib/Text/Wiki/Parse/Doc/Doclink.php +++ b/manual/new/lib/Text/Wiki/Parse/Doc/Doclink.php @@ -32,8 +32,11 @@ class Text_Wiki_Parse_Doclink extends Text_Wiki_Parse { if (isset($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 { - $options['text'] = $section->getIndex() . ' ' . $section->getName(true); + $options['text'] = $section->getIndex(); } return $this->wiki->addToken($this->rule, $options); diff --git a/manual/new/lib/Text/Wiki/Render/Latex/Doclink.php b/manual/new/lib/Text/Wiki/Render/Latex/Doclink.php new file mode 100644 index 000000000..f6ef7e88f --- /dev/null +++ b/manual/new/lib/Text/Wiki/Render/Latex/Doclink.php @@ -0,0 +1,8 @@ += $level) { + array_pop($label); + } + $label[] = Sensei_Doc_Section::convertNameToPath($text); + + switch ($level) { case '1': return '\chapter{'; case '2': @@ -22,12 +29,13 @@ class Text_Wiki_Render_Latex_Heading extends Text_Wiki_Render { return '\paragraph{'; case '6': return '\subparagraph{'; - } + } } + if ($type == 'end') { - return "}\n"; + return "}\n\label{" . implode(':', $label) . "}\n"; } } } -?> \ No newline at end of file +?> diff --git a/vendor/Sensei/Sensei/Doc/Renderer/Xhtml.php b/vendor/Sensei/Sensei/Doc/Renderer/Xhtml.php index 8b8a763c0..b767f7564 100644 --- a/vendor/Sensei/Sensei/Doc/Renderer/Xhtml.php +++ b/vendor/Sensei/Sensei/Doc/Renderer/Xhtml.php @@ -187,12 +187,17 @@ class Sensei_Doc_Renderer_Xhtml extends Sensei_Doc_Renderer 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']; if ($this->_options['section'] instanceof Sensei_Doc_Section) { - $path = $section->getPath(); $level = $this->_options['section']->getLevel(); $url .= implode(':', array_slice(explode(':', $path), 0, $level)); } @@ -205,9 +210,13 @@ class Sensei_Doc_Renderer_Xhtml extends Sensei_Doc_Renderer 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) { $level = $this->_options['section']->getLevel(); diff --git a/vendor/Sensei/Sensei/Doc/Section.php b/vendor/Sensei/Sensei/Doc/Section.php index e486d506a..010f9ee42 100644 --- a/vendor/Sensei/Sensei/Doc/Section.php +++ b/vendor/Sensei/Sensei/Doc/Section.php @@ -114,9 +114,9 @@ class Sensei_Doc_Section implements Countable public function getIndex($separator = '.') { if ($this->_parent->_name !== null) { - return $this->_parent->getIndex($separator) . ($this->_index + 1) . $separator; + return $this->_parent->getIndex($separator) . $separator . ($this->_index + 1); } else { - return ($this->_index + 1) . $separator; + return ($this->_index + 1); } } @@ -136,7 +136,7 @@ class Sensei_Doc_Section implements Countable $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 } } } -} \ 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)); + } +}