Merge branch 'MDL-28616-master' of https://github.com/mackensen/moodle

This commit is contained in:
Dan Poltawski 2012-09-25 14:26:41 +08:00
commit 03a1ef0cbc
2 changed files with 11 additions and 9 deletions

View File

@ -19,9 +19,8 @@ class html_parser extends nwiki_parser {
parent::__construct();
$this->tagrules = array('link' => $this->tagrules['link'], 'url' => $this->tagrules['url']);
//headers are considered tags here...
$h1 = array("<\s*h1\s*>", "<\/h1>");
$this->tagrules['header1'] = array('expression' => "/{$h1[0]}(.+?){$h1[1]}/is"
// Headers are considered tags here.
$this->tagrules['header'] = array('expression' => "/<\s*h([1-$this->maxheaderdepth])\s*>(.+?)<\/h[1-$this->maxheaderdepth]>/is"
);
}
@ -32,10 +31,12 @@ class html_parser extends nwiki_parser {
}
/**
* Header 1 tag rule
* Header tag rule
* @param array $match Header regex match
* @return string
*/
protected function header1_tag_rule($match) {
return $this->generate_header($match[1], 1);
protected function header_tag_rule($match) {
return $this->generate_header($match[2], $match[1]);
}
/**
@ -62,11 +63,11 @@ class html_parser extends nwiki_parser {
protected function get_repeated_sections(&$text, $repeated = array()) {
$this->repeated_sections = $repeated;
return preg_replace_callback($this->tagrules['header1'], array($this, 'get_repeated_sections_callback'), $text);
return preg_replace_callback($this->tagrules['header'], array($this, 'get_repeated_sections_callback'), $text);
}
protected function get_repeated_sections_callback($match) {
$text = trim($match[1]);
$text = trim($match[2]);
if (in_array($text, $this->repeated_sections)) {
$this->returnvalues['repeated_sections'][] = $text;

View File

@ -24,6 +24,7 @@ abstract class wiki_markup_parser extends generic_parser {
//header & ToC
protected $toc = array();
protected $maxheaderdepth = 3;
/**
* function wiki_parser_link_callback($link = "")
@ -183,7 +184,7 @@ abstract class wiki_markup_parser extends generic_parser {
$text .= parser_utils::h('a', '['.get_string('editsection', 'wiki').']', array('href' => "edit.php?pageid={$this->wiki_page_id}&section=" . urlencode($text), 'class' => 'wiki_edit_section'));
}
if ($level < 4) {
if ($level <= $this->maxheaderdepth) {
$this->toc[] = array($level, $text);
$num = count($this->toc);
$text = parser_utils::h('a', "", array('name' => "toc-$num")) . $text;