和---关联 这个问题, ,我想知道是否有人知道将单个 doxygen 注释转换为 HTML 的 javascript 代码片段/库?

例如,

/** This is a comment block
 *
 * \b bold text
 * \i italic text
 */

会被转换为类似的东西:

<p>This is a comment block</p>
<p><b>bold</b> text</p>
<p><i>italic</i> text</p>

与 doxygen 的所有其他格式相关的标签类似。

我发现了 已经,如果我必须自己实现它,这似乎是一个很好的起点,但可能我错过了一个完整的项目:-)

所以,欢迎提出建议!

有帮助吗?

解决方案

利用至少可以执行以下操作的现有工具/代码库 部分 你想要的就是你最好的选择。解析不是一个简单的问题,尤其是在代码中查找 doxygen 注释,尤其是在处理多种语言时。快速搜索并没有发现任何非常明显的项目,但如果您愿意在需要时创建自己的项目,我建议从 doxygen 代码库本身开始。它是开源的,可以通过 SVN 或者 直接下载. 。请记住,doxygen 是用 C++ 编写的,但如果您可以遵循解析器的操作(可能仅适用于特定语言),它可以为您节省大量工作并防止丢失极端情况等。这完全取决于您希望您的解决方案有多强大,以及是否只有您使用它,或者您最终可能会为其他人提供支持。祝你好运!

其他提示

 function commentToTag(comment) {
 
 var header = null;
 var commentHtml = '';
 
 comment.split('\n').forEach(function (i) {
 		var array = i.split(' ');
    do {
 				var index = array.indexOf('');
				if (index !== -1) array.splice(index, 1);
 				index = array.indexOf('');
    } while (index !== -1);
    do {
 				var index = array.indexOf('*');
				if (index !== -1) array.splice(index, 1);
 				index = array.indexOf('*');
    } while (index !== -1);
    do {
 				var index = array.indexOf('/**');
				if (index !== -1) array.splice(index, 3);
 				index = array.indexOf('/**');
    } while (index !== -1);
    do {
 				var index = array.indexOf('*/');
				if (index !== -1) array.splice(index, 2);
 				index = array.indexOf('*/');
    } while (index !== -1);
    if (array.length === 0) return;
    if (header === null) {
    		header = "<p>" + array.join(' ') + "</p>\n";
        return;
    }
    const tag = array.splice(0, 1);
    commentHtml += "<p><"+tag + ">"+array.splice(0,1)+"</" +tag+ ">" + array.join(' ') + '</p>\n';
    
    
 });
 return header + commentHtml;
 
 }
 
 var comment = `/** This is a comment block
 *
 * \i bold text
 * \i italic text
 */`;
 console.log(commentToTag(comment));

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top