【问题标题】:Numbered anchors in doxygendoxygen 中的编号锚
【发布时间】:2012-08-03 16:12:07
【问题描述】:

我有很多锚点可以用 doxygen 来描绘,例如

\anchor pic_foo
\image html foo.gif "My Caption"
\anchor pic_bar
\image html bar.gif "My Caption"

每当我使用\ref 链接其中一个时,我都必须弥补 一些很好的描述,所以锚的原始名称不会出现在 输出。

是否有可能在 doxygen 中有类似编号的锚点 链接文本将是该锚点的编号?理想情况下 类似:

\anchor pic_foo
\image html foo.gif "My Caption"
\anchor pic_bar
\image html bar.gif "My Caption"

As Figure \ref pic_foo shows... Figure \ref pic_bar is...

最好翻译成:

As Figure 1 shows... Figure 2 is...

其中的数字是链接。我会对各种计数方案(全局文档或本地页面)感到满意。

【问题讨论】:

    标签: anchor doxygen


    【解决方案1】:

    我不认为使用 doxygen 可以在页面内或整个文档中自动添加数字(我很乐意在这里得到更正)。但是,您的问题的一个简单解决方案是将锚文本替换为拼写出来的数字,即“一”、“二”、“三”……等等。或者,如果您有很多数字,您可以使用罗马数字。普通数字似乎不能用作锚链接。

    然后,您的示例将变为,在图形标题中带有附加文本,

    \anchor one
    \image html foo.gif "Figure one: My Caption"
    \anchor two
    \image html bar.gif "Figure two: My Caption"
    
    As Figure \ref one shows... Figure \ref two is...
    

    导致

    Here Figure one shows... Figure two is...
    

    带有onetwo 超链接到您的数字。

    然后您可以在配置文件中定义一个别名,例如 \fref,定义为 Figure \ref,它将自动在超链接数字前加上文本“Figure”。

    这个解决方案可以接受吗?我能想到的唯一其他选择涉及对 doxygen 输出进行后处理,但上述解决方案是迄今为止最简单的。

    更新

    以下 Python 代码会将锚引用转换为递增计数器:

    # Test documentation.
    s = r"""
    \anchor pic_foo
    \image html foo.gif "My Caption"
    \anchor pic_bar
    \image html bar.gif "My Caption"
    
    As Figure \ref pic_foo shows... Figure \ref pic_bar is...
    """
    
    # Split string into a list of lines.
    s = s.split('\n')
    
    # Dictionaries for mapping anchor names to an incrementing counter.
    d = {}
    
    numbers = {1: 'one',
        2 : 'two',
        3 : 'three'}
    
    counter = 1
    
    # Find all anchor links and map to the next counter value.
    for line in s:
        if r'\anchor' in line:
            d[line.split(r'\anchor ')[1]] = numbers[counter]
            counter += 1
    
    # Reform original string.
    s = '\n'.join(s)
    
    # Replace anchor links with appropriate counter value.
    for key, value in d.items():
        s = s.replace(key, value)
    
    print s
    

    运行此脚本会产生输出

    \anchor one
    \image html foo.gif "My Caption"
    \anchor two
    \image html bar.gif "My Caption"
    
    As Figure \ref one shows... Figure \ref two is...
    

    修改上述脚本以从标准输入读取并写入标准输出很简单,因此可以轻松地与INPUT_FILTER 配置文件选项结合使用。

    需要注意的一点是,必须扩展字典numbers 以允许包含三个以上的数字。这又是微不足道的,但可能不容易扩展。可以使用从任意数字映射到适当单词的解决方案(请参阅本网站上的其他问题),因此我没有费心在此处实现。

    【讨论】:

    • 非常好。当我实现脚注时,我偶然发现了另一种可能的解决方案。你可以使用JQuery!在我意识到这一点之后,我对 doxygen 文档的思考达到了一个全新的水平。
    • 这听起来很有趣。您能否分享一下您是如何实现脚注的,可能是作为另一个答案或在聊天中?我很想看到。
    • @pmr 请分享您是如何实现脚注的!
    • @ScottDeerwester 我使用并将其包含在生成的文档中。 planetholt.com/articles/jQuery-Footnotes 并添加我自己的ALIASES += "myFootnote{1}=<span class=\"footnote\">\1</span>"。我通过$(document).ready 添加了一个函数,它执行$("#doc-content").append('<ol id="autoFootnotes0" class="footnotesList"></ol>'); $("body").footnotes();,然后就可以了。
    • @pmr 您愿意将此作为对stackoverflow.com/questions/25290453/… 的回答吗?
    猜你喜欢
    • 1970-01-01
    • 2014-05-24
    • 1970-01-01
    • 1970-01-01
    • 2018-04-02
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    相关资源
    最近更新 更多