-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathnotes.js
More file actions
48 lines (41 loc) · 1.32 KB
/
notes.js
File metadata and controls
48 lines (41 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* This file is a part of @mdn/browser-compat-data
* See LICENSE file for more information. */
import { replaceCodeTagsWithBackticks } from '../utils.js';
import walk from '../../utils/walk.js';
/**
* @param {string | string[]} notes
* @returns {string | string[]}
*/
export const fixNotes = (notes) => {
if (Array.isArray(notes)) {
return notes.map(replaceCodeTagsWithBackticks);
}
return replaceCodeTagsWithBackticks(notes);
};
/**
* Fixes HTML in notes that should use Markdown syntax instead.
* @param {string} filename The filename containing compatibility info
* @param {string} actual The current content of the file
* @returns {string} expected content of the file
*/
const fixNotesFixer = (filename, actual) => {
if (filename.includes('/browsers/')) {
return actual;
}
const data = JSON.parse(actual);
const walker = walk(undefined, data);
for (const feature of walker) {
for (const support of Object.values(feature.compat.support)) {
for (const statement of Array.isArray(support) ? support : [support]) {
if (statement.notes) {
statement.notes =
/** @type {string | [string, string, ...string[]]} */ (
fixNotes(statement.notes)
);
}
}
}
}
return JSON.stringify(data, null, 2);
};
export default fixNotesFixer;