@adobe/helix-html-pipeline 1.5.5 → 1.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/PipelineContent.d.ts +2 -2
- package/src/PipelineContent.js +2 -2
- package/src/utils/id-slugger.js +38 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.5.6](https://github.com/adobe/helix-html-pipeline/compare/v1.5.5...v1.5.6) (2022-05-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* avoid leading digits in heading ids ([#60](https://github.com/adobe/helix-html-pipeline/issues/60)) ([b2af7bf](https://github.com/adobe/helix-html-pipeline/commit/b2af7bf23f8479ba31c410d5b0a3316bbe071481)), closes [#59](https://github.com/adobe/helix-html-pipeline/issues/59)
|
|
7
|
+
|
|
1
8
|
## [1.5.5](https://github.com/adobe/helix-html-pipeline/compare/v1.5.4...v1.5.5) (2022-05-16)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/PipelineContent.d.ts
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import {Node} from "unist";
|
|
13
|
-
import GithubSlugger from 'github-slugger';
|
|
14
13
|
import { Root } from 'hast';
|
|
14
|
+
import { IDSlugger } from './utils/id-slugger.js';
|
|
15
15
|
|
|
16
16
|
declare enum SourceType {
|
|
17
17
|
CONTENT = 'content',
|
|
@@ -58,7 +58,7 @@ declare class PipelineContent {
|
|
|
58
58
|
/**
|
|
59
59
|
* slugger to use for heading id calculations
|
|
60
60
|
*/
|
|
61
|
-
slugger:
|
|
61
|
+
slugger: IDSlugger;
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* document specific metadata
|
package/src/PipelineContent.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import
|
|
12
|
+
import { IDSlugger } from './utils/id-slugger.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* State of the pipeline
|
|
@@ -22,7 +22,7 @@ export class PipelineContent {
|
|
|
22
22
|
constructor() {
|
|
23
23
|
Object.assign(this, {
|
|
24
24
|
sourceBus: 'content',
|
|
25
|
-
slugger: new
|
|
25
|
+
slugger: new IDSlugger(),
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import GithubSlugger from 'github-slugger';
|
|
13
|
+
|
|
14
|
+
export class IDSlugger {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.occurrences = {};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Generate a unique slug.
|
|
21
|
+
* @param {string} value String of text to slugify
|
|
22
|
+
* @return {string} A unique slug string
|
|
23
|
+
*/
|
|
24
|
+
slug(value) {
|
|
25
|
+
let id = GithubSlugger.slug(value)
|
|
26
|
+
// remove leading numbers
|
|
27
|
+
.replace(/^\d+-+/, '');
|
|
28
|
+
|
|
29
|
+
// resolve collisions
|
|
30
|
+
const original = id;
|
|
31
|
+
while (id in this.occurrences) {
|
|
32
|
+
this.occurrences[original] += 1;
|
|
33
|
+
id = `${original}-${this.occurrences[original]}`;
|
|
34
|
+
}
|
|
35
|
+
this.occurrences[id] = 0;
|
|
36
|
+
return id;
|
|
37
|
+
}
|
|
38
|
+
}
|