Merge pull request #17216 from calixteman/issue17215
Render rich text with only one text element
This commit is contained in:
		
						commit
						f528f6f07b
					
				| @ -176,8 +176,8 @@ class XfaLayer { | |||||||
|         linkService, |         linkService, | ||||||
|       }); |       }); | ||||||
|     } |     } | ||||||
|     const stack = [[root, -1, rootHtml]]; |  | ||||||
| 
 | 
 | ||||||
|  |     const isNotForRichText = intent !== "richText"; | ||||||
|     const rootDiv = parameters.div; |     const rootDiv = parameters.div; | ||||||
|     rootDiv.append(rootHtml); |     rootDiv.append(rootHtml); | ||||||
| 
 | 
 | ||||||
| @ -187,13 +187,28 @@ class XfaLayer { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Set defaults.
 |     // Set defaults.
 | ||||||
|     if (intent !== "richText") { |     if (isNotForRichText) { | ||||||
|       rootDiv.setAttribute("class", "xfaLayer xfaFont"); |       rootDiv.setAttribute("class", "xfaLayer xfaFont"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Text nodes used for the text highlighter.
 |     // Text nodes used for the text highlighter.
 | ||||||
|     const textDivs = []; |     const textDivs = []; | ||||||
| 
 | 
 | ||||||
|  |     // In the rich text context, it's possible to just have a text node without
 | ||||||
|  |     // a root element, so we handle this case here (see issue 17215).
 | ||||||
|  |     if (root.children.length === 0) { | ||||||
|  |       if (root.value) { | ||||||
|  |         const node = document.createTextNode(root.value); | ||||||
|  |         rootHtml.append(node); | ||||||
|  |         if (isNotForRichText && XfaText.shouldBuildText(root.name)) { | ||||||
|  |           textDivs.push(node); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |       return { textDivs }; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     const stack = [[root, -1, rootHtml]]; | ||||||
|  | 
 | ||||||
|     while (stack.length > 0) { |     while (stack.length > 0) { | ||||||
|       const [parent, i, html] = stack.at(-1); |       const [parent, i, html] = stack.at(-1); | ||||||
|       if (i + 1 === parent.children.length) { |       if (i + 1 === parent.children.length) { | ||||||
| @ -233,7 +248,7 @@ class XfaLayer { | |||||||
|         stack.push([child, -1, childHtml]); |         stack.push([child, -1, childHtml]); | ||||||
|       } else if (child.value) { |       } else if (child.value) { | ||||||
|         const node = document.createTextNode(child.value); |         const node = document.createTextNode(child.value); | ||||||
|         if (XfaText.shouldBuildText(name)) { |         if (isNotForRichText && XfaText.shouldBuildText(name)) { | ||||||
|           textDivs.push(node); |           textDivs.push(node); | ||||||
|         } |         } | ||||||
|         childHtml.append(node); |         childHtml.append(node); | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								test/pdfs/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								test/pdfs/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -617,3 +617,5 @@ | |||||||
| !bug1851498.pdf | !bug1851498.pdf | ||||||
| !issue17065.pdf | !issue17065.pdf | ||||||
| !issue17069.pdf | !issue17069.pdf | ||||||
|  | !issue17215.pdf | ||||||
|  | 
 | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								test/pdfs/issue17215.pdf
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/pdfs/issue17215.pdf
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -8189,5 +8189,13 @@ | |||||||
|       "link": true, |       "link": true, | ||||||
|       "rounds": 1, |       "rounds": 1, | ||||||
|       "type": "eq" |       "type": "eq" | ||||||
|    } |    }, | ||||||
|  |    {  | ||||||
|  |       "id": "issue17215-annotations", | ||||||
|  |       "file": "pdfs/issue17215.pdf", | ||||||
|  |       "md5": "968848af6ef593a3d1d6aba030ef47cb", | ||||||
|  |       "rounds": 1, | ||||||
|  |       "type": "eq", | ||||||
|  |       "annotations": true | ||||||
|  |    }    | ||||||
| ] | ] | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user