Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions bin/main.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,14 @@ co(function*() {

//关闭用户输入
process.stdin.on('error', (e) => {
if (e.code !== 'EPIPE' || e.syscall !== 'shutdown') {
throw e;
}
process.stdin.destroy();
// if (e.code !== 'EPIPE' || e.syscall !== 'shutdown') {
// // throw e;
// }
});
process.stdin.end();

}).catch((e) => {
console.log(e);
console.error(e);
});
5 changes: 3 additions & 2 deletions build/creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ const creator = (function () {
['amWiki.search.worker.js', 'amWiki/js/amWiki.search.worker.js'],
['icons.svg', 'amWiki/images/icons.svg'],
['logo.png', 'amWiki/images/logo.png'],
['menubar_bg.png', 'amWiki/images/menubar_bg.png']
['menubar_bg.png', 'amWiki/images/menubar_bg.png'],
['mermaid.min.js', 'amWiki/js/mermaid.min.js']
];
for (let file of fileList) {
that._copyFile(options.filesPath + file[0], options.outputPath + file[1]);
Expand Down Expand Up @@ -330,4 +331,4 @@ const creator = (function () {
};
})();

module.exports = creator;
module.exports = creator;
94 changes: 51 additions & 43 deletions files/amWiki.docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
};

/**
* 设置文档h1、h2、h3描记
* 设置文档h1、h2、h3、h4描记
* @returns {string}
* @private
*/
Expand All @@ -108,7 +108,7 @@
}
var anchorHtml = '<a class="anchor" href="#{title}" name="{title}">' +
'<svg><use xlink:href="#icon:linkAnchor"></use></svg></a>';
$titles = that.$e.view.find('h1,h2,h3');
$titles = that.$e.view.find('h1,h2,h3,h4');
$titles.each(function (index, element) {
var $this = $(element);
var text1 = that._tramsformLinkText($this.text());
Expand All @@ -118,6 +118,8 @@
contentsMd += '1. [' + text1 + '](#' + text2 + ' "' + text2 + '")\n';
} else if ($this.is('h3')) {
contentsMd += '\t1. [' + text1 + '](#' + text2 + ' "' + text2 + '")\n';
} else if ($this.is('h4')) {
contentsMd += '\t\t1. [' + text1 + '](#' + text2 + ' "' + text2 + '")\n';
}
//设置描记
$this.prepend(anchorHtml.replace(/{title}/g, text2));
Expand Down Expand Up @@ -328,46 +330,6 @@
$contents = $contents.add($this);
}
});
//自带序号的目录,不再额外显示一层序号
$contents.find('ol').each(function () {
var $this = $(this);
var $links = $this.children('li').children('a');
var text1 = $links.eq(0).text(),
text2 = $links.eq(1).text();
var conditions = [
//普通数字类型
/^[\((]?(\d+\.?)+[^\d]{2,}/,
//汉字序号类型
/^[\((【第]?[一二三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+/,
//英文序号类型
/^(chapter)|(section)|(part)|(step)/i,
//罗马序号类型
/^[ⅠⅡⅢⅣIⅤⅥⅦⅧⅨⅩⅪⅫLCDM]+\.?/
];
for (var i = 0, cond; cond = conditions[i]; i++) {
if (cond.test(text1) && cond.test(text2)) {
$this.addClass('unindex');
break;
}
}
});
//没写序号的目录,创建序号
var setIndex = function ($elm, index1) {
if ($elm.length == 0) {
return;
}
$elm.children('li').each(function (index2) {
var $this = $(this);
if (!$elm.hasClass('unindex')) {
var index = typeof index1 == 'number' ? (index1 + 1) + '.' + (index2 + 1): (index2 + 1) + '.';
$this.prepend('<i>' + index + '</i>');
}
setIndex($this.children('ol'), index2);
});
};
$contents.children('ol').each(function () {
setIndex($(this));
});
};

/**
Expand Down Expand Up @@ -410,6 +372,26 @@
return url;
};

var _escapes = [
'\\',
'`',
'*',
'{',
'}',
'[',
']',
'(',
')',
'#',
'+',
'-',
'.',
'!',
'_',
'>',
'|' // 表格中有|会让表格变形
];

/**
* 渲染文档
* @param {String} content - 需要渲染的文档内容
Expand All @@ -421,6 +403,9 @@
this.cleanView();
//增加"\"符转义功能
content = content.replace(/\\(.)/g, function (m, s1) {
if (_escapes.indexOf(s1) == -1) {
return m;
}
return '&#' + s1.charCodeAt(0) + ';';
});
//创建脚注
Expand Down Expand Up @@ -455,6 +440,29 @@
that._setJSCommentDisable($elm);
}
});

// 解析 mermaid
this.$e.view.find('pre').each(function (i, element) {
var $elm = $(element); // 标记位置
var txt = $(element).text();

if (txt.indexOf('graph') === 0 || txt.indexOf('sequenceDiagram') === 0 || txt.indexOf('gantt') === 0) {
$(element).hide();

// 使用 mermaid api 解析
mermaid.initialize({
startOnLoad: true
})
$(function () {
var graphDefinition = txt;
var cb = function (svgGraph) {
$elm.after(svgGraph);
}
mermaid.render('mermaid-chart' + i, graphDefinition, cb);
})
}
});

//设置网页title
var title = this.$e.view.find('h1').eq(0).text();
this.$e.title.text(title);
Expand Down Expand Up @@ -537,4 +545,4 @@

return win.AWDocs = Docs;

})(window, document, jQuery);
})(window, document, jQuery);
3 changes: 2 additions & 1 deletion files/amWiki.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
<script type="text/javascript" src="amWiki/js/amWiki.scrollbar.js"></script>
<script type="text/javascript" src="amWiki/js/amWiki.imgsView.js"></script>
<script type="text/javascript" src="amWiki/js/amWiki.js"></script>
<script type="text/javascript" src="amWiki/js/mermaid.min.js"></script>
{{custom.js}}
</div>
<!-- svg -->
Expand Down Expand Up @@ -209,4 +210,4 @@
</div>
</body>

</html>
</html>
7 changes: 7 additions & 0 deletions files/mermaid.min.js

Large diffs are not rendered by default.