在 Drupal 中使用 reStructuredText - 改进版

用于 Drupal6 的版本,加上了 Pygments 对代码做彩色语法显示。还是很简陋而且乱糟糟的,有很多地方要完善。

需要在主题的 style sheet 里设置菜色显示的颜色方案。 Acquia Marina 有个好处是可以把自己修改的设定加在 local.css 里这样升级的时候就安全了。

  • local.css
#content {
    font-size: 133%;
}

#comments h2.comments {
    text-transform: none;
    font-variant: small-caps;
}

h2.title {
    text-transform: none;
    font-variant: small-caps;
}

pre {
    font-family: "Consolas", monospace;
}

.literal {
    text-decoration: none;
    background-color: #fbeddd;
    border-width: 0 0 1px 0;
    border-style: none none dashed none;
}

/* code-block highlight scheme for Pygments output */
.highlight {
    background-color: #ddedfb;
    border-style: solid;
    border-color: #0099cc;
    border-width: 1px 0 1px 0;
    margin: 1em 0;
    padding: 0.5em 1em;
}

/* css genetated from gen_pyg_style.py should be appended here*/

上面是针对自己的喜好改的 local.css 内容,代码彩色语法的 css 可以用下面的脚本生成,加在 local.css 后面。

  • gen_pyg_style.py
#!/usr/bin/python
import sys
from pygments.formatters import HtmlFormatter
style='friendly'
if len(sys.argv) > 1:
    style = sys.argv[1]
print style
f = HtmlFormatter(style=style)
print f.get_style_defs()

另外 settings.php 最好也改一下

  • settings.php
1 <?php
2 $db_url = '<database url...>';
3 $db_prefix = '';
4 $update_free_access = FALSE;
5 $conf = array(
6     'reverse_proxy' => TRUE,
7     'reverse_proxy_addresses' => array('x.y.z.w',),
8     'allow_insecure_uploads' => 1,
9 );

6、7 行是放在反向代理后面而本服务器又没做特别设置时的必要措施。8 行是因为 Drupal 默认会在上传文件时把多段扩展名加个下划线,譬如 .tar.gz 的改成 .tar_.gz 的样子,号称为了安全,但相当丑陋,我不需要这种安全。

附件大小
drest-with-pygments.tar.gz3.35 KB

评论

没在 drupal

  • 没在 drupal 网站找到这模块是因为我是新人,试图创建模块被拒,说让我先发帖混个脸熟 -_- 然后后来我就决定先自己慢慢改进,心情好了再去发帖
  • 6.x 可以用,我现在就用的是 6.x 配合这玩意
  • 用 code-block directive 即可
.. code-block:: python

    if __name__ == '__main__':      # this way the module can be
        if 4 != len(sys.argv):
            print """ %s usage::
            $ python sshuttler.py AIMUSER AIMHOST SSHPUBK
            """ % VER
        else:
            AIMUSER = sys.argv[1]
            AIMHOST = sys.argv[2]
            SSHPUBK = sys.argv[3]
            gensh(AIMUSER,AIMHOST,SSHPUBK,VER)
        print "Mnnnn export that .sh do it!"

出来的结果

if __name__ == '__main__':      # this way the module can be
    if 4 != len(sys.argv):
    print """ %s usage::
    $ python sshuttler.py AIMUSER AIMHOST SSHPUBK
    """ % VER
    else:
    AIMUSER = sys.argv[1]
    AIMHOST = sys.argv[2]
    SSHPUBK = sys.argv[3]
    gensh(AIMUSER,AIMHOST,SSHPUBK,VER)
    print "Mnnnn export that .sh do it!"

非常好! 但是没有在 Drupal

  • 非常好!
  • 但是没有在 Drupal 找到对应的模块
  • 俺用的是 Drupal 6.16 是否可以使用?
  • 怎么部署 reStructured Filter 而且包含 Pygments 的语法高亮支持?!

测试哈:

if __name__ == '__main__':      # this way the module can be
    if 4 != len(sys.argv):
        print """ %s usage::
        $ python sshuttler.py AIMUSER AIMHOST SSHPUBK
        """ % VER
    else:
        AIMUSER = sys.argv[1]
        AIMHOST = sys.argv[2]
        SSHPUBK = sys.argv[3]
        gensh(AIMUSER,AIMHOST,SSHPUBK,VER)
    print "Mnnnn export that .sh do it!"

study your work

study your work

发表新评论

此内容将保密,不会被其他人看见。
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.