Skip to content

Commit f5dc120

Browse files
amcdnltinayuangao
authored andcommitted
chore(docs): correcting headers and adding header linking (#6040)
* chore(*): correcting headers and adding header linking * chore(*): add specific class name * Update docs.ts
1 parent 21e9768 commit f5dc120

File tree

7 files changed

+33
-18
lines changed

7 files changed

+33
-18
lines changed

guides/getting-started.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ For help getting started with a new Angular app, check out the
33

44
For existing apps, follow these steps to begin using Angular Material.
55

6-
## Step 1: Install Angular Material and Angular CDK
6+
### Step 1: Install Angular Material and Angular CDK
77

88
```bash
99
npm install --save @angular/material @angular/cdk
@@ -16,7 +16,7 @@ build should not be considered stable and may break between releases.
1616
npm install --save angular/material2-builds angular/cdk-builds
1717
```
1818

19-
## Step 2: Animations
19+
### Step 2: Animations
2020

2121
Some Material components depend on the Angular animations module in order to be able to do
2222
more advanced transitions. If you want these animations to work in your app, you have to
@@ -50,7 +50,7 @@ import {NoopAnimationsModule} from '@angular/platform-browser/animations';
5050
export class PizzaPartyAppModule { }
5151
```
5252

53-
## Step 3: Import the component modules
53+
### Step 3: Import the component modules
5454

5555
Import the NgModule for each component you want to use:
5656

@@ -82,7 +82,7 @@ export class MyOwnCustomMaterialModule { }
8282
Whichever approach you use, be sure to import the Angular Material modules _after_ Angular's
8383
`BrowserModule`, as the import order matters for NgModules.
8484

85-
## Step 4: Include a theme
85+
### Step 4: Include a theme
8686

8787
Including a theme is **required** to apply all of the core and theme styles to your application.
8888

@@ -98,7 +98,7 @@ your `index.html`.
9898
For more information on theming and instructions on how to create a custom theme, see the
9999
[theming guide](./theming.md).
100100

101-
## Step 5: Gesture Support
101+
### Step 5: Gesture Support
102102

103103
Some components (`md-slide-toggle`, `md-slider`, `mdTooltip`) rely on
104104
[HammerJS](http://hammerjs.github.io/) for gestures. In order to get the full feature-set of these
@@ -118,7 +118,7 @@ After installing, import it on your app's root module.
118118
import 'hammerjs';
119119
```
120120

121-
## Step 6 (Optional): Add Material Icons
121+
### Step 6 (Optional): Add Material Icons
122122

123123
If you want to use the `md-icon` component with the official
124124
[Material Design Icons](https://material.io/icons/), load the icon font in your `index.html`.
@@ -133,7 +133,7 @@ For more information on using Material Icons, check out the
133133
Note that `md-icon` supports any font or svg icons; using Material Icons is one of many options.
134134

135135

136-
## Appendix: Configuring SystemJS
136+
### Appendix: Configuring SystemJS
137137

138138
If your project is using SystemJS for module loading, you will need to add `@angular/material` and
139139
`@angular/cdk` to the SystemJS configuration.
@@ -161,6 +161,6 @@ System.config({
161161
```
162162

163163

164-
## Example Angular Material projects
164+
### Example Angular Material projects
165165
- [material.angular.io](https://material.angular.io) -
166166
We build our own documentation with Angular Material!

guides/theming-your-components.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Theming your custom components
22
In order to style your own components with Angular Material's tooling, the component's styles must be defined with Sass.
33

4-
## Using `@mixin` to automatically apply a theme
4+
### Using `@mixin` to automatically apply a theme
55

6-
### Why using `@mixin`
6+
#### Why using `@mixin`
77
The advantage of using a `@mixin` function is that when you change your theme, every file that uses it will be updated automatically.
88
Calling it with a different theme argument allow multiple themes within the app or component.
99

10-
### How to use `@mixin`
10+
#### How to use `@mixin`
1111
We can better theming our custom components adding a `@mixin` function to its theme file and then calling this function to apply a theme.
1212

1313
All you need is to create a `@mixin` function in the custom-component-theme.scss
@@ -44,15 +44,15 @@ Now you just have to call the `@mixin` function to apply the theme:
4444
For more details about the theming functions, see the comments in the
4545
[source](https://github.com/angular/material2/blob/master/src/lib/core/theming/_theming.scss).
4646

47-
### Best practices using `@mixin`
47+
#### Best practices using `@mixin`
4848
When using `@mixin`, the theme file should only contain the definitions that are affected by the passed-in theme.
4949

5050
All styles that are not affected by the theme should be placed in a `candy-carousel.scss` file. This file should contain everything that is not affected by the theme like sizes, transitions...
5151

5252
Styles that are affected by the theme should be placed in a separated theming file as `_candy-carousel-theme.scss` and the file should have a `_` before the name. This file should contain the `@mixin` function responsible for applying the theme to the component.
5353

5454

55-
## Using colors from a palette
55+
### Using colors from a palette
5656
You can consume the theming functions and Material palette variables from `@angular/material/theming`.
5757
You can use the `mat-color` function to extract a specific color from a palette. For example:
5858

src/lib/autocomplete/autocomplete.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Then bind it to the autocomplete's `displayWith` property.
7878
<!-- example(autocomplete-display) -->
7979

8080

81-
#### Keyboard interaction:
81+
### Keyboard interaction
8282
- <kbd>DOWN_ARROW</kbd>: Next option becomes active.
8383
- <kbd>UP_ARROW</kbd>: Previous option becomes active.
8484
- <kbd>ENTER</kbd>: Select currently active item.

src/lib/select/select.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Here are the available global options:
7878
| --------------- | ------- | ------------------- | ----------------------------------------- |
7979
| float | string | auto, always, never | The default placeholder float behavior. |
8080

81-
#### Keyboard interaction:
81+
### Keyboard interaction
8282
- <kbd>DOWN_ARROW</kbd>: Focus next option
8383
- <kbd>UP_ARROW</kbd>: Focus previous option
8484
- <kbd>ENTER</kbd> or <kbd>SPACE</kbd>: Select focused item

src/lib/snack-bar/snack-bar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ snackbar.open('Message archived', 'Undo', {
4848
});
4949
```
5050

51-
### Sharing data with a custom snack-bar.
51+
### Sharing data with a custom snack-bar
5252
You can share data with the custom snack-bar, that you opened via the `openFromComponent` method,
5353
by passing it through the `data` property.
5454

src/material-examples/example-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {EXAMPLE_COMPONENTS} from './example-module';
77
*/
88
export class ExampleData {
99
// TODO: figure out how do we get these variables.
10-
description: string = 'Some description for material';
10+
description = 'Some description for material';
1111
// TODO: use real example and delete the example/ folder.
1212
examplePath = '/assets/example/';
1313
exampleFiles = ['button-demo.html', 'button-demo.scss', 'button-demo.ts'];

tools/gulp/tasks/docs.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,25 @@ task('docs', [
6969

7070
/** Generates html files from the markdown overviews and guides. */
7171
task('markdown-docs', () => {
72+
// Extend the renderer for custom heading anchor rendering
73+
markdown.marked.Renderer.prototype.heading = (text: string, level: number): string => {
74+
if (level === 3 || level === 4) {
75+
const escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
76+
return `
77+
<h${level} id="${escapedText}" class="docs-header-link">
78+
<div header-link="${escapedText}"></div>
79+
${text}
80+
</h${level}>
81+
`;
82+
} else {
83+
return `<h${level}>${text}</h${level}>`;
84+
}
85+
};
86+
7287
return src(['src/lib/**/*.md', 'src/cdk/**/*.md', 'guides/*.md'])
7388
.pipe(markdown({
7489
// Add syntax highlight using highlight.js
75-
highlight: (code: string, language: string) => {
90+
highlight: (code: string, language: string): string => {
7691
if (language) {
7792
// highlight.js expects "typescript" written out, while Github supports "ts".
7893
let lang = language.toLowerCase() === 'ts' ? 'typescript' : language;

0 commit comments

Comments
 (0)