@@ -11,7 +11,7 @@ import type {PathStep} from '../../../json-pointer';
1111import type { Slice } from '../slice/types' ;
1212import type { Peritext } from '../Peritext' ;
1313
14- export type Marks = Record < string | number , unknown > ;
14+ export type InlineAttributes = Record < string | number , unknown > ;
1515
1616/**
1717 * The `Inline` class represents a range of inline text within a block, which
@@ -60,14 +60,29 @@ export class Inline extends Range implements Printable {
6060 return updateNum ( this . start . refresh ( ) , this . end . refresh ( ) ) ;
6161 }
6262
63+ /**
64+ * @returns The full text content of the inline, which is the concatenation
65+ * of all the underlying {@link ChunkSlice}s.
66+ */
6367 public str ( ) : string {
6468 let str = '' ;
6569 for ( const slice of this . texts ) str += slice . view ( ) ;
6670 return str ;
6771 }
6872
69- public marks ( ) : Marks {
70- const marks : Marks = { } ;
73+ /**
74+ * @returns The position of the inline withing the text.
75+ */
76+ public pos ( ) : number {
77+ const chunkSlice = this . texts [ 0 ] ;
78+ if ( ! chunkSlice ) return - 1 ;
79+ const chunk = chunkSlice . chunk ;
80+ const pos = this . rga . pos ( chunk ) ;
81+ return pos + chunkSlice . off ;
82+ }
83+
84+ public attr ( ) : InlineAttributes {
85+ const attr : InlineAttributes = { } ;
7186 const point = this . start as OverlayPoint ;
7287 const slices : Slice [ ] = this . texts . length ? point . layers : point . markers ;
7388 const length = slices . length ;
@@ -76,8 +91,8 @@ export class Inline extends Range implements Printable {
7691 const type = slice . type as PathStep ;
7792 switch ( slice . behavior ) {
7893 case SliceBehavior . Stack : {
79- let dataList : unknown [ ] = ( marks [ type ] as unknown [ ] ) || ( marks [ type ] = [ ] ) ;
80- if ( ! Array . isArray ( dataList ) ) dataList = marks [ type ] = [ dataList ] ;
94+ let dataList : unknown [ ] = ( attr [ type ] as unknown [ ] ) || ( attr [ type ] = [ ] ) ;
95+ if ( ! Array . isArray ( dataList ) ) dataList = attr [ type ] = [ dataList ] ;
8196 let data = slice . data ( ) ;
8297 if ( data === undefined ) data = 1 ;
8398 dataList . push ( data ) ;
@@ -86,24 +101,16 @@ export class Inline extends Range implements Printable {
86101 case SliceBehavior . Overwrite : {
87102 let data = slice . data ( ) ;
88103 if ( data === undefined ) data = 1 ;
89- marks [ type ] = data ;
104+ attr [ type ] = data ;
90105 break ;
91106 }
92107 case SliceBehavior . Erase : {
93- delete marks [ type ] ;
108+ delete attr [ type ] ;
94109 break ;
95110 }
96111 }
97112 }
98- return marks ;
99- }
100-
101- public pos ( ) : number {
102- const chunkSlice = this . texts [ 0 ] ;
103- if ( ! chunkSlice ) return - 1 ;
104- const chunk = chunkSlice . chunk ;
105- const pos = this . rga . pos ( chunk ) ;
106- return pos + chunkSlice . off ;
113+ return attr ;
107114 }
108115
109116 // ---------------------------------------------------------------- Printable
@@ -116,7 +123,7 @@ export class Inline extends Range implements Printable {
116123 const range =
117124 this . start . cmp ( this . end ) === 0 ? startFormatted : `${ startFormatted } ↔ ${ this . end . toString ( tab , true ) } ` ;
118125 const header = `${ this . constructor . name } ${ range } ${ text } ` ;
119- const marks = this . marks ( ) ;
126+ const marks = this . attr ( ) ;
120127 const markKeys = Object . keys ( marks ) ;
121128 return (
122129 header +
0 commit comments