@@ -5,7 +5,7 @@ import { useSlotText } from '@/utils/vnode'
55import MarkdowView , {
66 preprocessCustomRawComponents ,
77 preprocessIncompleteTags ,
8- preprocessInlineComponents
8+ preprocessSelfClosingComponents
99} from './MarkdownView'
1010
1111describe ( 'preprocessCustomRawComponents' , ( ) => {
@@ -102,60 +102,61 @@ describe('preprocessCustomRawComponents', () => {
102102 } )
103103} )
104104
105- describe ( 'preprocessInlineComponents' , ( ) => {
106- it ( 'should separate self-closing tag from next line text with blank line' , ( ) => {
107- const value = '<x-comp />\nHello world'
108- const tagNames = [ 'x-comp' ]
109- const result = preprocessInlineComponents ( value , tagNames )
110- expect ( result ) . toBe ( '<x-comp />\n\nHello world' )
111- } )
112- it ( 'should separate self-closing tag from next line text with blank line with attributes' , ( ) => {
113- const value = '<x-comp some="foo" />\nHello world'
114- const tagNames = [ 'x-comp' ]
115- const result = preprocessInlineComponents ( value , tagNames )
116- expect ( result ) . toBe ( '<x-comp some="foo" />\n\nHello world' )
117- } )
118- it ( 'should preserve leading spaces of next line' , ( ) => {
119- const value = '<x-comp />\n Hello'
120- const tagNames = [ 'x-comp' ]
121- const result = preprocessInlineComponents ( value , tagNames )
122- expect ( result ) . toBe ( '<x-comp />\n\n Hello' )
123- } )
124- it ( 'should ignore when there is a blank line' , ( ) => {
125- const value = '<x-comp />\n\nHello'
126- const tagNames = [ 'x-comp' ]
127- const result = preprocessInlineComponents ( value , tagNames )
128- expect ( result ) . toBe ( '<x-comp />\n\nHello' )
129- } )
130- it ( 'should not change when inline already' , ( ) => {
131- const value = '<x-comp />Hello\nWorld'
132- const tagNames = [ 'x-comp' ]
133- const result = preprocessInlineComponents ( value , tagNames )
134- expect ( result ) . toBe ( '<x-comp />Hello\nWorld' )
135- } )
136- it ( 'should match spaces before newline' , ( ) => {
137- const value = '<x-comp /> \nHello'
138- const tagNames = [ 'x-comp' ]
139- const result = preprocessInlineComponents ( value , tagNames )
140- expect ( result ) . toBe ( '<x-comp /> \n\nHello' )
141- } )
142- it ( 'should not change when not self-closing' , ( ) => {
143- const value = '<x-comp></x-comp>\nHello'
144- const tagNames = [ 'x-comp' ]
145- const result = preprocessInlineComponents ( value , tagNames )
146- expect ( result ) . toBe ( '<x-comp></x-comp>\nHello' )
147- } )
148- it ( 'should separate even when a self-closing tag is preceded by text' , ( ) => {
149- const value = 'before<x-comp />\nHello'
150- const tagNames = [ 'x-comp' ]
151- const result = preprocessInlineComponents ( value , tagNames )
152- expect ( result ) . toBe ( 'before<x-comp />\n\nHello' )
153- } )
154- it ( 'should insert a blank line before an inline component when preceded by text' , ( ) => {
155- const value = '<x-comp />\n<x-comp />\nHello\n<x-comp />'
156- const tagNames = [ 'x-comp' ]
157- const result = preprocessInlineComponents ( value , tagNames )
158- expect ( result ) . toBe ( '<x-comp />\n\n<x-comp />\n\nHello\n<x-comp />' )
105+ describe ( 'preprocessSelfClosingComponents' , ( ) => {
106+ it ( 'should convert self-closing tags to opening and closing tags' , ( ) => {
107+ const value = '<custom-component />'
108+ const tagNames = [ 'custom-component' ]
109+ const result = preprocessSelfClosingComponents ( value , tagNames )
110+ expect ( result ) . toBe ( '<custom-component></custom-component>' )
111+ } )
112+
113+ it ( 'should handle attributes' , ( ) => {
114+ const value = '<custom-component attr="value" />'
115+ const tagNames = [ 'custom-component' ]
116+ const result = preprocessSelfClosingComponents ( value , tagNames )
117+ expect ( result ) . toBe ( '<custom-component attr="value"></custom-component>' )
118+ } )
119+
120+ it ( 'should handle multiple attributes' , ( ) => {
121+ const value = '<custom-component attr1="value1" attr2="value2" />'
122+ const tagNames = [ 'custom-component' ]
123+ const result = preprocessSelfClosingComponents ( value , tagNames )
124+ expect ( result ) . toBe ( '<custom-component attr1="value1" attr2="value2"></custom-component>' )
125+ } )
126+
127+ it ( 'should handle spaces before closing slash' , ( ) => {
128+ const value = '<custom-component />'
129+ const tagNames = [ 'custom-component' ]
130+ const result = preprocessSelfClosingComponents ( value , tagNames )
131+ expect ( result ) . toBe ( '<custom-component></custom-component>' )
132+ } )
133+
134+ it ( 'should handle multiple occurrences' , ( ) => {
135+ const value = '<custom-component /> <custom-component />'
136+ const tagNames = [ 'custom-component' ]
137+ const result = preprocessSelfClosingComponents ( value , tagNames )
138+ expect ( result ) . toBe ( '<custom-component></custom-component> <custom-component></custom-component>' )
139+ } )
140+
141+ it ( 'should not affect other tags' , ( ) => {
142+ const value = '<other-component />'
143+ const tagNames = [ 'custom-component' ]
144+ const result = preprocessSelfClosingComponents ( value , tagNames )
145+ expect ( result ) . toBe ( '<other-component />' )
146+ } )
147+
148+ it ( 'should handle empty value' , ( ) => {
149+ const value = ''
150+ const tagNames = [ 'custom-component' ]
151+ const result = preprocessSelfClosingComponents ( value , tagNames )
152+ expect ( result ) . toBe ( '' )
153+ } )
154+
155+ it ( 'should handle no tag names' , ( ) => {
156+ const value = '<custom-component />'
157+ const tagNames : string [ ] = [ ]
158+ const result = preprocessSelfClosingComponents ( value , tagNames )
159+ expect ( result ) . toBe ( '<custom-component />' )
159160 } )
160161} )
161162
@@ -331,7 +332,7 @@ After`,
331332 } )
332333 }
333334 } )
334- expect ( result ) . toBe ( '<div><p>Before<div class="test-comp-1">hello world</div></p>\n<p>After </p></div>' )
335+ expect ( result ) . toBe ( '<div><p>Before<div class="test-comp-1">hello world</div>\nAfter </p></div>' )
335336 } )
336337 it ( 'should handle a custom self-closing tag when text follows immediately on the next line' , async ( ) => {
337338 const testComp1 = {
0 commit comments