Skip to content
Merged
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
36 changes: 34 additions & 2 deletions plugins/docusaurus-plugin-ionic-component-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,38 @@ function formatMultiline(str) {
return str.split('\n\n').join('<br /><br />').split('\n').join(' ');
}

/**
* Kebab-case slug for API identifiers (camelCase props, method names).
*/
function apiIdentifierSlug(name) {
return name
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
.replace(/_/g, '-')
.toLowerCase();
}

/**
* Heading id for Properties subheadings.
* Prefixes IDs with `prop-` so they never collide with narrative sections on the same
* doc page that use headings like "Shape", "Fill", or "Size".
*
* Anchors become `#prop-${slug}` rather than `#${slug}`.
*/
function propertyHeadingId(propName) {
return `prop-${apiIdentifierSlug(propName)}`;
}

/**
* Heading id for Methods subheadings.
* Prefixes IDs with `method-` so they never collide with narrative sections on the same
* doc page that use headings like "Dismiss", "Present", or "Close".
*
* Anchors become `#method-${slug}` rather than `#${slug}`.
*/
function methodHeadingId(methodName) {
return `method-${apiIdentifierSlug(methodName)}`;
}

function formatType(attr, type) {
if (attr === 'color') {
/**
Expand Down Expand Up @@ -181,7 +213,7 @@ ${properties
}

return `
### ${prop.name} ${isDeprecated ? '(deprecated)' : ''}
### ${prop.name} ${isDeprecated ? '(deprecated)' : ''} {#${propertyHeadingId(prop.name)}}

| | |
| --- | --- |
Expand Down Expand Up @@ -243,7 +275,7 @@ function renderMethods({ methods }) {
${methods
.map(
(method) => `
### ${method.name}
### ${method.name} {#${methodHeadingId(method.name)}}

| | |
| --- | --- |
Expand Down
Loading