File tree Expand file tree Collapse file tree 4 files changed +67
-3
lines changed Expand file tree Collapse file tree 4 files changed +67
-3
lines changed Original file line number Diff line number Diff line change @@ -673,13 +673,21 @@ export default {
673673 // without any inline formatting—other block kinds like asides will be
674674 // ignored in the resulting plaintext representation.
675675 plaintext () {
676+ const { references = {} } = this ;
676677 return this .reduce ((text , node ) => {
677678 if (node .type === BlockType .paragraph ) {
678679 return ` ${ text} \n ` ;
679680 }
681+ if (node .type === InlineType .codeVoice ) {
682+ return ` ${ text}${ node .code } ` ;
683+ }
680684 if (node .type === InlineType .text ) {
681685 return ` ${ text}${ node .text } ` ;
682686 }
687+ if (node .type === InlineType .reference ) {
688+ const title = references[node .identifier ]? .title ?? ' ' ;
689+ return ` ${ text}${ title} ` ;
690+ }
683691 return text;
684692 }, ' ' ).trim ();
685693 },
Original file line number Diff line number Diff line change @@ -18,9 +18,11 @@ export default {
1818 // Extracts the first paragraph of plaintext from the given content tree,
1919 // which can be used for metadata purposes.
2020 extractFirstParagraphText ( content = [ ] ) {
21+ const { references = { } } = this ;
2122 const plaintext = ContentNode . computed . plaintext . bind ( {
2223 ...ContentNode . methods ,
2324 content,
25+ references,
2426 } ) ( ) ;
2527 return firstParagraph ( plaintext ) ;
2628 } ,
Original file line number Diff line number Diff line change @@ -2538,10 +2538,57 @@ describe('ContentNode', () => {
25382538 } ,
25392539 ] ,
25402540 } ,
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+ } ,
25412577 ] ,
25422578 } ,
2579+ provide : {
2580+ store : {
2581+ state : {
2582+ references : {
2583+ b : {
2584+ title : 'B' ,
2585+ } ,
2586+ } ,
2587+ } ,
2588+ } ,
2589+ } ,
25432590 } ) ;
2544- expect ( wrapper . vm . plaintext ) . toBe ( 'A\nB ' ) ;
2591+ expect ( wrapper . vm . plaintext ) . toBe ( 'A B ' ) ;
25452592 } ) ;
25462593 } ) ;
25472594} ) ;
Original file line number Diff line number Diff line change @@ -45,6 +45,9 @@ const createWrapper = ({
4545 disableMetadata : ( ) => disableMetadata ,
4646 pageTitle : ( ) => title ,
4747 pageDescription : ( ) => description ,
48+ references : ( ) => ( {
49+ 'ref-d' : { title : 'd' } ,
50+ } ) ,
4851 } ,
4952 } , {
5053 mocks : {
@@ -99,7 +102,11 @@ describe('metadata', () => {
99102 } ,
100103 {
101104 type : 'text' ,
102- text : ' c' ,
105+ text : ' c ' ,
106+ } ,
107+ {
108+ type : 'reference' ,
109+ identifier : 'ref-d' ,
103110 } ,
104111 ] ,
105112 } ,
@@ -114,7 +121,7 @@ describe('metadata', () => {
114121 } ,
115122 ] ;
116123 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 ' ) ;
118125 expect ( wrapper . vm . extractFirstParagraphText ( [ ] ) ) . toBe ( '' ) ;
119126 } ) ;
120127 } ) ;
You can’t perform that action at this time.
0 commit comments