Skip to content

Commit a8fac4c

Browse files
SkyZeroZxAndrewKushnir
authored andcommitted
docs(docs-infra): Fix prefer/avoid rule matching with word boundaries
Improve code block rule detection by adding word-boundary anchors. Also update indentation for consistency.
1 parent 567172b commit a8fac4c

8 files changed

Lines changed: 61 additions & 60 deletions

File tree

adev/shared-docs/pipeline/shared/marked/extensions/docs-code/docs-code-block.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const docsCodeBlockExtension = {
4141
const headerRule = /header\s*:\s*(['"`])([^'"`]+)\1/; // The 2nd capture matters here
4242
const highlightRule = /highlight\s*:\s*(.*)([^,])/;
4343
const hideCopyRule = /hideCopy/;
44-
const preferRule = /(prefer|avoid)/;
44+
const preferRule = /\b(prefer|avoid)\b/;
4545
const linenumsRule = /linenums/;
4646

4747
const token: DocsCodeBlock = {

adev/shared-docs/pipeline/shared/marked/extensions/docs-code/docs-code.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const visibleLinesRule = /visibleLines="([^"]*)"/;
3232
const regionRule = /region="([^"]*)"/;
3333
const previewRule = /preview/;
3434
const hideCodeRule = /hideCode/;
35-
const preferRule = /(prefer|avoid)/;
35+
const preferRule = /\b(prefer|avoid)\b/;
3636

