assistant: Add /rustdoc slash command (#12453)

This PR adds a `/rustdoc` slash command for retrieving and inserting
rustdoc docs into the Assistant.

Right now the command accepts the crate name as an argument and will
return the top-level docs from `docs.rs`.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-05-29 18:14:29 -04:00 committed by GitHub
parent dd328efaa7
commit 08881828ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 152 additions and 21 deletions

View file

@ -4,6 +4,8 @@
mod markdown_writer;
use std::io::Read;
use anyhow::{Context, Result};
use html5ever::driver::ParseOpts;
use html5ever::parse_document;
@ -14,7 +16,7 @@ use markup5ever_rcdom::RcDom;
use crate::markdown_writer::MarkdownWriter;
/// Converts the provided rustdoc HTML to Markdown.
pub fn convert_rustdoc_to_markdown(html: &str) -> Result<String> {
pub fn convert_rustdoc_to_markdown(mut html: impl Read) -> Result<String> {
let parse_options = ParseOpts {
tree_builder: TreeBuilderOpts {
drop_doctype: true,
@ -24,7 +26,7 @@ pub fn convert_rustdoc_to_markdown(html: &str) -> Result<String> {
};
let dom = parse_document(RcDom::default(), parse_options)
.from_utf8()
.read_from(&mut html.as_bytes())
.read_from(&mut html)
.context("failed to parse rustdoc HTML")?;
let markdown_writer = MarkdownWriter::new();