在降价时逃避一些乳胶代码

时间:2018-03-03 06:43:31

标签: escaping markdown latex-environment

我找到了一个简单的WordPress plugin,可以使用乳胶支持降价。

它运作良好,但它不支持某些乳胶代码,如

\begin{align*} 
    a+b=c\\
    a+a=2a
\end{align*} . 

任何人都可以帮助改进插件吗?所以它可以逃脱乳胶代码

\begin{...}  
   ...
\end{...} 

我在这个插件中找到了以下代码来逃避一些乳胶代码:

  function doDisplayMath($text) {
  # Wrap text between \[ and \] in display math tags.

  $text = preg_replace_callback('{
  ^\\\\         # line starts with a single backslash (double escaping)
  \[            # followed by a square bracket
  (.+)          # then the actual LaTeX code
  \\\\          # followed by another backslash
  \]            # and closing bracket
  \s*$          # and maybe some whitespace before the end of the line
  }mx',
  array(&$this, '_doDisplayMath_callback'), $text);

return $text;
}

function _doDisplayMath_callback($matches) {
$texblock = $matches[1];
# $texblock = htmlspecialchars(trim($texblock), ENT_NOQUOTES);
$texblock = trim($texblock);
if (MARKDOWN_MATH_TYPE == "mathjax") {
  $texblock = "<span class=\"MathJax_Preview\">[$texblock]</span><script type=\"math/tex; mode=display\">$texblock</script>";
} else {
      $texblock = "<div class=\"math\">$texblock</div>";
  }
    return "\n\n".$this->hashBlock($texblock)."\n\n";
}

function makeCodeSpan($code) {
#
# Create a code span markup for $code. Called from handleSpanToken.
#
    $code = htmlspecialchars(trim($code), ENT_NOQUOTES);
    return $this->hashPart("<code>$code</code>");
}

所以我添加了一个新的类似功能:

function doBeginEnd($text) {
  # Wrap text between \begin and \end{...} in display math tags.

  $text = preg_replace_callback('{
  ^\\\\         # line starts with a single backslash (double escaping)
  \"begin\"     # followed by  "begin"
  (.+)          # then the actual LaTeX code
  \\\\          # followed by another backslash
  \"end\"       # and "end"
  \{            # and {
  (.+)          # and a string
  \}            # and }
  \s*$          # and maybe some whitespace before the end of the line
  }mx',
  array(&$this, '_doDisplayMath_callback'), $text);

return $text;
}

function _doBeginEnd_callback($matches) {
$texblock = $matches[1];
# $texblock = htmlspecialchars(trim($texblock), ENT_NOQUOTES);
$texblock = trim($texblock);
if (MARKDOWN_MATH_TYPE == "mathjax") {
  $texblock = "<span class=\"MathJax_Preview\">[$texblock]</span><script 
              type=\"math/tex; mode=display\">$texblock</script>";
    } else {
              $texblock = "<div class=\"math\">$texblock</div>";
           }
    return "\n\n".$this->hashBlock($texblock)."\n\n";
}

它无效,有什么帮助吗? THX。

0 个答案:

没有答案