免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4660 | 回复: 13
打印 上一主题 下一主题

求PHP格式化引擎。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-09-25 18:15 |只看该作者 |倒序浏览
100可用积分
求PHP格式化引擎。

如 Trac 风格的。


  1. {{{

  2. }}}

  3. * one
  4. * two
  5. * three
复制代码


或有没有其它更好的。

我想用latex or docbook

论坛徽章:
0
2 [报告]
发表于 2007-09-25 19:21 |只看该作者
要用 LaTex 那你的机器需要安装 LaTex 或者 MimeTex。PHP 好像只有 Wrapper。

论坛徽章:
0
3 [报告]
发表于 2007-09-25 20:48 |只看该作者
LZ是说代码格式化?

论坛徽章:
0
4 [报告]
发表于 2007-09-26 09:20 |只看该作者
原帖由 powerpolly 于 2007-9-25 20:48 发表
LZ是说代码格式化?


是文档。不是代码。

论坛徽章:
0
5 [报告]
发表于 2007-09-26 10:03 |只看该作者
trac的文档编辑器确实不错,真正用起来却要比word舒服很多。LZ可以模仿trac的语法自己写一套分析。。。

期待大作。

论坛徽章:
0
6 [报告]
发表于 2007-09-26 10:12 |只看该作者
呵呵,,code文档还不会做。

论坛徽章:
0
7 [报告]
发表于 2007-09-26 10:24 |只看该作者
原帖由 a_coder 于 2007-9-26 10:03 发表
trac的文档编辑器确实不错,真正用起来却要比word舒服很多。LZ可以模仿trac的语法自己写一套分析。。。

期待大作。


自己写工作量太大,应该有现成的。

论坛徽章:
0
8 [报告]
发表于 2007-09-26 18:05 |只看该作者
工作量好大,不写了。 还是用XML + XSL


  1. <?
  2. class NeoFormatting{
  3.         public $input;
  4.         public $output;
  5.         public function __construct(){

  6.         }
  7.         public function generation(){

  8.         }
  9.         public function trac(){
  10.                 $string = $this->input;
  11.                 $patterns[0] = '/\={1} (\w+) \={1}/';
  12.                 $patterns[1] = '/== (\w+) ==/';
  13.                 $patterns[2] = '/=== (\w+) ===/';

  14.                 $replacements[0] = '<h1>${1}</h1>';
  15.                 $replacements[1] = '<h2>${1}</h2>';
  16.                 $replacements[2] = '<h3>${1}</h3>';

  17.                 //$string = preg_replace($patterns, $replacements, $string);
  18.                 $string = preg_replace('/={7} (\w+) ={7}/', '<h7>${1}</h7>', $string);
  19.                 $string = preg_replace('/={6} (\w+) ={6}/', '<h6>${1}</h6>', $string);
  20.                 $string = preg_replace('/={5} (\w+) ={5}/', '<h5>${1}</h5>', $string);
  21.                 $string = preg_replace('/={4} (\w+) ={4}/', '<h4>${1}</h4>', $string);
  22.                 $string = preg_replace('/=== (\w+) ===/', '<h3>${1}</h3>', $string);
  23.                 $string = preg_replace('/== (\w+) ==/', '<h2>${1}</h2>', $string);
  24.                 $string = preg_replace('/= (\w+) =/', '<h1>${1}</h1>', $string);

  25.                 //$string = preg_replace('/\{\{\{(\w+)\}\}\}/', '<pre>${1}</pre>', $string);
  26.                 $string = str_replace('{{{', '<pre>', $string);
  27.                 $string = str_replace('}}}', '</pre>', $string);
  28. //                $string = str_replace('<', '&lt;', $string);
  29. //                $string = str_replace('>', '&gt;', $string);

  30.                 $string = preg_replace('/(\s(\*)\s(\w+))+/', '<ul>${1}</ul>', $string);
  31.                 $string = preg_replace('/\s(\*)\s(\w+)/', '<li>${2}</li>', $string);

  32.                 $this->output = $string;

  33.         }
  34. }

  35. $nf = new NeoFormatting();

  36. $nf->input = "
  37. = Heading =\r\n
  38. == Heading ==\r\n
  39. === Heading ===\r\n
  40. ==== Heading ====\r\n
  41. ===== Heading =====\r\n
  42. ====== Heading ======\r\n
  43. ======= Heading =======\r\n
  44. \r\n

  45. {{{\r\n
  46. <?
  47.         class hello{
  48.                 public hello(){

  49.                 }
  50.         }
  51. ?>\r\n
  52. }}}

  53. \r\n
  54. * line 1\r\n
  55. * line 1\r\n
  56. * line 1\r\n
  57. * line 1\r\n
  58. \r\n

  59. ";

  60. $nf->trac();

  61. echo $nf->output;

  62. ?>
复制代码

论坛徽章:
0
9 [报告]
发表于 2007-09-26 18:59 |只看该作者
zendstudio 自带的 文档生成。你可以试下。

论坛徽章:
0
10 [报告]
发表于 2007-09-27 11:04 |只看该作者
看看这个吧,如果你有安装 cgi 的权限。

http://www.forkosh.com/mimetex.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP