mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-23 01:48:18 +00:00
refactoring
This commit is contained in:
32
langserver/doc-formatter.js
Normal file
32
langserver/doc-formatter.js
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @param {string} header
|
||||
* @param {string} documentation
|
||||
* @returns {import('vscode-languageserver').MarkupContent}
|
||||
*/
|
||||
function formatDoc(header, documentation) {
|
||||
if (!documentation) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
kind: 'markdown',
|
||||
value: `${header ? header + '\n\n' : ''}${
|
||||
documentation
|
||||
.replace(/(^\/\*+|(?<=\n)[ \t]*\*+\/?|\*+\/)/gm, '')
|
||||
.replace(/(\n[ \t]*@[a-z]+)|(<p(?: .*)?>)|(<\/?i>|<\/?em>)|(<\/?b>|<\/?strong>|<\/?dt>)|(<\/?tt>)|(<\/?code>|<\/?pre>|<\/?blockquote>)|(\{@link.+?\}|\{@code.+?\})|(<li>)|(<a href="\{@docRoot\}.*?">.+?<\/a>)|(<h\d>)|<\/?dd ?.*?>|<\/p ?.*?>|<\/h\d ?.*?>|<\/?div ?.*?>|<\/?[uo]l ?.*?>/gim, (_,prm,p,i,b,tt,c,lc,li,a,h) => {
|
||||
return prm ? ` ${prm}`
|
||||
: p ? '\n\n'
|
||||
: i ? '*'
|
||||
: b ? '**'
|
||||
: tt ? '`'
|
||||
: c ? '\n```'
|
||||
: lc ? lc.replace(/\{@\w+\s*(.+)\}/, (_,x) => `\`${x.trim()}\``)
|
||||
: li ? '\n- '
|
||||
: a ? a.replace(/.+?\{@docRoot\}(.*?)">(.+?)<\/a>/m, (_,p,t) => `[${t}](https://developer.android.com/${p})`)
|
||||
: h ? `\n${'#'.repeat(1 + parseInt(h.slice(2,-1),10))} `
|
||||
: '';
|
||||
})
|
||||
}`,
|
||||
};
|
||||
}
|
||||
|
||||
exports.formatDoc = formatDoc;
|
||||
Reference in New Issue
Block a user