{' . $gloss . '}'; } function gloss_get_html($text, $glosses) { $glosses = explode('}{', ltrim(rtrim($glosses, '}'), '{')); $text = '' . $text . ''; $glosses_html = implode('', array_map(array($this, 'gloss_map_function'), $glosses)); return '' . ($this->above ? $glosses_html . $text : $text . $glosses_html) . ''; } function flush_parts() { $r = ''; if (count($this->parts) > 0 && $this->parts[0]{0} != '<') { $r = array_shift($this->parts); } if (count($this->parts) > 1) $r .= '' . implode('', $this->parts) . ''; elseif (count($this->parts) > 0) $r .= implode('', $this->parts); else $r .= ''; $this->parts = array(); return $r; } function callback($m) { if ($m[2] && $m[3]) { $white = $m[1]; $code = $this->gloss_get_html($m[2], $m[3]); } else if($m[6] && $m[7]) { $white = $m[5]; $code = $this->gloss_get_html($m[6], $m[7]); } else { $white = $m[9]; $code = str_replace(' ', ' ', $m[10]); } if ($white) $res = $this->flush_parts(); else $res = ''; if (!$this->strip_spaces && $white) $this->parts[] = str_replace(' ', ' ', $white); $this->parts[] = $code; return $res; } public function convert_line($text) { $this->parts = array(); $gloss = preg_replace_callback( "#( *)``(\S.+?)``((\{[^}]+\})+)|( *)([^\{\s]+)((\{[^}]+\})+)|( *)(\S+)#", array($this, 'callback'), $text); $gloss .= $this->flush_parts(); return $gloss; } public function convert($text, $dir, $strip_spaces, $above, $classes = '') { $this->above = $above; $this->pos = $above ? 'above' : 'below'; $this->strip_spaces = $strip_spaces; $lines = array_map(array($this, 'convert_line'), explode("\n", $text)); return ($dir == 'rtl' ? '

' . implode('
', $lines) . '

'; } public static function conv($t, $args) { $gmp = new self(); $dir = 'ltr'; $strip_spaces = false; $above = false; $classes = array(); foreach ($args as $arg) { if ($arg == 'ltr' || $arg == 'rtl') { $dir = $arg; } elseif ($arg == 'nospaces') { $strip_spaces = true; } elseif ($arg == 'above') { $above = true; } else { $class = str_replace('=', '-', trim(preg_replace('[^=a-zA-Z0-9]', '', $arg))); if ($class) { $classes[] = 'gloss-' . $class; } } } return $gmp->convert($t, $dir, $strip_spaces, $above, implode(' ', $classes)); } } Markup('gloss', '>markup', "/\\(:gloss(\\s+.*?)?\\s*:\\)[^\\S\n]*\n(.*?)\\(:glossend:\\)/sei", "GlossMarkup(PSS('$1'), PSS('$2'))"); function GlossMarkup($arguments, $content) { return GlossMarkupParser::conv($content, explode(' ', $arguments)); }