1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-27 17:49:08 -05:00

fix(doc): remove JSDoc comment truncation (#6031)

This commit is contained in:
Matt Dumler 2020-06-01 17:40:51 -05:00 committed by GitHub
parent d8c681d37a
commit a4567e0e01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,7 +35,7 @@ pub fn format_details(node: doc::DocNode) -> String {
let js_doc = node.js_doc.clone(); let js_doc = node.js_doc.clone();
if let Some(js_doc) = js_doc { if let Some(js_doc) = js_doc {
details.push_str(&format_jsdoc(js_doc, false, 1)); details.push_str(&format_jsdoc(js_doc, 1));
} }
details.push_str("\n"); details.push_str("\n");
@ -92,7 +92,7 @@ fn format_(doc_nodes: Vec<doc::DocNode>, indent: i64) -> String {
for node in sorted { for node in sorted {
output.push_str(&format_signature(&node, indent)); output.push_str(&format_signature(&node, indent));
if let Some(js_doc) = node.js_doc { if let Some(js_doc) = node.js_doc {
output.push_str(&format_jsdoc(js_doc, true, indent)); output.push_str(&format_jsdoc(js_doc, indent));
} }
output.push_str("\n"); output.push_str("\n");
if DocNodeKind::Namespace == node.kind { if DocNodeKind::Namespace == node.kind {
@ -308,19 +308,15 @@ fn add_indent(string: String, indent: i64) -> String {
} }
// TODO: this should use some sort of markdown to console parser. // TODO: this should use some sort of markdown to console parser.
fn format_jsdoc(jsdoc: String, truncated: bool, indent: i64) -> String { fn format_jsdoc(jsdoc: String, indent: i64) -> String {
let mut lines = jsdoc.split("\n\n").map(|line| line.replace("\n", " ")); let lines = jsdoc.split("\n\n").map(|line| line.replace("\n", " "));
let mut js_doc = String::new(); let mut js_doc = String::new();
if truncated { for line in lines {
let first_line = lines.next().unwrap_or_else(|| "".to_string()); js_doc.push_str(&add_indent(format!("{}\n", line), indent + 1));
js_doc.push_str(&add_indent(format!("{}\n", first_line), indent + 1));
} else {
for line in lines {
js_doc.push_str(&add_indent(format!("{}\n", line), indent + 1));
}
} }
format!("{}", colors::gray(js_doc)) format!("{}", colors::gray(js_doc))
} }