book-source 0.3.8 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/brainstorming CHANGED
@@ -40,7 +40,9 @@
40
40
  (where style can be a color like red, green, black, or other style like bold, italic, oblique, separated by comma ",")
41
41
  (generate a <span>)
42
42
 
43
- Title/Hint tooltip: [text][title text]
43
+ ✅ Hint (title-style tooltip): [text][title text]
44
+ ✅ Infotip (hover block-display tooltip): ?[text][some block of text]
45
+ ✅ Infotip href-variant: ?[text](href)
44
46
 
45
47
  ✅ Link: [link text](href)
46
48
  ✅ Link+Title: [link text][title text](href)
@@ -199,23 +199,26 @@ StructuredDocument.prototype.autoTitle = function() {
199
199
 
200
200
  if ( ! header ) { return ; }
201
201
 
202
- str = this.getText( header.parts ) ;
202
+ str = StructuredDocument.getText( header.parts ) ;
203
203
  if ( str ) { this.title = str ; }
204
204
  } ;
205
205
 
206
206
 
207
207
 
208
- StructuredDocument.prototype.getText = function( parts = this.parts ) {
208
+ StructuredDocument.getText = function( parts ) {
209
209
  var str = '' ;
210
210
 
211
211
  for ( let part of parts ) {
212
212
  if ( part.text ) { str += part.text ; }
213
- else if ( part.parts?.length ) { str += this.getText( part.parts ) ; }
213
+ else if ( part.parts?.length ) { str += StructuredDocument.getText( part.parts ) ; }
214
214
  }
215
215
 
216
216
  return str ;
217
217
  } ;
218
218
 
219
+ // Backqard compatibility/API
220
+ StructuredDocument.prototype.getText = function( parts = this.parts ) { return StructuredDocument.getText( parts ) ; } ;
221
+
219
222
 
220
223
 
221
224
  StructuredDocument.prototype.textPostFilter = function( postFilterList , parts = this.parts ) {
@@ -1382,7 +1385,7 @@ function parseInline( str , ctx , blockEnd , trim = false ) {
1382
1385
 
1383
1386
  function parseNestedInline( str , ctx , scanEnd , topLevel = false ) {
1384
1387
  var isSpace ,
1385
- lastWasSpace = WHITE_SPACES.has( str[ ctx.i - 1 ] ) ;
1388
+ lastWasSpaceOrBegining = ! ctx.i || WHITE_SPACES.has( str[ ctx.i - 1 ] ) ;
1386
1389
 
1387
1390
  //console.log( "parseInline() -- remaining:" , ctx.i , str.slice( ctx.i ) ) ;
1388
1391
 
@@ -1393,7 +1396,7 @@ function parseNestedInline( str , ctx , scanEnd , topLevel = false ) {
1393
1396
  for ( ; ctx.i < scanEnd ; ctx.i ++ ) {
1394
1397
  let char = str[ ctx.i ] ;
1395
1398
 
1396
- //if ( lastWasSpace ) {}
1399
+ //if ( lastWasSpaceOrBegining ) {}
1397
1400
  //console.error( "Checking: " , string.inspect( char ) ) ;
1398
1401
 
1399
1402
  isSpace = WHITE_SPACES.has( char ) ;
@@ -1422,12 +1425,16 @@ function parseNestedInline( str , ctx , scanEnd , topLevel = false ) {
1422
1425
  addInlineTextChunk( str , ctx ) ;
1423
1426
  parseStyledText( str , ctx , scanEnd ) ;
1424
1427
  }
1425
- else if ( char === '!' && str[ ctx.i + 1 ] === '[' && lastWasSpace ) {
1428
+ else if ( char === '?' && str[ ctx.i + 1 ] === '[' && lastWasSpaceOrBegining ) {
1429
+ addInlineTextChunk( str , ctx ) ;
1430
+ parseInfotipedText( str , ctx , scanEnd ) ;
1431
+ }
1432
+ else if ( char === '!' && str[ ctx.i + 1 ] === '[' && lastWasSpaceOrBegining ) {
1426
1433
  addInlineTextChunk( str , ctx ) ;
1427
1434
  parseImage( str , ctx , scanEnd ) ;
1428
1435
  }
1429
1436
 
1430
- lastWasSpace = isSpace ;
1437
+ lastWasSpaceOrBegining = isSpace ;
1431
1438
  }
1432
1439
 
1433
1440
  addInlineTextChunk( str , ctx ) ;
@@ -1581,8 +1588,6 @@ function parseStyledText( str , ctx , scanEnd ) {
1581
1588
  var end = searchCloser( str , ctx.i + 1 , '[' , ']' , false , scanEnd ) ;
1582
1589
  if ( end < 0 ) { return ; }
1583
1590
 
1584
- //var text = str.slice( ctx.i + 1 , end ) ;
1585
-
1586
1591
  var start = ctx.i + 1 ;
1587
1592
  ctx.i = end ;
1588
1593
  var data = parseDataMark( str , ctx , STYLE_DATA_MARK , scanEnd ) ;
@@ -1613,6 +1618,41 @@ function parseStyledText( str , ctx , scanEnd ) {
1613
1618
 
1614
1619
 
1615
1620
 
1621
+ const INFOTIP_DATA_MARK = {
1622
+ text: true , href: true , style: true , extra: false
1623
+ } ;
1624
+
1625
+ function parseInfotipedText( str , ctx , scanEnd ) {
1626
+ //console.error( "parseStyledText()" ) ;
1627
+ var end = searchCloser( str , ctx.i + 2 , '[' , ']' , false , scanEnd ) ;
1628
+ if ( end < 0 ) { return ; }
1629
+
1630
+ var start = ctx.i + 2 ;
1631
+ ctx.i = end ;
1632
+ var data = parseDataMark( str , ctx , INFOTIP_DATA_MARK , scanEnd ) ;
1633
+
1634
+ var fullMarkupEnd = ctx.i ;
1635
+
1636
+ var href = data?.href?.[ 0 ] ,
1637
+ style = data?.style?.[ 0 ] ,
1638
+ hint = data?.text?.[ 0 ] ;
1639
+
1640
+ var infotipedText = new documentParts.InfotipedText( hint , href , style ) ;
1641
+ ctx.parts.push( infotipedText ) ;
1642
+
1643
+ ctx.i = start ;
1644
+ parseNestedInline( str , ctx , end ) ;
1645
+
1646
+ ctx.i = fullMarkupEnd ;
1647
+ ctx.iStartOfInlineChunk = ctx.i + 1 ;
1648
+
1649
+ if ( ! href && ! hint ) {
1650
+ infotipedText.href = StructuredDocument.getText( infotipedText.parts ) ;
1651
+ }
1652
+ }
1653
+
1654
+
1655
+
1616
1656
  const IMAGE_DATA_MARK = {
1617
1657
  text: true , href: true , style: false , extra: false
1618
1658
  } ;
@@ -148,6 +148,21 @@ documentParts.Link = Link ;
148
148
 
149
149
 
150
150
 
151
+ // Tooltip/Infotip/Hint displayed when hovering
152
+ function InfotipedText( hint , href , style ) {
153
+ this.type = 'infotipedText' ;
154
+ this.hint = hint || undefined ;
155
+ this.href = href || undefined ;
156
+ this.style = style || undefined ;
157
+ InlineContainerPart.call( this ) ;
158
+ }
159
+
160
+ InfotipedText.prototype = Object.create( InlineContainerPart.prototype ) ;
161
+ InfotipedText.prototype.constructor = InfotipedText ;
162
+ documentParts.InfotipedText = InfotipedText ;
163
+
164
+
165
+
151
166
  function StyledText( style , hint ) {
152
167
  this.type = 'styledText' ;
153
168
  this.style = style || undefined ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "book-source",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "A lightweight markup language, inspired by Markdown.",
5
5
  "main": "lib/book-source.js",
6
6
  "directories": {