修改PHP markdown编辑器

时间:2011-04-29 16:05:18

标签: php markdown

我想更改此PHP markdown port创建图片的方式:

function doImages($text) {
#
# Turn Markdown image shortcuts into <img> tags.
#
    #
    # First, handle reference-style labeled images: ![alt text][id]
    #
    $text = preg_replace_callback('{
        (               # wrap whole match in $1
          !\[
            ('.$this->nested_brackets_re.')     # alt text = $2
          \]

          [ ]?              # one optional space
          (?:\n[ ]*)?       # one optional newline followed by spaces

          \[
            (.*?)       # id = $3
          \]

        )
        }xs', 
        array(&$this, '_doImages_reference_callback'), $text);

    #
    # Next, handle inline images:  ![alt text](url "optional title")
    # Don't forget: encode * and _
    #
    $text = preg_replace_callback('{
        (               # wrap whole match in $1
          !\[
            ('.$this->nested_brackets_re.')     # alt text = $2
          \]
          \s?           # One optional whitespace character
          \(            # literal paren
            [ \n]*
            (?:
                <(\S*)> # src url = $3
            |
                ('.$this->nested_url_parenthesis_re.')  # src url = $4
            )
            [ \n]*
            (           # $5
              ([\'"])   # quote char = $6
              (.*?)     # title = $7
              \6        # matching quote
              [ \n]*
            )?          # title is optional
          \)
        )
        }xs',
        array(&$this, '_doImages_inline_callback'), $text);

    return $text;
}

我知道它通常是![alt](image),但我相信[alt]和(图像)是不必要的并发症*。简单的样子!http:// imageURI,然后是一个可选的alt。

所以!http://image [optional alt],甚至是![optional ALT]http://ImageURI

我在kiki中尝试了以下正则表达式,但无济于事:

(   !(?:\n[  ]*)? \[(.*?)\]    )

修改

有人指出,某些事情应该指示链接的结束位置:

!LINK![ALT]

这个'!(。*?)!'发现!LINK!,您如何找到可选的alt?

(我姐姐没有看到alt的意思,'好吧如果我不想包括alt?......'

0 个答案:

没有答案