Skip to content

Commit f43858c

Browse files
committed
Enhance MarkdownRenderer to support internal navigation; resolve document paths and update link handling
1 parent 8dda579 commit f43858c

8 files changed

Lines changed: 391 additions & 311 deletions

File tree

spa/src/components/docs/MarkdownRenderer.tsx

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,46 @@ import remarkGfm from 'remark-gfm';
44
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
55
import { oneLight, oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
66
import { useTheme } from '../../hooks/useTheme';
7+
import { useNavigation } from '../../hooks/useNavigation';
8+
import { useDocs } from '../../hooks/useDocs';
79
import { MermaidDiagram } from './MermaidDiagram';
810

911
interface MarkdownRendererProps {
1012
content: string;
1113
}
1214

15+
function resolveDocPath(currentDocPath: string, href: string): string {
16+
const lastSlash = currentDocPath.lastIndexOf('/');
17+
const currentDir = lastSlash >= 0 ? currentDocPath.substring(0, lastSlash) : '';
18+
const baseParts = currentDir ? currentDir.split('/') : [];
19+
20+
for (const part of href.split('/')) {
21+
if (part === '..') {
22+
baseParts.pop();
23+
} else if (part !== '.' && part !== '') {
24+
baseParts.push(part);
25+
}
26+
}
27+
28+
return baseParts.join('/');
29+
}
30+
31+
function collectAllPaths(items: import('../../types').DocsNavItem[]): Set<string> {
32+
const paths = new Set<string>();
33+
for (const item of items) {
34+
if (item.path) paths.add(item.path);
35+
if (item.items.length > 0) {
36+
for (const p of collectAllPaths(item.items)) paths.add(p);
37+
}
38+
}
39+
return paths;
40+
}
41+
1342
export function MarkdownRenderer({ content }: MarkdownRendererProps) {
43+
const { view, navigate } = useNavigation();
44+
const { navigation } = useDocs();
45+
const knownPaths = collectAllPaths(navigation);
46+
1447
return (
1548
<div className="prose-doc max-w-4xl mt-10">
1649
<Markdown
@@ -48,11 +81,38 @@ export function MarkdownRenderer({ content }: MarkdownRendererProps) {
4881
li: ({ children }) => (
4982
<li className="leading-relaxed">{children}</li>
5083
),
51-
a: ({ href, children }) => (
52-
<a href={href} className="text-primary-600 dark:text-primary-400 underline hover:text-primary-700 dark:hover:text-primary-300" target="_blank" rel="noopener noreferrer">
53-
{children}
54-
</a>
55-
),
84+
a: ({ href, children }) => {
85+
const linkClass = "text-primary-600 dark:text-primary-400 underline hover:text-primary-700 dark:hover:text-primary-300";
86+
87+
if (!href || /^(?:https?:|\/\/|mailto:|tel:)/.test(href)) {
88+
return <a href={href} className={linkClass} target="_blank" rel="noopener noreferrer">{children}</a>;
89+
}
90+
91+
if (href.startsWith('#')) {
92+
return <a href={href} className={linkClass}>{children}</a>;
93+
}
94+
95+
const [linkPath, anchor] = href.split('#');
96+
const currentDocPath = view.type === 'doc' ? view.path : '';
97+
const resolved = resolveDocPath(currentDocPath, linkPath!);
98+
99+
if (!knownPaths.has(resolved) && !/\.md$/.test(linkPath!)) {
100+
return <a href={href} className={linkClass} target="_blank" rel="noopener noreferrer">{children}</a>;
101+
}
102+
103+
return (
104+
<a
105+
href={href}
106+
className={linkClass}
107+
onClick={e => {
108+
e.preventDefault();
109+
navigate({ type: 'doc', path: resolved, anchor: anchor || undefined });
110+
}}
111+
>
112+
{children}
113+
</a>
114+
);
115+
},
56116
code: CodeBlock,
57117
pre: ({ children }) => <>{children}</>,
58118
blockquote: ({ children }) => (

templates/doc.html.php

Lines changed: 298 additions & 298 deletions
Large diffs are not rendered by default.

tests/Functional/docs/introduction.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Use the Club API to access contacts, conversations, group messages, and more and
44

55
## Getting started
66

7-
To get started, create a new application in your developer settings, then read about how to make requests for the resources you need to access using our HTTP APIs or dedicated client SDKs. When your integration is ready to go live, publish it to our integrations directory to reach the Club community.
7+
To get started, follow the [Quickstart guide](./quickstart.md) to create a new application in your developer settings, then read about how to make requests for the resources you need to access using our HTTP APIs or dedicated client SDKs. When your integration is ready to go live, publish it to our integrations directory to reach the Club community.
8+
9+
For details on the domain model, see the [Property module](./specs/catalog/property/domain/models.md) and its [business rules](./specs/catalog/property/domain/business-rules.md).
810

911
| Field1 | Field2 | Description |
1012
| --- | --- | --- |

tests/Functional/docs/quickstart.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This guide will get you all set up and ready to use the Club API. We'll cover ho
55
## What's next?
66
Great, you're now set up with an API client and have made your first request to the API. Here are a few links that might be handy as you venture further into the Protocol API:
77

8-
* Grab your API key from the Protocol dashboard
9-
* Check out the Conversations endpoint
10-
* Learn about the different error messages in Protocol
8+
* Read the [Introduction](./introduction.md) for an overview of the Club API
9+
* Explore the [Property module](./specs/catalog/property/README.md) to understand the catalog structure
10+
* Review the [API endpoints](./specs/catalog/property/presentation/api.md) and [webhook integration](./specs/catalog/property/presentation/webhook.md)
11+
* Check out the [SDK reference](./sdk/README.md) for client libraries
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
# Property Module
22

3-
A property is a key-value pair that describes an aspect of a catalog item. Properties can be used to provide additional information about an item, such as its color, size, or material. They can also be used to categorize items, such as by brand or type.
3+
A property is a key-value pair that describes an aspect of a catalog item. Properties can be used to provide additional information about an item, such as its color, size, or material. They can also be used to categorize items, such as by brand or type.
4+
5+
## Layers
6+
7+
* **Domain**[Models](./domain/models.md) | [Business Rules](./domain/business-rules.md) | [Ubiquitous Language](./domain/ubiquitous-language.md)
8+
* **Application**[Use-cases](./application/use-cases.md)
9+
* **Infrastructure**[Integration](./infrastructure/integration.md)
10+
* **Presentation**[API](./presentation/api.md) | [Console](./presentation/console.md) | [Webhook](./presentation/webhook.md)
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
# Application Use-cases
1+
# Application Use-cases
2+
3+
This section describes the application-level operations on the Property module. These use-cases operate on the [Domain Models](../domain/models.md) and enforce the [Business Rules](../domain/business-rules.md).
4+
5+
For the external-facing interfaces, see the [API endpoints](../presentation/api.md) and the [Console commands](../presentation/console.md).
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# Domain Business Rules
1+
# Domain Business Rules
2+
3+
These rules apply to the entities defined in [Domain Models](./models.md). See also the [Ubiquitous Language](./ubiquitous-language.md) for term definitions.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
# Domain Models
1+
# Domain Models
2+
3+
The Property aggregate is the core of the Catalog context. For terminology definitions, see the [Ubiquitous Language](./ubiquitous-language.md). Validation constraints are documented in the [Business Rules](./business-rules.md).
4+
5+
For how these models are used in practice, refer to the [Application Use-cases](../application/use-cases.md).

0 commit comments

Comments
 (0)