Skip to content

Commit

Permalink
feat: Expose publicPath option
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Nov 30, 2023
1 parent 2c3bf59 commit c91ffef
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 126 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-socks-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'typedoc-plugin-markdown': patch
---

- Exposed `publicPath` option
1 change: 1 addition & 0 deletions packages/typedoc-plugin-markdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Options that configure additional functionality.
* [`--preserveAnchorCasing`](./docs/plugin-options.md#--preserveanchorcasing)
* [`--anchorPrefix`](./docs/plugin-options.md#--anchorprefix)
* [`--namedAnchors`](./docs/plugin-options.md#--namedanchors)
* [`--publicPath`](./docs/plugin-options.md#--publicpath)

## Contributing

Expand Down
13 changes: 13 additions & 0 deletions packages/typedoc-plugin-markdown/docs/plugin-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This document describes all the additional options exposed by the plugin.
* [`--preserveAnchorCasing`](#--preserveanchorcasing)
* [`--anchorPrefix`](#--anchorprefix)
* [`--namedAnchors`](#--namedanchors)
* [`--publicPath`](#--publicpath)

## File output options

Expand Down Expand Up @@ -397,3 +398,15 @@ There are two flags exposed by this option:
[↑ Top](#options-guide)

***

### `--publicPath`

Specify the base path for all urls. If undefined urls will be relative. Defaults to `"undefined"`.

```shell
--publicPath <string>
```

[↑ Top](#options-guide)

***
15 changes: 15 additions & 0 deletions packages/typedoc-plugin-markdown/src/plugin/options/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export const indexFormat: DeclarationOption = {
};

/**
* @category other
*/
export const preserveAnchorCasing: DeclarationOption = {
name: 'preserveAnchorCasing',
Expand All @@ -288,6 +289,7 @@ export const preserveAnchorCasing: DeclarationOption = {
};

/**
* @category other
*/
export const anchorPrefix: DeclarationOption = {
name: 'anchorPrefix',
Expand All @@ -297,12 +299,15 @@ export const anchorPrefix: DeclarationOption = {
};

/**
*
* Internal anchor links are used when referencing symbols with in-page table of contents or when referenced with by {\@link} tags.
*
* There are two flags exposed by this option:
*
* - `headings` - Add HTML named anchors to heading for implementations that do not assign header ids.
* - `tableRows` - Add anchors to table rows when table formats are selected and no heading elements are present.
*
* @category other
*/
export const namedAnchors: DeclarationOption = {
name: 'namedAnchors',
Expand All @@ -313,3 +318,13 @@ export const namedAnchors: DeclarationOption = {
tableRows: false,
},
};

/**
* @category other
*/
export const publicPath: DeclarationOption = {
name: 'publicPath',
help: 'Specify the base path for all urls. If undefined urls will be relative.',
type: ParameterType.String,
defaultValue: undefined,
};
2 changes: 2 additions & 0 deletions packages/typedoc-plugin-markdown/src/plugin/options/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ declare module 'typedoc' {
preserveAnchorCasing: boolean;
anchorPrefix: string;
namedAnchors: Record<string, boolean>;
publicPath: string;
}
}

Expand All @@ -48,4 +49,5 @@ export interface PluginOptions {
preserveAnchorCasing: boolean;
anchorPrefix: string;
namedAnchors: Record<string, boolean>;
publicPath: string;
}
6 changes: 6 additions & 0 deletions packages/typedoc-plugin-markdown/src/theme/render-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ export class MarkdownThemeRenderContext {
if (URL_PREFIX.test(url)) {
return url;
} else {
const publicPath = this.options.getValue('publicPath');

if (publicPath) {
return path.join(publicPath, url);
}

const relative = path.relative(
path.dirname(this.page?.url || '.'),
path.dirname(url),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const FIXTURES: Fixture[] = [
theme: 'custom-theme',
indexFormat: 'table',
hideInPageTOC: true,
publicPath: 'http://public-path',
},
],
},
Expand All @@ -91,6 +92,7 @@ export const FIXTURES: Fixture[] = [
namedAnchors: {
tableRows: true,
},
publicPath: 'http://public-path',
},
],
},
Expand All @@ -104,11 +106,6 @@ export const FIXTURES: Fixture[] = [
hideGenerator: true,
name: 'packages-example',
},
{
entryPointStrategy: 'packages',
hideGenerator: true,
name: 'packages-example',
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ Comments form module comments
Links using \`{@link}\` inline tags.
- [CommentInterface](interfaces/CommentInterface.md) - Links to CommentInterface
- [Links to CommentInterface.prop](interfaces/CommentInterface.md#prop)
- [Links to CommentInterface.propb](interfaces/CommentInterface.md#propb)
- [CommentEnum.MemberB](enumerations/CommentEnum.md#memberb)
- [SameName:var](variables/SameName.md)
- [SameName:interface](interfaces/SameName.md)
- [SameName.prop](interfaces/SameName.md#prop)
- [prop:var](variables/prop.md)
- [CommentInterface](http:/public-path/interfaces/CommentInterface.md) - Links to CommentInterface
- [Links to CommentInterface.prop](http:/public-path/interfaces/CommentInterface.md#prop)
- [Links to CommentInterface.propb](http:/public-path/interfaces/CommentInterface.md#propb)
- [CommentEnum.MemberB](http:/public-path/enumerations/CommentEnum.md#memberb)
- [SameName:var](http:/public-path/variables/SameName.md)
- [SameName:interface](http:/public-path/interfaces/SameName.md)
- [SameName.prop](http:/public-path/interfaces/SameName.md#prop)
- [prop:var](http:/public-path/variables/prop.md)
External links:
Expand Down Expand Up @@ -109,22 +109,22 @@ Some <p> html </p> inside codeblock
| Enumeration | Description |
| :------ | :------ |
| [CommentEnum](enumerations/CommentEnum.md) | - |
| [CommentEnum](http:/public-path/enumerations/CommentEnum.md) | - |
## Interfaces
| Interface | Description |
| :------ | :------ |
| [CommentInterface](interfaces/CommentInterface.md) | - |
| [SameName](interfaces/SameName.md) | - |
| [CommentInterface](http:/public-path/interfaces/CommentInterface.md) | - |
| [SameName](http:/public-path/interfaces/SameName.md) | - |
## Variables
| Variable | Description |
| :------ | :------ |
| [SameName](variables/SameName.md) | - |
| [prop](variables/prop.md) | - |
| [propb](variables/propb.md) | - |
| [SameName](http:/public-path/variables/SameName.md) | - |
| [prop](http:/public-path/variables/prop.md) | - |
| [propb](http:/public-path/variables/propb.md) | - |
"
`;
Expand Down Expand Up @@ -266,14 +266,14 @@ Comments form module comments
Links using \`{@link}\` inline tags.
- [CommentInterface](exports.md#commentinterface) - Links to CommentInterface
- [Links to CommentInterface.prop](exports.md#prop)
- [Links to CommentInterface.propb](exports.md#propb)
- [CommentEnum.MemberB](exports.md#memberb)
- [SameName:var](exports.md#samename-1)
- [SameName:interface](exports.md#samename)
- [SameName.prop](exports.md#prop-1)
- [prop:var](exports.md#prop-2)
- [CommentInterface](http:/public-path/exports.md#commentinterface) - Links to CommentInterface
- [Links to CommentInterface.prop](http:/public-path/exports.md#prop)
- [Links to CommentInterface.propb](http:/public-path/exports.md#propb)
- [CommentEnum.MemberB](http:/public-path/exports.md#memberb)
- [SameName:var](http:/public-path/exports.md#samename-1)
- [SameName:interface](http:/public-path/exports.md#samename)
- [SameName.prop](http:/public-path/exports.md#prop-1)
- [prop:var](http:/public-path/exports.md#prop-2)
External links:
Expand Down Expand Up @@ -309,7 +309,7 @@ Some <p> html </p> inside codeblock
| Member | Value | Description |
| :------ | :------ | :------ |
| <a id="member" name="member"></a> \`Member\` | \`0\` | Comment for Member<br /><br />**Deprecated**<br />Deprecated member<br /><br />**See**<br />[SameName](exports.md#samename-1) |
| <a id="member" name="member"></a> \`Member\` | \`0\` | Comment for Member<br /><br />**Deprecated**<br />Deprecated member<br /><br />**See**<br />[SameName](http:/public-path/exports.md#samename-1) |
| <a id="memberb" name="memberb"></a> \`MemberB\` | \`1\` | - |
## Interfaces
Expand Down
Loading

0 comments on commit c91ffef

Please sign in to comment.