Skip to content

Commit

Permalink
Delete the Code markdown type
Browse files Browse the repository at this point in the history
Summary: Used once to add backticks around a format string. Simplify.

Reviewed By: stepancheg

Differential Revision: D44727992

fbshipit-source-id: 42a22f1fe57a95932e111583848fb686bfdb14d7
  • Loading branch information
ndmitchell authored and facebook-github-bot committed Apr 6, 2023
1 parent da1e0dc commit e1f12b7
Showing 1 changed file with 7 additions and 32 deletions.
39 changes: 7 additions & 32 deletions starlark-rust/starlark/src/docs/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ fn render_property(name: &str, property: &Property) -> String {
let mut header = format!("## {}", name);
if property.typ.is_some() {
header += &format!(
" : {}",
Code(Box::new(TypeRenderer::Type(&property.typ)))
.render_markdown(MarkdownFlavor::DocFile)
" : `{}`",
TypeRenderer::Type(&property.typ).render_markdown(MarkdownFlavor::DocFile)
);
};
let summary = render_doc_string(DSOpts::Summary, &property.docs);
Expand Down Expand Up @@ -345,22 +344,6 @@ impl<'a> RenderMarkdown for TypeRenderer<'a> {
}
}

/// A string that should be put in "`" and be rendered literally.
struct Code<'a>(Box<dyn RenderMarkdown + 'a>);

impl<'a> RenderMarkdown for Code<'a> {
fn render_markdown_opt(&self, flavor: MarkdownFlavor) -> Option<String> {
match flavor {
MarkdownFlavor::DocFile => self
.0
.render_markdown_opt(flavor)
.map(|md| format!("`{}`", md)),
MarkdownFlavor::LspSummary => None,
}
}
}

/// A code block that optionally has a language. Note that this will always take multiple
/// lines, so may not be ideal for tables at the moment.
struct CodeBlock<'a> {
Expand Down Expand Up @@ -639,11 +622,6 @@ mod test {
assert_eq!(expected_f4, render_function("f4", &f4));
}

#[test]
fn doc_file_literal() {
assert_eq!("`foo`", render(&Code(Box::new("foo".to_owned()))));
}

#[test]
fn doc_file_module() {
let ds = sample_ds();
Expand Down Expand Up @@ -785,18 +763,15 @@ mod test {
let ds_no_details = sample_ds_no_details();
let typ = sample_type();

let expected_no_docs = format!(
"## foo1 : {}",
render(&Code(Box::new(TypeRenderer::Type(&typ))))
);
let expected_no_docs = format!("## foo1 : `{}`", render(&TypeRenderer::Type(&typ)));
let expected_no_details = format!(
"## foo2 : {}\n\n{}",
render(&Code(Box::new(TypeRenderer::Type(&typ)))),
"## foo2 : `{}`\n\n{}",
render(&TypeRenderer::Type(&typ)),
render_ds_summary(&ds_no_details)
);
let expected_with_docs = format!(
"## foo3 : {}\n\n{}\n\n{}",
render(&Code(Box::new(TypeRenderer::Type(&typ)))),
"## foo3 : `{}`\n\n{}\n\n{}",
render(&TypeRenderer::Type(&typ)),
render_ds_summary(&ds),
render_ds_details(&ds)
);
Expand Down

0 comments on commit e1f12b7

Please sign in to comment.