3737
export const docsCodeExtension = {
3838
name: 'docs-code',

adev/src/content/introduction/essentials/signal-forms.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ When a user selects a radio button, the form `field` stores the value from that
189189

190190
Select elements work with both static and dynamic options:
191191

192-
```html
192+
```angular-html
193193
<!-- Static options -->
194194
<select [field]="form.country">
195195
<option value="">Select a country</option>

adev/src/content/kitchen-sink.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ We also have styling for the terminal, just set the language as `shell`:
161161
npm install @angular/material --save
162162
```
163163

164+
You can style standard Markdown triple backticks with attributes for enhanced presentation:
165+
166+
```ts {header:"Awesome Title", linenums, highlight="[2]", hideCopy}
167+
console.log('Hello, World!');
168+
console.log('Awesome Angular Docs!');
169+
```
170+
164171
#### `<docs-code>` Attributes
165172

166173
| Attributes | Type | Details |

adev/src/content/tools/cli/aot-compiler.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ Use the non-null type assertion operator to suppress the `Object is possibly 'un
472472
In the following example, the `person` and `address` properties are always set together, implying that `address` is always non-null if `person` is non-null.
473473
There is no convenient way to describe this constraint to TypeScript and the template compiler, but the error is suppressed in the example by using `address!.street`.
474474

475-
```ts
475+
```angular-ts
476476
477477
@Component({
478478
selector: 'my-component',
@@ -494,7 +494,7 @@ The non-null assertion operator should be used sparingly as refactoring of the c
494494

495495
In this example it is recommended to include the checking of `address` in the `*ngIf` as shown below:
496496

497-
```ts
497+
```angular-ts
498498
499499
@Component({
500500
selector: 'my-component',

adev/src/content/tools/cli/schematics-for-libraries.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ When you add a schematic to the collection, you have to point to it in the colle
107107

108108
1. Edit the `schematics/collection.json` file to point to the new schematic subfolder, and include a pointer to a schema file that specifies inputs for the new schematic.
109109

110-
<docs-code header="projects/my-lib/schematics/collection.json (Schematics Collection)" path="adev/src/content/examples/schematics-for-libraries/projects/my-lib/schematics/collection.json"/>
110+
<docs-code header="projects/my-lib/schematics/collection.json (Schematics Collection)" path="adev/src/content/examples/schematics-for-libraries/projects/my-lib/schematics/collection.json"/>
111111

112112
1. Go to the `<lib-root>/schematics/my-service` folder.
113113
1. Create a `schema.json` file and define the available options for the schematic.
@@ -142,19 +142,20 @@ Schematic templates support special syntax to execute code and variable substitu
142142
1. Create a file named `__name@dasherize__.service.ts.template` that defines a template to use for generating files.
143143
This template will generate a service that already has Angular's `HttpClient` injected into an `http` property.
144144

145-
<docs-code lang="typescript" header="projects/my-lib/schematics/my-service/files/__name@dasherize__.service.ts.template (Schematic Template)">
145+
```ts {header:projects/my-lib/schematics/my-service/files/__name@dasherize__.service.ts.template (Schematic Template)}
146146

147147
import { Injectable } from '@angular/core';
148148
import { HttpClient } from '@angular/common/http';
149149

150150
@Injectable({
151-
providedIn: 'root'
151+
providedIn: 'root'
152152
})
153153
export class <%= classify(name) %>Service {
154-
private http = inject(HttpClient);
154+
private http = inject(HttpClient);
155155
}
156156

157-
</docs-code>
157+
```
158+
158159
- The `classify` and `dasherize` methods are utility functions that your schematic uses to transform your source template and filename.
159160
- The `name` is provided as a property from your factory function.
160161
It is the same `name` you defined in the schema.
@@ -173,15 +174,15 @@ For details of these data structures and syntax, see the [Schematics README](htt
173174
1. First, import the schematics definitions you will need.
174175
The Schematics framework offers many utility functions to create and use rules when running a schematic.
175176

176-
<docs-code header="projects/my-lib/schematics/my-service/index.ts (Imports)" path="adev/src/content/examples/schematics-for-libraries/projects/my-lib/schematics/my-service/index.ts" region="schematics-imports"/>
177+
<docs-code header="projects/my-lib/schematics/my-service/index.ts (Imports)" path="adev/src/content/examples/schematics-for-libraries/projects/my-lib/schematics/my-service/index.ts" region="schematics-imports"/>
177178

178179
1. Import the defined schema interface that provides the type information for your schematic's options.
179180

180-
<docs-code header="projects/my-lib/schematics/my-service/index.ts (Schema Import)" path="adev/src/content/examples/schematics-for-libraries/projects/my-lib/schematics/my-service/index.ts" region="schema-imports"/>
181+
<docs-code header="projects/my-lib/schematics/my-service/index.ts (Schema Import)" path="adev/src/content/examples/schematics-for-libraries/projects/my-lib/schematics/my-service/index.ts" region="schema-imports"/>
181182

182183
1. To build up the generation schematic, start with an empty rule factory.
183184

184-
<docs-code header="projects/my-lib/schematics/my-service/index.ts (Initial Rule)" path="adev/src/content/examples/schematics-for-libraries/projects/my-lib/schematics/my-service/index.1.ts" region="factory"/>
185+
<docs-code header="projects/my-lib/schematics/my-service/index.ts (Initial Rule)" path="adev/src/content/examples/schematics-for-libraries/projects/my-lib/schematics/my-service/index.1.ts" region="factory"/>
185186

186187
This rule factory returns the tree without modification.
187188
The options are the option values passed through from the `ng generate` command.

adev/src/content/tools/language-service.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,17 @@ Starting with TypeScript 2.3, TypeScript has a plug-in model that the language s
9191

9292
1. Install the latest version of TypeScript in a local `node_modules` directory:
9393

94-
```shell
95-
96-
npm install --save-dev typescript
97-
98-
```
94+
```shell
95+
npm install --save-dev typescript
96+
```
9997

10098
1. Install the Angular Language Service package in the same location:
10199

102-
```shell
100+
```shell
103101

104-
npm install --save-dev @angular/language-service
102+
npm install --save-dev @angular/language-service
105103

106-
```
104+
```
107105

108106
1. Once the package is installed, add the following to the `"compilerOptions"` section of your project's `tsconfig.json`.
109107

@@ -113,7 +111,7 @@ npm install --save-dev @angular/language-service
113111
]
114112
```
115113

116-
2. In your editor's user preferences \(`Cmd+,` or `Ctrl+,`\), add the following:
114+
1. In your editor's user preferences \(`Cmd+,` or `Ctrl+,`\), add the following:
117115

118116
```json {header:"Sublime Text user preferences"}
119117

adev/src/content/tools/libraries/using-libraries.md

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,24 @@ To do this:
4141

4242
1. Add the following code in `src/typings.d.ts`:
4343

44-
```ts
45-
declare module 'host' {
46-
export interface Host {
47-
protocol?: string;
48-
hostname?: string;
49-
pathname?: string;
50-
}
51-
export function parse(url: string, queryString?: string): Host;
52-
}
53-
54-
```
44+
```ts
45+
declare module 'host' {
46+
export interface Host {
47+
protocol?: string;
48+
hostname?: string;
49+
pathname?: string;
50+
}
51+
export function parse(url: string, queryString?: string): Host;
52+
}
53+
```
5554

5655
1. In the component or file that uses the library, add the following code:
5756

58-
```ts
59-
import * as host from 'host';
60-
const parsedUrl = host.parse('https://angular.dev');
61-
console.log(parsedUrl.hostname);
62-
63-
```
57+
```ts
58+
import * as host from 'host';
59+
const parsedUrl = host.parse('https://angular.dev');
60+
console.log(parsedUrl.hostname);
61+
```
6462

6563
Define more typings as needed.
6664

@@ -85,33 +83,30 @@ For example, to use the [Bootstrap 4][GetbootstrapDocs40GettingStartedIntroducti
8583

8684
1. Install the library and the associated dependencies using the npm package manager:
8785

88-
```shell
89-
npm install jquery --save
90-
npm install popper.js --save
91-
npm install bootstrap --save
92-
93-
```
86+
```shell
87+
npm install jquery --save
88+
npm install popper.js --save
89+
npm install bootstrap --save
90+
```
9491

9592
1. In the `angular.json` configuration file, add the associated script files to the `scripts` array:
9693

97-
```json
98-
"scripts": [
99-
"node_modules/jquery/dist/jquery.slim.js",
100-
"node_modules/popper.js/dist/umd/popper.js",
101-
"node_modules/bootstrap/dist/js/bootstrap.js"
102-
],
103-
104-
```
94+
```json
95+
"scripts": [
96+
"node_modules/jquery/dist/jquery.slim.js",
97+
"node_modules/popper.js/dist/umd/popper.js",
98+
"node_modules/bootstrap/dist/js/bootstrap.js"
99+
],
100+
```
105101

106102
1. Add the `bootstrap.css` CSS file to the `styles` array:
107103

108-
```json
109-
"styles": [
110-
"node_modules/bootstrap/dist/css/bootstrap.css",
111-
"src/styles.css"
112-
],
113-
114-
```
104+
```json
105+
"styles": [
106+
"node_modules/bootstrap/dist/css/bootstrap.css",
107+
"src/styles.css"
108+
],
109+
```
115110

116111
1. Run or restart the `ng serve` Angular CLI command to see Bootstrap 4 work in your application.
117112

0 commit comments

Comments
 (0)