24 'hr' => '<hr />' |
24 'hr' => '<hr />' |
25 ); |
25 ); |
26 |
26 |
27 public function heading($text, $pieces) |
27 public function heading($text, $pieces) |
28 { |
28 { |
|
29 static $heading_names = array(); |
29 foreach ( $pieces as $i => $piece ) |
30 foreach ( $pieces as $i => $piece ) |
30 { |
31 { |
31 $tocid = sanitize_page_id(trim($piece['text'])); |
32 $tocid = sanitize_page_id(trim($piece['text'])); |
32 // (bad) workaround for links in headings |
33 // (bad) workaround for links in headings |
33 $tocid = str_replace(array('[', ']'), '', $tocid); |
34 $tocid = str_replace(array('[', ']'), '', $tocid); |
|
35 // conflict avoidance |
|
36 if ( isset($heading_names[$tocid]) ) |
|
37 { |
|
38 $id = 2; |
|
39 while ( isset($heading_names["{$tocid}{$id}"]) ) |
|
40 $id++; |
|
41 |
|
42 $tocid .= $id; |
|
43 } |
|
44 $heading_names[$tocid] = true; |
|
45 |
34 $tag = '<h' . $piece['level'] . ' id="head:' . $tocid . '">'; |
46 $tag = '<h' . $piece['level'] . ' id="head:' . $tocid . '">'; |
35 $tag .= trim($piece['text']); |
47 $tag .= trim($piece['text']); |
36 $tag .= '</h' . $piece['level'] . '>'; |
48 $tag .= '</h' . $piece['level'] . '>'; |
37 |
49 |
38 $text = str_replace(Carpenter::generate_token($i), $tag, $text); |
50 $text = str_replace(Carpenter::generate_token($i), $tag, $text); |