11const { List } = require ( 'immutable' ) ;
2+ const warning = require ( 'warning' ) ;
23const trimTrailingLines = require ( 'trim-trailing-lines' ) ;
3- const { Serializer, Deserializer, Block } = require ( '../../' ) ;
4+ const { Serializer, Deserializer, Block, BLOCKS } = require ( '../../' ) ;
45const reBlock = require ( '../re/block' ) ;
56const liquid = require ( '../liquid' ) ;
67
8+
79/**
810 * Return true if a block type is a custom one.
911 * @param {String } tag
@@ -49,6 +51,18 @@ function isClosingTagFor(tag, forTag) {
4951 return tag . indexOf ( `end${ forTag } ` ) === 0 ;
5052}
5153
54+ /**
55+ * Wrap the given nodes in the default block
56+ * @param {Array<Node> } nodes
57+ * @return {Block }
58+ */
59+ function wrapInDefaultBlock ( nodes ) {
60+ return Block . create ( {
61+ type : BLOCKS . DEFAULT ,
62+ nodes
63+ } ) ;
64+ }
65+
5266/**
5367 * Serialize a templating block to markdown
5468 * @type {Serializer }
@@ -64,24 +78,41 @@ const serialize = Serializer()
6478 data
6579 } ) ;
6680
67- const unendingTags = state . getProp ( 'unendingTags' ) || List ( ) ;
68- const endTag =
69- unendingTags . includes ( getTagFromCustomType ( node . type ) )
70- ? ''
71- : liquid . stringifyTag ( {
72- tag : 'end' + getTagFromCustomType ( node . type )
73- } ) ;
74-
7581 const split = node . object == 'block' ? '\n' : '' ;
7682 const end = node . object == 'block' ? '\n\n' : '' ;
7783
78- if ( node . isVoid ) {
84+ if ( node . isVoid || node . nodes . isEmpty ( ) ) {
85+ warning (
86+ node . isVoid ,
87+ 'Encountered a non-void custom block with no children'
88+ ) ;
89+
7990 return state
8091 . shift ( )
8192 . write ( `${ startTag } ${ end } ` ) ;
8293 }
8394
84- const inner = trimTrailingLines ( state . serialize ( node . nodes ) ) ;
95+ const containsInline = node . nodes . first ( ) . object !== 'block' ;
96+ warning (
97+ ! containsInline ,
98+ 'Encountered a custom block containing inlines'
99+ ) ;
100+
101+ const innerNodes = containsInline
102+ ? List ( [ wrapInDefaultBlock ( node . nodes ) ] )
103+ : node . nodes ;
104+
105+ const inner = trimTrailingLines (
106+ state . serialize ( innerNodes )
107+ ) ;
108+
109+ const unendingTags = state . getProp ( 'unendingTags' ) || List ( ) ;
110+ const endTag =
111+ unendingTags . includes ( getTagFromCustomType ( node . type ) )
112+ ? ''
113+ : liquid . stringifyTag ( {
114+ tag : 'end' + getTagFromCustomType ( node . type )
115+ } ) ;
85116
86117 return state
87118 . shift ( )
@@ -103,7 +134,15 @@ const deserialize = Deserializer()
103134 return state ;
104135 }
105136
137+ < << << << HEAD
106138 const { tag , data } = liquid . parseTag ( text ) ;
139+ = === ===
140+ const parsed = liquid . parseTag ( text ) ;
141+ if ( ! parsed ) {
142+ return state ;
143+ }
144+ const { tag, data } = parsed ;
145+ > >>> >>> 6. x . x
107146
108147 const node = Block . create ( {
109148 type : getCustomTypeFromTag ( tag ) ,
0 commit comments