3

关于这个问题,我想知道是否有人知道将单个 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 的所有其他与格式相关的标签都类似。

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

所以,欢迎提出建议!

4

2 回答 2

0

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

于 2009-06-14T16:54:28.050 回答
0

 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));

于 2018-12-24T16:33:40.913 回答