Files
angular-docs-cn/aio/tools/transforms/angular-api-package/processors/splitDescription.js
T
Zhicheng Wang 2cd125f40c docs(API): 改进标题行翻译方式
docs(API): 翻译了 directive.ts 中的所有 tsdoc
2018-08-31 09:01:12 +08:00

29 lines
984 B
JavaScript

/**
* Split the description (of selected docs) into:
* * `shortDescription`: the first paragraph
* * `description`: the rest of the paragraphs
*/
module.exports = function splitDescription() {
return {
$runAfter: ['tags-extracted', 'migrateLegacyJSDocTags'],
$runBefore: ['processing-docs'],
docTypes: [],
$process(docs) {
docs.forEach(doc => {
if (this.docTypes.indexOf(doc.docType) !== -1 && doc.description !== undefined) {
const description = doc.description.trim();
const endOfParagraph = description.search(/\n\s*\n+(?!.*[\u4e00-\u9fa5])/); // 从第一个非汉字行开始拆分
if (endOfParagraph === -1) {
doc.shortDescription = description;
doc.description = '';
} else {
doc.shortDescription = description.substr(0, endOfParagraph).trim();
doc.description = description.substr(endOfParagraph).trim();
}
}
});
}
};
};