使用制表符和换行符标记预先格式化的文本块

时间:2013-03-06 01:50:38

标签: pug

我想将这段代码放入Jade(缩进是一个标签):

function isSafe(number) {
    return /^\d+(\.\d+)?(e\d+)?$/i.test(number);
}

typeof number === 'string' && isSafe(number) && typeof eval(number) !== 'number'

当我这样做时,空行消失:

pre
    code
        | function isSafe(number) {
        |    return /^\d+(\.\d+)?(e\d+)?$/i.test(number);
        | }

        | typeof number === 'string' && isSafe(number) && typeof eval(number) !== 'number'

当我这样做时,管道显示出来:

pre
    code
        | function isSafe(number) {
        |    return /^\d+(\.\d+)?(e\d+)?$/i.test(number);
        | }
        |
        | typeof number === 'string' && isSafe(number) && typeof eval(number) !== 'number'

当我这样做时,标签会变成一个空格:

pre
    code.
        function isSafe(number) {
            return /^\d+(\.\d+)?(e\d+)?$/i.test(number);
        }

        typeof number === 'string' && isSafe(number) && typeof eval(number) !== 'number'

标记它的正确方法是什么?

1 个答案:

答案 0 :(得分:3)

原来管道后面需要一个空格:

pre
    code
        | function isSafe(number) {
        |    return /^\d+(\.\d+)?(e\d+)?$/i.test(number);
        | }
        |·← here
        | typeof number === 'string' && isSafe(number) && typeof eval(number) !== 'number'