@markuplint/spec-generator 4.7.0 → 4.8.1
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 +18 -0
- package/lib/html-elements.js +7 -4
- package/lib/scraping.d.ts +0 -1
- package/lib/scraping.js +17 -33
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.8.1](https://github.com/markuplint/markuplint/compare/@markuplint/spec-generator@4.8.0...@markuplint/spec-generator@4.8.1) (2025-11-05)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @markuplint/spec-generator
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [4.8.0](https://github.com/markuplint/markuplint/compare/@markuplint/spec-generator@4.7.0...@markuplint/spec-generator@4.8.0) (2025-08-24)
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
- **spec-generator:** remove debug log ([a00691b](https://github.com/markuplint/markuplint/commit/a00691bc9874ba6a8adb5bf6217e7d6c79959660))
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
- **spec-generator:** update MDN scraping logic ([45889a9](https://github.com/markuplint/markuplint/commit/45889a9a308c48ccd43df6837463d0ecabd547a8))
|
|
23
|
+
|
|
6
24
|
# [4.7.0](https://github.com/markuplint/markuplint/compare/@markuplint/spec-generator@4.6.19...@markuplint/spec-generator@4.7.0) (2025-08-13)
|
|
7
25
|
|
|
8
26
|
### Bug Fixes
|
package/lib/html-elements.js
CHANGED
|
@@ -50,13 +50,16 @@ export async function getElements(filePattern) {
|
|
|
50
50
|
specs.push(...obsoleteElements);
|
|
51
51
|
specs = await Promise.all(specs.map(async (el) => {
|
|
52
52
|
const { localName, namespace, ml } = getName(el.name);
|
|
53
|
-
const
|
|
53
|
+
const urlTagName = /^h[1-6]$/i.test(localName) ? 'Heading_Elements' : localName;
|
|
54
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a
|
|
55
|
+
// https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/a
|
|
56
|
+
const cite = `https://developer.mozilla.org/en-US/docs/Web/${ml}/Reference/Element${ml === 'HTML' ? 's' : ''}/${urlTagName}`;
|
|
54
57
|
const mdnData = await fetchHTMLElement(cite);
|
|
55
58
|
// @ts-ignore
|
|
56
59
|
delete el.name;
|
|
57
60
|
// @ts-ignore
|
|
58
61
|
delete el.namespace;
|
|
59
|
-
|
|
62
|
+
const spec = {
|
|
60
63
|
// @ts-ignore
|
|
61
64
|
name: namespace === 'http://www.w3.org/2000/svg' ? `svg:${localName}` : localName,
|
|
62
65
|
namespace,
|
|
@@ -99,9 +102,9 @@ export async function getElements(filePattern) {
|
|
|
99
102
|
return attrs;
|
|
100
103
|
})()),
|
|
101
104
|
};
|
|
105
|
+
return spec;
|
|
102
106
|
}));
|
|
103
107
|
return specs
|
|
104
108
|
.sort(nameCompare)
|
|
105
|
-
.sort((a, b) => (a.namespace == b.namespace ? 0 : a.namespace === 'http://www.w3.org/2000/svg' ? 1 : -1))
|
|
106
|
-
.filter(spec => spec.name !== 'h1-h6');
|
|
109
|
+
.sort((a, b) => (a.namespace == b.namespace ? 0 : a.namespace === 'http://www.w3.org/2000/svg' ? 1 : -1));
|
|
107
110
|
}
|
package/lib/scraping.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ExtendedElementSpec } from '@markuplint/ml-spec';
|
|
2
|
-
export declare function fetchHTMLElementLinks(): Promise<string[]>;
|
|
3
2
|
export declare function fetchObsoleteElements(obsoleteList: readonly string[], specs: readonly ExtendedElementSpec[]): ExtendedElementSpec[];
|
|
4
3
|
export declare function fetchHTMLElement(link: string): Promise<ExtendedElementSpec>;
|
package/lib/scraping.js
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
import { fetch } from './fetch.js';
|
|
2
|
-
import {
|
|
3
|
-
const MAIN_ARTICLE_SELECTOR = '
|
|
4
|
-
export async function fetchHTMLElementLinks() {
|
|
5
|
-
const $ = await fetch('https://developer.mozilla.org/en-US/docs/Web/HTML/Element');
|
|
6
|
-
const $listHeading = $($('#sidebar-quicklinks summary')
|
|
7
|
-
.toArray()
|
|
8
|
-
.find(el => /html elements/i.test($(el).text())));
|
|
9
|
-
const $list = $listHeading.siblings('ol,ul');
|
|
10
|
-
const lists = $list
|
|
11
|
-
.find('li a')
|
|
12
|
-
.toArray()
|
|
13
|
-
.map(el => `https://developer.mozilla.org${$(el).attr('href')}`);
|
|
14
|
-
return lists;
|
|
15
|
-
}
|
|
2
|
+
import { sortObjectByKey } from './utils.js';
|
|
3
|
+
const MAIN_ARTICLE_SELECTOR = 'main#content';
|
|
16
4
|
export function fetchObsoleteElements(obsoleteList, specs) {
|
|
17
5
|
return obsoleteList
|
|
18
6
|
.map(name => {
|
|
@@ -41,16 +29,13 @@ export function fetchObsoleteElements(obsoleteList, specs) {
|
|
|
41
29
|
}
|
|
42
30
|
export async function fetchHTMLElement(link) {
|
|
43
31
|
const $ = await fetch(link);
|
|
44
|
-
|
|
45
|
-
if (name === 'heading_elements') {
|
|
46
|
-
name = 'h1-h6';
|
|
47
|
-
}
|
|
32
|
+
const name = link.replace(/.+\/([\w-]+)$/, '$1').toLowerCase();
|
|
48
33
|
const $article = $(MAIN_ARTICLE_SELECTOR);
|
|
49
|
-
$article
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
const description = $article
|
|
35
|
+
.find('.reference-layout__header .content-section')
|
|
36
|
+
.text()
|
|
37
|
+
.trim()
|
|
38
|
+
.replaceAll(/\s+/g, ' ');
|
|
54
39
|
const $bcTable = $article.find('.bc-table');
|
|
55
40
|
const $bcTableFirstRow = $bcTable.find('tbody tr:first-child th');
|
|
56
41
|
const isBcTableIsAvailable = $bcTableFirstRow.find('code').text().trim() === name;
|
|
@@ -98,11 +83,11 @@ export async function fetchHTMLElement(link) {
|
|
|
98
83
|
categories.push('#palpable');
|
|
99
84
|
if (/script-supporting/i.test(cat))
|
|
100
85
|
categories.push('#script-supporting');
|
|
101
|
-
let { attributes } = getAttributes($, '
|
|
102
|
-
const { attributes: deprecatedAttributes } = getAttributes($, '
|
|
103
|
-
const { attributes: individualAttributes } = getAttributes($, '
|
|
104
|
-
const { attributes: nonStandardAttributes } = getAttributes($, '
|
|
105
|
-
const { attributes: obsoleteAttributes } = getAttributes($, '
|
|
86
|
+
let { attributes } = getAttributes($, 'attributes');
|
|
87
|
+
const { attributes: deprecatedAttributes } = getAttributes($, 'deprecated_attributes');
|
|
88
|
+
const { attributes: individualAttributes } = getAttributes($, 'individual_attributes');
|
|
89
|
+
const { attributes: nonStandardAttributes } = getAttributes($, 'non-standard_attributes');
|
|
90
|
+
const { attributes: obsoleteAttributes } = getAttributes($, 'obsolete_attributes');
|
|
106
91
|
attributes = sortObjectByKey({
|
|
107
92
|
...attributes,
|
|
108
93
|
...deprecatedAttributes,
|
|
@@ -134,7 +119,7 @@ export async function fetchHTMLElement(link) {
|
|
|
134
119
|
function getProperty(
|
|
135
120
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
136
121
|
$, prop) {
|
|
137
|
-
const $tr = $(
|
|
122
|
+
const $tr = $('#technical_summary ~ figure.table-container > table tr');
|
|
138
123
|
const $th = $($tr
|
|
139
124
|
.find('th')
|
|
140
125
|
.toArray()
|
|
@@ -143,11 +128,10 @@ $, prop) {
|
|
|
143
128
|
}
|
|
144
129
|
function getAttributes(
|
|
145
130
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
146
|
-
$,
|
|
147
|
-
const $
|
|
148
|
-
const $outline = getThisOutline($, $heading);
|
|
131
|
+
$, id) {
|
|
132
|
+
const $section = $(`.content-section[aria-labelledby="${id}"]`);
|
|
149
133
|
const attributes = {};
|
|
150
|
-
for (const dt of $
|
|
134
|
+
for (const dt of $section.find('> dl > dt').toArray()) {
|
|
151
135
|
const $dt = $(dt);
|
|
152
136
|
const name = $dt.find('code').text().trim();
|
|
153
137
|
if (!name) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/spec-generator",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.1",
|
|
4
4
|
"description": "Generates @markuplint/html-spec",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"strip-json-comments": "5.0.3"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@markuplint/ml-spec": "4.
|
|
34
|
-
"@markuplint/test-tools": "4.5.
|
|
33
|
+
"@markuplint/ml-spec": "4.10.1",
|
|
34
|
+
"@markuplint/test-tools": "4.5.22",
|
|
35
35
|
"@types/cli-progress": "3.11.6",
|
|
36
36
|
"type-fest": "4.41.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "6213ea30269ef404f030e67bbcc7fc7443ec1060"
|
|
39
39
|
}
|