File tree Expand file tree Collapse file tree 4 files changed +68
-3
lines changed Expand file tree Collapse file tree 4 files changed +68
-3
lines changed Original file line number Diff line number Diff line change @@ -673,13 +673,21 @@ export default {
673
673
// without any inline formatting—other block kinds like asides will be
674
674
// ignored in the resulting plaintext representation.
675
675
plaintext () {
676
+ const { references = {} } = this ;
676
677
return this .reduce ((text , node ) => {
677
678
if (node .type === BlockType .paragraph ) {
678
679
return ` ${ text} \n ` ;
679
680
}
681
+ if (node .type === InlineType .codeVoice ) {
682
+ return ` ${ text}${ node .code } ` ;
683
+ }
680
684
if (node .type === InlineType .text ) {
681
685
return ` ${ text}${ node .text } ` ;
682
686
}
687
+ if (node .type === InlineType .reference ) {
688
+ const title = references[node .identifier ]? .title ?? ' ' ;
689
+ return ` ${ text}${ title} ` ;
690
+ }
683
691
return text;
684
692
}, ' ' ).trim ();
685
693
},
Original file line number Diff line number Diff line change @@ -18,9 +18,11 @@ export default {
18
18
// Extracts the first paragraph of plaintext from the given content tree,
19
19
// which can be used for metadata purposes.
20
20
extractFirstParagraphText ( content = [ ] ) {
21
+ const { references = { } } = this ;
21
22
const plaintext = ContentNode . computed . plaintext . bind ( {
22
23
...ContentNode . methods ,
23
24
content,
25
+ references,
24
26
} ) ( ) ;
25
27
return firstParagraph ( plaintext ) ;
26
28
} ,
Original file line number Diff line number Diff line change @@ -2538,10 +2538,58 @@ describe('ContentNode', () => {
2538
2538
} ,
2539
2539
] ,
2540
2540
} ,
2541
+ {
2542
+ type : ContentNode . BlockType . paragraph ,
2543
+ inlineContent : [
2544
+ {
2545
+ type : ContentNode . InlineType . codeVoice ,
2546
+ code : 'C' ,
2547
+ } ,
2548
+ ] ,
2549
+ } ,
2550
+ ] ,
2551
+ } ,
2552
+ } ) ;
2553
+ expect ( wrapper . vm . plaintext ) . toBe ( 'A\nB\nC' ) ;
2554
+ } ) ;
2555
+
2556
+ it ( 'includes text from references' , ( ) => {
2557
+ const wrapper = shallowMount ( ContentNode , {
2558
+ propsData : {
2559
+ content : [
2560
+ {
2561
+ type : ContentNode . BlockType . paragraph ,
2562
+ inlineContent : [
2563
+ {
2564
+ type : ContentNode . InlineType . text ,
2565
+ text : 'A' ,
2566
+ } ,
2567
+ {
2568
+ type : ContentNode . InlineType . text ,
2569
+ text : ' ' ,
2570
+ } ,
2571
+ {
2572
+ type : ContentNode . InlineType . reference ,
2573
+ identifier : 'b' ,
2574
+ } ,
2575
+ ] ,
2576
+ } ,
2541
2577
] ,
2542
2578
} ,
2579
+ provide : {
2580
+ store : {
2581
+ state : {
2582
+ references : {
2583
+ b : {
2584
+ title : 'B' ,
2585
+ url : '/b' ,
2586
+ } ,
2587
+ } ,
2588
+ } ,
2589
+ } ,
2590
+ } ,
2543
2591
} ) ;
2544
- expect ( wrapper . vm . plaintext ) . toBe ( 'A\nB ' ) ;
2592
+ expect ( wrapper . vm . plaintext ) . toBe ( 'A B ' ) ;
2545
2593
} ) ;
2546
2594
} ) ;
2547
2595
} ) ;
Original file line number Diff line number Diff line change @@ -45,6 +45,9 @@ const createWrapper = ({
45
45
disableMetadata : ( ) => disableMetadata ,
46
46
pageTitle : ( ) => title ,
47
47
pageDescription : ( ) => description ,
48
+ references : ( ) => ( {
49
+ 'ref-d' : { title : 'd' } ,
50
+ } ) ,
48
51
} ,
49
52
} , {
50
53
mocks : {
@@ -99,7 +102,11 @@ describe('metadata', () => {
99
102
} ,
100
103
{
101
104
type : 'text' ,
102
- text : ' c' ,
105
+ text : ' c ' ,
106
+ } ,
107
+ {
108
+ type : 'reference' ,
109
+ identifier : 'ref-d' ,
103
110
} ,
104
111
] ,
105
112
} ,
@@ -114,7 +121,7 @@ describe('metadata', () => {
114
121
} ,
115
122
] ;
116
123
const wrapper = createWrapper ( pageData ) ;
117
- expect ( wrapper . vm . extractFirstParagraphText ( content ) ) . toBe ( 'a b c' ) ;
124
+ expect ( wrapper . vm . extractFirstParagraphText ( content ) ) . toBe ( 'a b c d ' ) ;
118
125
expect ( wrapper . vm . extractFirstParagraphText ( [ ] ) ) . toBe ( '' ) ;
119
126
} ) ;
120
127
} ) ;
You can’t perform that action at this time.
0 commit comments