Skip to content

Commit 3123b73

Browse files
Planeshifterkgrytestdlib-bot
authored
build: add remark plugin for validating HTML section structure
PR-URL: #6133 Ref: stdlib-js/metr-issue-tracker#49 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Co-authored-by: stdlib-bot <[email protected]>
1 parent 50b84b5 commit 3123b73

File tree

15 files changed

+1071
-0
lines changed

15 files changed

+1071
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# remark-lint-html-section-structure
22+
23+
> [remark][remark] plugin to lint HTML section structure in README files.
24+
25+
<section class="intro">
26+
27+
This plugin validates the HTML section structure in README files, ensuring that:
28+
29+
1. Each opening `<section>` tag has a corresponding `</section>` closing tag.
30+
2. Each opening `<section class="foo">` tag has a corresponding closing comment `<!-- /.foo -->`.
31+
3. There is an empty line between the closing `</section>` tag and the closing comment `<!-- /.foo -->`.
32+
33+
</section>
34+
35+
<!-- /.intro -->
36+
37+
<section class="usage">
38+
39+
## Usage
40+
41+
```javascript
42+
var sectionStructure = require( '@stdlib/_tools/remark/plugins/remark-lint-html-section-structure' );
43+
```
44+
45+
### sectionStructure()
46+
47+
Plugin to lint HTML section structure in README files.
48+
49+
```javascript
50+
var remark = require( 'remark' );
51+
52+
remark().use( sectionStructure );
53+
```
54+
55+
</section>
56+
57+
<!-- /.usage -->
58+
59+
<section class="examples">
60+
61+
## Examples
62+
63+
```javascript
64+
var remark = require( 'remark' );
65+
var report = require( 'vfile-reporter' );
66+
var sectionStructure = require( '@stdlib/_tools/remark/plugins/remark-lint-html-section-structure' );
67+
68+
// Create a markdown file with HTML sections:
69+
var markdown = [
70+
'# Title',
71+
'',
72+
'<section class="usage">',
73+
'',
74+
'## Usage',
75+
'',
76+
'```javascript',
77+
'var foo = require( \'foo\' );',
78+
'```',
79+
'',
80+
'</section>',
81+
'',
82+
'<!-- /.usge -->',
83+
''
84+
].join( '\n' );
85+
86+
// Lint using the plugin:
87+
remark()
88+
.use( sectionStructure )
89+
.process( markdown, onDone );
90+
91+
function onDone( error, file ) {
92+
if ( error ) {
93+
throw error;
94+
}
95+
console.log( report( file ) );
96+
}
97+
```
98+
99+
</section>
100+
101+
<!-- /.examples -->
102+
103+
<section class="links">
104+
105+
[remark]: https://github.com/remarkjs/remark
106+
107+
</section>
108+
109+
<!-- /.links -->
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var remark = require( 'remark' );
22+
var report = require( 'vfile-reporter' );
23+
var linter = require( './../lib' );
24+
25+
// Create a markdown file with both valid and invalid HTML sections:
26+
var markdown = [
27+
'# Title',
28+
'',
29+
'<section class="usage">',
30+
'',
31+
'## Usage',
32+
'',
33+
'```javascript',
34+
'var foo = require( \'foo\' );',
35+
'```',
36+
'',
37+
'</section>',
38+
'',
39+
'<!-- /.usge -->'
40+
].join( '\n' );
41+
42+
// Lint using the plugin:
43+
remark()
44+
.use( linter )
45+
.process( markdown, done );
46+
47+
/**
48+
* Callback invoked upon processing a Markdown file.
49+
*
50+
* @private
51+
* @param {Error|null} error - error object
52+
* @param {VFile} file - virtual file
53+
*/
54+
function done( error, file ) {
55+
if ( error ) {
56+
throw error;
57+
}
58+
console.log( report( file ) );
59+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/**
22+
* remark lint plugin for validating HTML section structure in README files.
23+
*
24+
* @module @stdlib/_tools/remark/plugins/remark-lint-html-section-structure
25+
*
26+
* @example
27+
* var remark = require( 'remark' );
28+
* var lint = require( '@stdlib/_tools/remark/plugins/remark-lint-html-section-structure' );
29+
*
30+
* var str = '# Title\n\n<section class="usage">\n\n## Usage\n\n</section><!-- /.usage -->';
31+
*
32+
* function done( error, file ) {
33+
* var i;
34+
* if ( error ) {
35+
* throw error;
36+
* }
37+
* for ( i = 0; i < file.messages.length; i++ ) {
38+
* console.error( file.messages[ i ].message );
39+
* }
40+
* }
41+
*/
42+
43+
// MODULES //
44+
45+
var main = require( './main.js' );
46+
47+
48+
// EXPORTS //
49+
50+
module.exports = main;

0 commit comments

Comments
 (0)