如何获得降价以正确格式化此代码?

时间:2020-03-05 18:47:20  来源:igfitidea点击:

这是一些我无法在markdown中正确设置格式的代码,这是直接的C代码,以'4个空格'格式粘贴到文本框中以表示代码:

#define PRINT(x, format, ...) \
if ( x ) { \
    if ( debug_fd != NULL ) { \
        fprintf(debug_fd, format, ##__VA_ARGS__); \
    } \
    else { \
        fprintf(stdout, format, ##__VA_ARGS__); \
    } \
}

似乎''导致换行符被忽略。好的,我已经习惯了使用bash,但是如果我输入'',第二个不会出现。好像第二个被吸收了。我想念什么吗?

解决方案

回答

在代码的每一行之前至少添加四个空格或者一个硬选项卡。像这样:

#define PRINT(x, format, ...) \
if ( x ) { \
    if ( debug_fd != NULL ) { \
        fprintf(debug_fd, format, ##VA_ARGS); \
} \
else { \
    fprintf(stdout, format, ##VA_ARGS); \
} \
}

回答

#define PRINT(x, format, ...)
if ( x ) 
{
    if ( debug_fd != NULL ) 
    { 
        fprintf(debug_fd, format, ##VA_ARGS); 
    } 
    else 
    { 
        fprintf(stdout, format, ##VA_ARGS); 
    } 
}

回答

我们还可以连续使用HTML标记<pre> <code>。我发现将代码粘贴到窗口中比较容易。

#define PRINT(x, format, ...)
if ( x ) 
{
    if ( debug_fd != NULL ) 
    { 
        fprintf(debug_fd, format, ##VA_ARGS); 
    } 
    else 
    { 
        fprintf(stdout, format, ##VA_ARGS); 
    } 
}