Skip to content

Some codes of cpp cannot be rendered #3437

Closed
@Vanessa219

Description

@Vanessa219

Describe the issue
Some code of cpp can not be rendered.

Which language seems to have the issue?
cpp

Are you using highlight or highlightAuto?

highlight

...

Sample Code to Reproduce

image

#include <iostream>
#include <Eigen/Core>
int main(int argc, char** argv)
{
    //1.方阵
    Eigen::Matrix3f  A;   //本质是Eigen::Matrix<float,3,3> A;  
    A << 1,2,3,4,5,6,7,8,9;
    std::cout << "A= \n" << A << std::endl;

    //2. 转置操作
    Eigen::Matrix3f  A_T =  A.transpose();
    std::cout << "\nA的转置矩阵A_T= \n" << A_T << std::endl;

    //3. 零矩阵
    Eigen::Matrix<float,3,5> B = Eigen::Matrix<float,3,5>::Zero();
    std::cout << "\nB= \n" << B << std::endl;

    //4. 对角矩阵
    //4.1 构造对角矩阵
    Eigen::VectorXd vector(5);                //构建5维向量
    vector<<1,2,3,4,5;                        //向量赋值
    Eigen::MatrixXd  C(vector.asDiagonal());  //使用向量生成对角阵
    std::cout << "\nC= \n" << C << std::endl;

    //4.2 从普通矩阵中提取对角元素组成向量 
    std::cout << "\n从C中提取对角元素构成向量= \n" << C.diagonal() << std::endl;    //C也可以不是方阵

    //5. 单位矩阵
    //5.1 构造单位矩阵
    Eigen::Matrix3f D = Eigen::Matrix3f::Identity();                    //简写
    Eigen::Matrix<float,4,4> E = Eigen::Matrix<float,4,4>::Identity();  //完整写法
    std::cout << "\n单位矩阵D= \n" << D << std::endl;
    std::cout << "\n单位矩阵E= \n" << E << std::endl;

    //5.2 构造对角线为1的普通矩阵
    Eigen::Matrix<float,3,5> F = Eigen::Matrix<float,3,5>::Identity();
    std::cout << "\n普通对角元素为1的矩阵F= \n" << F << std::endl;

    return 0;
}

Expected behavior

image

Additional context
Code:

element.innerHTML = hljs.highlight(code, {
                language: "cpp",
                ignoreIllegals: true
            }).value;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions