11import { toJS , fromJS } from '@putout/operator-json' ;
22import stringify from 'remark-stringify' ;
33import preset from 'remark-preset-lint-consistent' ;
4+ import remarkFrontmatter from 'remark-frontmatter' ;
45import { visit } from 'unist-util-visit' ;
56import { unified } from 'unified' ;
7+ import remarkParse from 'remark-parse' ;
68import removeDependenciesStatusBadge from './rules/remove-dependencies-status-badge.js' ;
79import removeTrailingWhitespacesFromHeading from './rules/remove-trailing-whitespaces-from-heading.js' ;
810import mergeHeadingSpceces from './rules/merge-heading-spaces.js' ;
911import { run } from './rules/index.js' ;
1012import { toPlace } from './parse-place.js' ;
11- import { initParseStore } from './parse-store.js' ;
1213
1314const plugins = [
1415 removeDependenciesStatusBadge ,
1516 removeTrailingWhitespacesFromHeading ,
1617 mergeHeadingSpceces ,
1718] ;
1819
19- const parseStore = initParseStore ( ) ;
20-
2120const text = ( { value} ) => value ;
2221
2322const stringifyOptions = {
@@ -32,13 +31,11 @@ const stringifyOptions = {
3231
3332export const files = [ '*.md' ] ;
3433export const find = async ( rawSource , options = { } ) => {
35- await parseStore . init ( ) ;
36-
3734 if ( ! rawSource . length )
3835 return [ ] ;
3936
4037 const { messages} = await unified ( )
41- . use ( parseStore )
38+ . use ( remarkParse )
4239 . use ( preset )
4340 . use ( run , {
4441 fix : false ,
@@ -48,24 +45,24 @@ export const find = async (rawSource, options = {}) => {
4845 ] ,
4946 } )
5047 . use ( stringify , stringifyOptions )
48+ . use ( remarkFrontmatter , [ 'yaml' , 'toml' ] )
5149 . process ( rawSource ) ;
5250
5351 return messages . map ( toPlace ) ;
5452} ;
5553export const fix = async ( rawSource , options = { } ) => {
56- await parseStore . init ( ) ;
57-
5854 const { value} = await unified ( )
59- . use ( parseStore )
55+ . use ( remarkParse )
6056 . use ( preset )
57+ . use ( stringify , stringifyOptions )
58+ . use ( remarkFrontmatter , [ 'yaml' , 'toml' ] )
6159 . use ( run , {
6260 fix : true ,
6361 plugins : [
6462 ...plugins ,
6563 ...options . plugins || [ ] ,
6664 ] ,
6765 } )
68- . use ( stringify , stringifyOptions )
6966 . process ( rawSource ) ;
7067
7168 return value ;
@@ -74,7 +71,7 @@ export const branch = async (rawSource) => {
7471 const list = [ ] ;
7572
7673 await unified ( )
77- . use ( parseStore )
74+ . use ( remarkParse )
7875 . use ( collect , {
7976 list,
8077 visit,
@@ -88,7 +85,7 @@ export const merge = async (rawSource, list) => {
8885 const newList = list . slice ( ) ;
8986
9087 const { value} = await unified ( )
91- . use ( parseStore )
88+ . use ( remarkParse )
9289 . use ( apply , {
9390 list : newList ,
9491 rawSource,
@@ -97,15 +94,12 @@ export const merge = async (rawSource, list) => {
9794 . use ( stringify , stringifyOptions )
9895 . process ( rawSource ) ;
9996
100- await parseStore . clear ( ) ;
101-
10297 return value ;
10398} ;
10499
105100const collect = ( { list, visit} ) => ( node ) => {
106101 visit ( node , 'code' , ( node ) => {
107102 const { lang, value} = node ;
108-
109103 const startLine = node . position . start . line ;
110104
111105 if ( / ^ ( j s | j a v a s c r i p t ) $ / . test ( lang ) ) {
0 commit comments