开发者

Wiki syntax parser in Java

开发者 https://www.devze.com 2023-01-23 14:31 出处:网络
I would like to make a wiki syntax parser in Java. I have one in PHP that goes a little something like this:

I would like to make a wiki syntax parser in Java. I have one in PHP that goes a little something like this:

private static function runAllConversions($pString) {
    $tConverted = $pString;
    $tConverted = stripTags($tConverted); 

    // Bold and italic text.
    $tConverted = preg_replace('/\'\'\'\'\'([^\n\']+)\'\'\'\'\'/',
        '<strong><i>${1}</i></strong>', $tConverted);

In replacement I was thinking of replaceAll instead of the preg_replace in PHP. I guess it would be something like:

// Bold text in开发者_StackOverflow中文版 Java.
converted = converted.replaceAll('/\'\'\'([^\n\']+)\'\'\'/',
    '<strong>${1}</strong>', converted);

Any one got any good suggestions for that? Thanks!


converted = converted.replaceAll("'{5}([^\n']+)'{5}", "<strong><i>$1</i></strong>");
  • I used '{5} instead of ''''' but they are the same.
  • The two delimiters / in PHP are specific to PHP. They should not appear in Java's regex.

BTW, you may use an existing MediaWiki parser instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号