Skip to content

Commit

Permalink
feat(html): external jsdoc module linking (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats authored Aug 8, 2024
1 parent 584fd49 commit 88dd94c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/ddoc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ impl HrefResolver for EmptyResolver {
fn resolve_source(&self, location: &deno_doc::Location) -> Option<String> {
Some(location.filename.to_string())
}

fn resolve_external_jsdoc_module(
&self,
_module: &str,
_symbol: Option<&str>,
) -> Option<(String, String)> {
None
}
}

fn generate_docs_directory(
Expand Down
16 changes: 16 additions & 0 deletions src/html/jsdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ fn parse_links<'a>(md: &'a str, ctx: &RenderContext) -> Cow<'a, str> {
title = short_path.display_name().to_string();
}
}
} else if let Some((external_link, external_title)) =
ctx.ctx.href_resolver.resolve_external_jsdoc_module(
module_link,
symbol_match.map(|symbol_match| symbol_match.as_str()),
)
{
link = external_link;
title = external_title;
}

link
Expand Down Expand Up @@ -767,6 +775,14 @@ mod test {
fn resolve_source(&self, _location: &Location) -> Option<String> {
None
}

fn resolve_external_jsdoc_module(
&self,
_module: &str,
_symbol: Option<&str>,
) -> Option<(String, String)> {
None
}
}

#[test]
Expand Down
8 changes: 8 additions & 0 deletions src/html/render_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,14 @@ mod test {
fn resolve_source(&self, location: &Location) -> Option<String> {
Some(location.filename.clone().into_string())
}

fn resolve_external_jsdoc_module(
&self,
_module: &str,
_symbol: Option<&str>,
) -> Option<(String, String)> {
None
}
}

#[test]
Expand Down
8 changes: 8 additions & 0 deletions src/html/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ pub trait HrefResolver {

/// Resolve the URL used in source code link buttons.
fn resolve_source(&self, location: &crate::Location) -> Option<String>;

/// Resolve external JSDoc module links.
/// Returns a tuple with link and title.
fn resolve_external_jsdoc_module(
&self,
module: &str,
symbol: Option<&str>,
) -> Option<(String, String)>;
}

#[derive(Debug, Serialize, Clone)]
Expand Down
8 changes: 8 additions & 0 deletions tests/html_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ impl HrefResolver for EmptyResolver {
fn resolve_source(&self, _location: &deno_doc::Location) -> Option<String> {
None
}

fn resolve_external_jsdoc_module(
&self,
_module: &str,
_symbol: Option<&str>,
) -> Option<(String, String)> {
None
}
}

async fn get_files(subpath: &str) -> IndexMap<ModuleSpecifier, Vec<DocNode>> {
Expand Down

0 comments on commit 88dd94c

Please sign in to comment.