Hexo: 有些代码不能被高亮是什么问题。。

Created on 10 Jan 2016  ·  9Comments  ·  Source: hexojs/hexo

好像是某些特定的代码无法被高亮,我这里上传一个无法高亮的代码,请求测试。
我自己测试是第51行的锅,去掉后能高亮
ll ans = (sum(bit0, b) + b*sum(bit1, b)) - (sum(bit0, a-1) + (a-1)*sum(bit1, a-1));

/*************************************************************************
    > File Name: 3468_3.cpp
      > Author: Netcan
      > Blog: http://www.netcan666.com
      > Mail: [email protected]
      > Created Time: 2016-01-24 日 11:12:19 CST
 ************************************************************************/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 100000+5;
typedef long long ll;
int A[MAXN];
ll bit0[MAXN], bit1[MAXN];
int N, Q;

void add(ll *bit, int i, int x) {
    while(i<=N) {
        bit[i] += x;
        i += i&-i;
    }
}

ll sum(ll *bit, int i) {
    ll res = 0;
    while(i) {
        res += bit[i];
        i -= i&-i;
    }
    return res;
}

void solve() {
    for (int i = 1; i <= N; ++i) add(bit0, i, A[i]);
    char op;
    int a, b, c;
    for (int i = 0; i < Q; ++i) {
        getchar();
        scanf("%c%d%d", &op, &a, &b);
        if(op == 'C') { // [a,b]区间+c
            scanf("%d", &c);
            add(bit0, a, -c*(a-1));
            add(bit1, a, c); // c*a-c*(a-1) = +c
            add(bit0, b+1, c*b);
            add(bit1, b+1, -c);
        }
        else {
            ll ans = (sum(bit0, b) + b*sum(bit1, b)) - (sum(bit0, a-1) + (a-1)*sum(bit1, a-1));
            printf("%lld\n", ans);
        }
    }

}

int main() {
#ifdef Oj
    freopen("3468.in", "r", stdin);
    // freopen("3468_3.out", "w",stdout);
#endif
    scanf("%d%d", &N, &Q);
    for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
    solve();
    return 0;
}
bug highlight

Most helpful comment

可以考虑换个渲染引擎供用户选择么?。。比如弄成插件形式

All 9 comments

hexo支持的代码高亮不能解析用 ``` 的单行代码高亮么。

比如 print 'hello world!' inline的代码高亮。

github是支持的 比如这句 print 'hello world!'

单行不支持,这个取决于Hexo使用的渲染插件,目前官方默认的是marked引擎。

@netcan 收到,近期将会进行测试= =

所以是單行用 ``` 的問題嗎? 是的話就跟#1727 一樣close 掉了

@leesei 不是,这个issues的提出者与评论 https://github.com/hexojs/hexo/issues/1710#issuecomment-174568429 不是同一个问题。可能是Highlight.js对某些长句子的处理有BUG或者是Hexo在这个方面有点问题。

The content of ln 51 is relevant. I think it is a bug of highlight.js
This is the reduced test case.

``````

Fail

typedef long long ll;
ll ans = (sum(bit0, b) + b*sum(bit1, b)) - (sum(bit0, a-1) + (a-1)*sum(bit1, a-1));
typedef long long ll;
ll ans = (sum(bit0, b) + b*sum(bit1, b));

Success

typedef long long ll;
ll ans = sum(bit0, b) + b*sum(bit1, b);

``````

可以考虑换个渲染引擎供用户选择么?。。比如弄成插件形式

Highlight.js 9.3.0 fixed the original problem.
Clean node_modules and npm install to pick up the latest version.

Discuss using other highlight engine in this issue: https://github.com/hexojs/hexo/issues/1300

Was this page helpful?
0 / 5 - 0 ratings