Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(html): external jsdoc module linking #622

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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