@@ -52,33 +52,6 @@ export class Block<Attr = unknown> extends Range implements IBlock, Printable, S
5252 return length ? path [ length - 1 ] : '' ;
5353 }
5454
55- // public htmlTag(): string {
56- // const tag = this.tag();
57- // switch (typeof tag) {
58- // case 'string': return tag.toLowerCase();
59- // case 'number': return SliceTypeName[tag] || 'div';
60- // default: return 'div';
61- // }
62- // }
63-
64- // protected jsonMlNode(): JsonMlElement {
65- // const props: Record<string, string> = {};
66- // const node: JsonMlElement = ['div', props];
67- // const tag = this.tag();
68- // switch (typeof tag) {
69- // case 'string':
70- // node[0] = tag;
71- // break;
72- // case 'number':
73- // const tag0 = SliceTypeName[tag];
74- // if (tag0) node[0] = tag0; else props['data-tag'] = tag + '';
75- // break;
76- // }
77- // const attr = this.attr();
78- // if (attr !== undefined) props['data-attr'] = JSON.stringify(attr);
79- // return node;
80- // }
81-
8255 public attr ( ) : Attr | undefined {
8356 return this . marker ?. data ( ) as Attr | undefined ;
8457 }
@@ -112,59 +85,70 @@ export class Block<Attr = unknown> extends Range implements IBlock, Printable, S
11285 return new UndefEndIter ( this . points0 ( withMarker ) ) ;
11386 }
11487
115- public tuples0 ( ) : UndefIterator < OverlayTuple < T > > {
88+ protected tuples0 ( ) : UndefIterator < OverlayTuple < T > > {
11689 const overlay = this . txt . overlay ;
117- const iterator = overlay . tuples0 ( this . marker ) ;
90+ const marker = this . marker ;
91+ const iterator = overlay . tuples0 ( marker ) ;
11892 let closed = false ;
11993 return ( ) => {
12094 if ( closed ) return ;
121- const pair = iterator ( ) ;
122- if ( ! pair ) return ;
95+ let pair = iterator ( ) ;
96+ while ( ! marker && pair && pair [ 1 ] && pair [ 1 ] . cmpSpatial ( this . start ) < 0 ) pair = iterator ( ) ;
97+ if ( ! pair ) return ( closed = true ) , void 0 ;
12398 if ( ! pair [ 1 ] || pair [ 1 ] instanceof MarkerOverlayPoint ) closed = true ;
12499 return pair ;
125100 } ;
126101 }
127102
128- public tuples ( ) : IterableIterator < OverlayTuple < T > > {
129- return new UndefEndIter ( this . tuples0 ( ) ) ;
130- }
131-
103+ /**
104+ * @todo Consider moving inline-related methods to {@link LeafBlock}.
105+ */
132106 public texts0 ( ) : UndefIterator < Inline > {
133107 const txt = this . txt ;
134108 const iterator = this . tuples0 ( ) ;
135- const blockStart = this . start ;
136- const blockEnd = this . end ;
109+ const start = this . start ;
110+ const end = this . end ;
111+ const startIsMarker = txt . overlay . isMarker ( start . id ) ;
112+ const endIsMarker = txt . overlay . isMarker ( end . id ) ;
137113 let isFirst = true ;
138114 let next = iterator ( ) ;
115+ let closed = false ;
139116 return ( ) => {
117+ if ( closed ) return ;
140118 const pair = next ;
141119 next = iterator ( ) ;
142120 if ( ! pair ) return ;
143- const [ p1 , p2 ] = pair ;
144- let start : Point = p1 ;
145- let end : Point = p2 ;
121+ const [ overlayPoint1 , overlayPoint2 ] = pair ;
122+ let point1 : Point = overlayPoint1 ;
123+ let point2 : Point = overlayPoint2 ;
146124 if ( isFirst ) {
147125 isFirst = false ;
148- if ( blockStart . cmpSpatial ( p1 ) > 0 ) start = blockStart ;
126+ if ( start . cmpSpatial ( overlayPoint1 ) > 0 ) point1 = start ;
127+ if ( startIsMarker ) {
128+ point1 = point1 . clone ( ) ;
129+ point1 . step ( 1 ) ;
130+ }
149131 }
150- const isLast = ! next ;
151- if ( isLast ) if ( blockEnd . cmpSpatial ( p2 ) < 0 ) end = blockEnd ;
152- return new Inline ( txt , p1 , p2 , start , end ) ;
132+ if ( ! endIsMarker && end . cmpSpatial ( overlayPoint2 ) < 0 ) {
133+ closed = true ;
134+ point2 = end ;
135+ }
136+ return new Inline ( txt , overlayPoint1 , overlayPoint2 , point1 , point2 ) ;
153137 } ;
154138 }
155139
140+ /**
141+ * @todo Consider moving inline-related methods to {@link LeafBlock}.
142+ */
156143 public texts ( ) : IterableIterator < Inline > {
157144 return new UndefEndIter ( this . texts0 ( ) ) ;
158145 }
159146
160147 public text ( ) : string {
161148 let str = '' ;
162- const iterator = this . texts0 ( ) ;
163- let inline = iterator ( ) ;
164- while ( inline ) {
165- str += inline . text ( ) ;
166- inline = iterator ( ) ;
167- }
149+ const children = this . children ;
150+ const length = children . length ;
151+ for ( let i = 0 ; i < length ; i ++ ) str += children [ i ] . text ( ) ;
168152 return str ;
169153 }
170154
@@ -204,6 +188,7 @@ export class Block<Attr = unknown> extends Range implements IBlock, Printable, S
204188 public toStringName ( ) : string {
205189 return 'Block' ;
206190 }
191+
207192 protected toStringHeader ( ) : string {
208193 const hash = `#${ this . hash . toString ( 36 ) . slice ( - 4 ) } ` ;
209194 const tag = this . path . map ( ( step ) => formatType ( step ) ) . join ( '.' ) ;
0 commit comments