Skip to content

Commit 0015ff1

Browse files
authored
HTML Rewriter (#1193)
1 parent f42ff90 commit 0015ff1

39 files changed

+3949
-2
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# after
9+
10+
The `after` method inserts content after the closing tag of the element.
11+
12+
## Syntax
13+
14+
```js
15+
element.after(content);
16+
element.after(content, options);
17+
```
18+
19+
### Parameters
20+
21+
- `content` _: string_
22+
- The content to insert after the element's closing tag.
23+
24+
- `options` _: ElementRewriterOptions_
25+
- An optional object that can have the following properties:
26+
- `escapeHTML` _: boolean_
27+
- If `true`, any HTML markup in `content` will be escaped so it is safe to insert as text.
28+
29+
### Examples
30+
31+
```js
32+
// Assuming `e` is an Element representing <div>Hello</div>
33+
e.after("World");
34+
// Result: <div>Hello</div>World
35+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# append
9+
10+
The `append` method inserts content at the end of the element's content.
11+
12+
## Syntax
13+
14+
```js
15+
element.append(content);
16+
element.append(content, options);
17+
```
18+
19+
### Parameters
20+
21+
- `content` _: string_
22+
- The content to insert at the end of the element's content.
23+
24+
- `options` _: ElementRewriterOptions_
25+
- An optional object that can have the following properties:
26+
- `escapeHTML` _: boolean_
27+
- If `true`, any HTML markup in `content` will be escaped so it is safe to insert as text.
28+
29+
### Examples
30+
31+
```js
32+
// Assuming `e` is an Element representing <div>Hello</div>
33+
e.append(", World");
34+
// Result: <div>Hello, World</div>
35+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# before
9+
10+
The `before` method inserts content before the opening tag of the element.
11+
12+
## Syntax
13+
14+
```js
15+
element.before(content);
16+
element.before(content, options);
17+
```
18+
19+
### Parameters
20+
21+
- `content` _: string_
22+
- The content to insert before the element's opening tag.
23+
24+
- `options` _: ElementRewriterOptions_
25+
- An optional object that can have the following properties:
26+
- `escapeHTML` _: boolean_
27+
- If `true`, any HTML markup in `content` will be escaped so it is safe to insert as text.
28+
29+
### Examples
30+
31+
```js
32+
// Assuming `e` is an Element representing <div>Hello</div>
33+
e.before("Well");
34+
// Result: Well<div>Hello</div>
35+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# hasAttribute
9+
10+
The `hasAttribute` method returns a `boolean` value indicating whether the specified attribute is present on the element.
11+
12+
## Syntax
13+
14+
```js
15+
element.hasAttribute(attributeName);
16+
```
17+
18+
### Parameters
19+
20+
- `attributeName` _: string_
21+
- The name of the attribute to check for.
22+
23+
### Return value
24+
25+
A boolean value indicating whether the attribute is present.
26+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# prepend
9+
10+
The `prepend` method inserts content at the beginning of the element's content.
11+
12+
## Syntax
13+
14+
```js
15+
element.prepend(content);
16+
element.prepend(content, options);
17+
```
18+
19+
### Parameters
20+
21+
- `content` _: string_
22+
- The content to insert at the beginning of the element's content.
23+
24+
- `options` _: ElementRewriterOptions_
25+
- An optional object that can have the following properties:
26+
- `escapeHTML` _: boolean_
27+
- If `true`, any HTML markup in `content` will be escaped so it is safe to insert as text.
28+
29+
### Examples
30+
31+
```js
32+
// Assuming `e` is an Element representing <div>Hello</div>
33+
e.prepend("Well, ");
34+
// Result: <div>Well, Hello</div>
35+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# removeAttribute
9+
10+
The `removeAttribute` method removes the specified attribute from the element.
11+
12+
## Syntax
13+
14+
```js
15+
element.removeAttribute(attributeName);
16+
```
17+
18+
### Parameters
19+
20+
- `attributeName` _: string_
21+
- The name of the attribute to remove.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# replaceChildren
9+
10+
The `replaceChildren` method replaces the element's children with new content.
11+
12+
## Syntax
13+
14+
```js
15+
element.replaceChildren(content);
16+
element.replaceChildren(content, options);
17+
```
18+
19+
### Parameters
20+
21+
- `content` _: string_
22+
- The content to replace the element's children with.
23+
24+
- `options` _: ElementRewriterOptions_
25+
- An optional object that can have the following properties:
26+
- `escapeHTML` _: boolean_
27+
- If `true`, any HTML markup in `content` will be escaped so it is safe to insert as text.
28+
29+
### Examples
30+
31+
```js
32+
// Assuming `e` is an Element representing <div>Hello</div>
33+
e.replaceChildren("Greetings!");
34+
// Result: <div>Greetings!</div>
35+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# replaceWith
9+
10+
The `replaceWith` method replaces the element with new content.
11+
12+
## Syntax
13+
14+
```js
15+
element.replaceWith(content);
16+
element.replaceWith(content, options);
17+
```
18+
19+
### Parameters
20+
21+
- `content` _: string_
22+
- The content to replace the element with.
23+
24+
- `options` _: ElementRewriterOptions_
25+
- An optional object that can have the following properties:
26+
- `escapeHTML` _: boolean_
27+
- If `true`, any HTML markup in `content` will be escaped so it is safe to insert as text.
28+
29+
### Examples
30+
31+
```js
32+
// Assuming `e` is an Element representing <div>Hello</div>
33+
e.replaceWith("<p>Greetings!</p>");
34+
// Result: <p>Greetings!</p>
35+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# selector
9+
10+
The `selector` read-only property is a `string` representing the [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors) that matches the element.
11+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# setAttribute
9+
10+
The `setAttribute` method sets the value of the specified attribute on the element. If the value already exists, it will be updated; otherwise, a new attribute with the specified name and value will be added to the element.
11+
12+
## Syntax
13+
14+
```js
15+
element.setAttribute(attributeName, value);
16+
```
17+
18+
### Parameters
19+
20+
- `attributeName` _: string_
21+
- The name of the attribute to set.
22+
- `value` _: string_
23+
- The value to assign to the attribute.
24+

0 commit comments

Comments
 (0)