@@ -198,17 +198,30 @@ const mdcRemarkHandlers: Record<string, (state: State, node: Parents, parent: Pa
198198 children : state . toFlow ( state . all ( node ) ) ,
199199 }
200200 } ,
201+ 'li' : ( state : State , node : Parents ) => {
202+ const result = defaultHandlers . li ( state , node as Element )
203+
204+ if ( result . children [ 0 ] ?. type === 'paragraph' ) {
205+ const paragraph = result . children [ 0 ] !
206+ const lastChild = paragraph . children [ paragraph . children . length - 1 ] as Text
207+ if ( lastChild ?. type === 'text' && lastChild . value ?. endsWith ( '\n' ) ) {
208+ lastChild . value = lastChild . value . trim ( )
209+ }
210+ }
211+
212+ return result
213+ } ,
201214 'ul' : ( state : State , node : Parents , parent : Parents | undefined ) => {
202215 const result = defaultHandlers . ul ( state , node as Element )
203216
204- return parent ?. tagName === 'p'
217+ return [ 'p' , 'li' ] . includes ( parent ?. tagName || '' )
205218 ? result
206219 : { type : 'paragraph' , children : [ result ] }
207220 } ,
208221 'ol' : ( state : State , node : Parents , parent : Parents | undefined ) => {
209222 const result = defaultHandlers . ol ( state , node as Element )
210223
211- return parent ?. tagName === 'p'
224+ return [ 'p' , 'li' ] . includes ( parent ?. tagName || '' )
212225 ? result
213226 : { type : 'paragraph' , children : [ result ] }
214227 } ,
0 commit comments