-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
107 deletions.
There are no files selected for viewing
65 changes: 0 additions & 65 deletions
65
packages/typedoc-plugin-markdown/src/components/front-matter.ts
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
packages/typedoc-plugin-markdown/src/utils/front-matter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { PageEvent } from 'typedoc/dist/lib/output/events'; | ||
|
||
import { reflectionTitle } from '../resources/helpers/reflection-title'; | ||
|
||
/* | ||
* Front Matter variable model. | ||
*/ | ||
export interface FrontMatterVars { | ||
[key: string]: string | number | boolean; | ||
} | ||
|
||
/* | ||
* Prepends YAML block to top of page. | ||
* @param page | ||
* @param vars | ||
*/ | ||
export const addYAML = (page: PageEvent, vars: FrontMatterVars) => { | ||
if (page.contents) { | ||
page.contents = page.contents | ||
.replace(/^/, toYAML(vars) + '\n\n') | ||
.replace(/[\r\n]{3,}/g, '\n\n'); | ||
} | ||
}; | ||
|
||
/* | ||
* Returns the page title as rendered in the document h1(# title) | ||
* @param page | ||
*/ | ||
export const getPageTitle = (page: PageEvent) => { | ||
return reflectionTitle.call(page, false); | ||
}; | ||
|
||
/** | ||
* Converts YAML object to a YAML string | ||
* @param vars | ||
*/ | ||
const toYAML = (vars: FrontMatterVars) => { | ||
const yaml = `--- | ||
${Object.entries(vars) | ||
.map( | ||
([key, value]) => | ||
`${key}: ${ | ||
typeof value === 'string' ? `"${escapeString(value)}"` : value | ||
}`, | ||
) | ||
.join('\n')} | ||
---`; | ||
return yaml; | ||
}; | ||
|
||
// prettier-ignore | ||
const escapeString=(str: string)=> { | ||
return str.replace(/([^\\])'/g, '$1\\\'').replace(/\"/g, ''); | ||
} |
10 changes: 0 additions & 10 deletions
10
packages/typedoc-plugin-markdown/test/specs/__snapshots__/front-matter.spec.ts.snap
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
packages/typedoc-plugin-markdown/test/specs/front-matter.spec.ts
This file was deleted.
Oops, something went wrong.