@@ -6,6 +6,12 @@ import YAML from 'yaml';
66import { FeatureData } from './types' ;
77import { Temporal } from '@js-temporal/polyfill' ;
88
9+ import { toString as hastTreeToString } from 'hast-util-to-string' ;
10+ import rehypeStringify from 'rehype-stringify' ;
11+ import remarkParse from 'remark-parse' ;
12+ import remarkRehype from 'remark-rehype' ;
13+ import { unified } from 'unified' ;
14+
915import { BASELINE_LOW_TO_HIGH_DURATION } from 'compute-baseline' ;
1016
1117// The longest description allowed, to avoid them growing into documentation.
@@ -15,6 +21,7 @@ const descriptionMaxLength = 300;
1521// They're not part of the public schema (yet).
1622const omittables = [
1723 "description" ,
24+ "description_html" ,
1825 "snapshot" ,
1926 "group"
2027]
@@ -87,8 +94,30 @@ function* identifiers(value) {
8794 }
8895}
8996
97+ function convertMarkdown ( markdown : string ) {
98+ const mdTree = unified ( ) . use ( remarkParse ) . parse ( markdown ) ;
99+ const htmlTree = unified ( ) . use ( remarkRehype ) . runSync ( mdTree ) ;
100+ const text = hastTreeToString ( htmlTree ) ;
101+
102+ let html = unified ( ) . use ( rehypeStringify ) . stringify ( htmlTree ) ;
103+ // Remove leading <p> and trailing </p> if there is only one of each in the
104+ // description. (If there are multiple paragraphs, let them be.)
105+ if ( html . lastIndexOf ( '<p>' ) === 0 && html . indexOf ( '</p>' ) === html . length - 4 ) {
106+ html = html . substring ( 3 , html . length - 4 ) ;
107+ }
108+
109+ return { text, html } ;
110+ }
111+
90112const features : { [ key : string ] : FeatureData } = { } ;
91113for ( const [ key , data ] of yamlEntries ( 'feature-group-definitions' ) ) {
114+ // Convert markdown to text+HTML.
115+ if ( data . description ) {
116+ const { text, html } = convertMarkdown ( data . description ) ;
117+ data . description = text ;
118+ data . description_html = html ;
119+ }
120+
92121 // Compute Baseline high date from low date.
93122 const isDist = fs . existsSync ( `feature-group-definitions/${ key } .dist.yml` ) ;
94123 if ( ! isDist && data . status ?. baseline_high_date ) {
0 commit comments