在格式化时间时,与markdown格式化冲突,抛异常
发布于 10小时前 作者 qianjiahao 51 次浏览 来自 问答

自己设定的时间格式为:

var time = { date: date, year : date.getFullYear(), month : date.getFullYear() + "-" + (date.getMonth() + 1), day : date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate(), minute : date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + “:” + (date.getMinutes() < 10 ? ‘0’ + date.getMinutes() : date.getMinutes()) }

但是markdown抛出异常:

/Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/connection/base.js:246 throw message;
^ TypeError: Cannot read property ‘slice’ of null at convert_tree_to_html (/Users/qianjiahao/blog/node_modules/markdown/lib/markdown.js:1556:20) at Object.toHTMLTree (/Users/qianjiahao/blog/node_modules/markdown/lib/markdown.js:112:14) at Object.toHTML (/Users/qianjiahao/blog/node_modules/markdown/lib/markdown.js:82:22) at /Users/qianjiahao/blog/models/post.js:101:25 at /Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/collection/query.js:164:5 at Cursor.nextObject (/Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/cursor.js:753:5) at commandHandler (/Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/cursor.js:727:14) at /Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/db.js:1912:9 at Server.Base._callHandler (/Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/connection/base.js:448:41) at /Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/connection/server.js:481:18 Process finished with exit code 1

尝试通过“\”来转义,但是转义失败。

var time = { date: date, year : date.getFullYear(), month : date.getFullYear() + "-" + (date.getMonth() + 1),

    day : date.getFullYear() + "\-" + (date.getMonth() + 1) + "\-" + date.getDate(),
    minute : date.getFullYear() + "\-" + (date.getMonth() + 1) + "\-" + date.getDate() + "\-" +
    date.getHours() + "\-" + (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes())
}

各位大神有没有什么办法。。。

回到顶部