【问题标题】:Doxygen @code line numbersDoxygen @code 行号
【发布时间】:2014-02-19 18:45:23
【问题描述】:

有没有办法在 @code ... @endcode 块内显示代码行号?从 doxygen 手册中的屏幕截图来看,似乎有,但我无法找到 doxygen 本身的选项,或完成此操作的标记语法。

我需要它才能在代码块之后编写类似“在上面的代码中,第 3 行”之类的内容。

还针对受保护的代码块进行了测试,仍然没有得到任何数字。

【问题讨论】:

  • 我想到了两个问题。 1. 你想要哪些“行号”——文件中 doxygen 注释的行号,还是注释中引用的源的相对行号? 2. 你在 doxygen 手册的哪里看到这些屏幕截图?我正在查看在线手册的\code 部分,但没有看到任何内容。
  • @Cheeseminer:我对后面的行号(相对的)感兴趣。至于我的意思的一个例子,请查看手册的这一部分:stack.nl/~dimitri/doxygen/manual/markdown.html#md_fenced
  • 嗯。出于兴趣,您正在记录什么代码语言?该示例尤其在 Markdown 部分和注释 python 代码中;而等效的 C 代码示例没有它们。我想知道这是否是 doxygen 为 Markdown 使用的任何解释器的结果。这不是标准的 Markdown。我没有建议,对不起。为问题 +1。
  • 我确实在使用 C 代码。我不认为将 {.py} 添加到我的@code 会很好地工作......不过,您似乎是对的 - 显然 C 不支持代码行,这奇怪的是任意的。

标签: doxygen


【解决方案1】:

简答

似乎至少在当前版本(1.8.9)中增加了行号:


详情

Python 代码格式化程序

如果g_sourceFileDef 评估为TRUE,则Python 代码格式化程序包括行号:

/*! start a new line of code, inserting a line number if g_sourceFileDef
 * is TRUE. If a definition starts at the current line, then the line
 * number is linked to the documentation of that definition.
 */
static void startCodeLine()
{
  //if (g_currentFontClass) { g_code->endFontClass(); }
  if (g_sourceFileDef)

(https://github.com/doxygen/doxygen/blob/Release_1_8_9/src/pycode.l#L356 )

如果提供(非零),则从 FileDef *fd 传递到 parseCode/parsePythonCode 初始化,否则从 new FileDef(<...>) 初始化:

g_sourceFileDef = fd;
<...>
if (fd==0)
{
  // create a dummy filedef for the example
  g_sourceFileDef = new FileDef("",(exName?exName:"generated"));
  cleanupSourceDef = TRUE;
}

(https://github.com/doxygen/doxygen/blob/Release_1_8_9/src/pycode.l#L1458) 所以似乎所有 Python 代码都包含行号

C 代码格式化程序

C 代码格式化程序有一个附加变量 g_lineNumbers,如果 g_sourceFileDefg_lineNumbers 评估为 TRUE,则包括行号:

/*! start a new line of code, inserting a line number if g_sourceFileDef
 * is TRUE. If a definition starts at the current line, then the line
 * number is linked to the documentation of that definition.
 */
static void startCodeLine()
{
  //if (g_currentFontClass) { g_code->endFontClass(); }
  if (g_sourceFileDef && g_lineNumbers)

(https://github.com/doxygen/doxygen/blob/Release_1_8_9/src/code.l#L486)

它们的初始化方式如下:

g_sourceFileDef = fd;
g_lineNumbers = fd!=0 && showLineNumbers;
<...>
if (fd==0)
{
  // create a dummy filedef for the example
  g_sourceFileDef = new FileDef("",(exName?exName:"generated"));
  cleanupSourceDef = TRUE;
}

(https://github.com/doxygen/doxygen/blob/Release_1_8_9/src/code.l#L3623)

请注意,g_lineNumbers 仍然是 FALSE,如果提供的 fd 值为 0

HtmlDocVisitor

parseCode 调用HtmlDocVisitor::visit 中,只有一个(对于DocInclude::IncWithLines,对应于\includelineno)通过非零fdhttps://github.com/doxygen/doxygen/blob/Release_1_8_9/src/htmldocvisitor.cpp#L540 所以这似乎是唯一会导致 C 代码列表中包含行号的命令


【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-26
    • 1970-01-01
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    • 2014-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多