Fix header id and text might affects by mathjax tags
This commit is contained in:
		
							parent
							
								
									de2067f7e8
								
							
						
					
					
						commit
						ead48e45e0
					
				| @ -689,7 +689,8 @@ function generateToc(id) { | |||||||
|         'top': -1, |         'top': -1, | ||||||
|         'class': 'toc', |         'class': 'toc', | ||||||
|         'ulClass': 'nav', |         'ulClass': 'nav', | ||||||
|         'targetId': id |         'targetId': id, | ||||||
|  |         'process': getHeaderContent | ||||||
|     }); |     }); | ||||||
|     if (target.text() == 'undefined') |     if (target.text() == 'undefined') | ||||||
|         target.html(''); |         target.html(''); | ||||||
| @ -777,7 +778,7 @@ var linkifyAnchors = function (level, containingElement) { | |||||||
|         if (header.getElementsByClassName("anchor").length == 0) { |         if (header.getElementsByClassName("anchor").length == 0) { | ||||||
|             if (typeof header.id == "undefined" || header.id == "") { |             if (typeof header.id == "undefined" || header.id == "") { | ||||||
|                 //to escape characters not allow in css and humanize
 |                 //to escape characters not allow in css and humanize
 | ||||||
|                 var id = slugifyWithUTF8(header.innerHTML); |                 var id = slugifyWithUTF8(getHeaderContent(header)); | ||||||
|                 header.id = id; |                 header.id = id; | ||||||
|             } |             } | ||||||
|             header.insertBefore(anchorForId(header.id), header.firstChild); |             header.insertBefore(anchorForId(header.id), header.firstChild); | ||||||
| @ -795,6 +796,13 @@ function autoLinkify(view) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function getHeaderContent(header) { | ||||||
|  |     var headerHTML = $(header).clone(); | ||||||
|  |     headerHTML.find('.MathJax_Preview').remove(); | ||||||
|  |     headerHTML.find('.MathJax').remove(); | ||||||
|  |     return headerHTML[0].innerHTML; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| function deduplicatedHeaderId(view) { | function deduplicatedHeaderId(view) { | ||||||
|     var headers = view.find(':header.raw').removeClass('raw').toArray(); |     var headers = view.find(':header.raw').removeClass('raw').toArray(); | ||||||
|     for (var i = 0; i < headers.length; i++) { |     for (var i = 0; i < headers.length; i++) { | ||||||
| @ -826,7 +834,8 @@ function renderTOC(view) { | |||||||
|             'level': 3, |             'level': 3, | ||||||
|             'top': -1, |             'top': -1, | ||||||
|             'class': 'toc', |             'class': 'toc', | ||||||
|             'targetId': id |             'targetId': id, | ||||||
|  |             'process': getHeaderContent | ||||||
|         }); |         }); | ||||||
|         if (target.text() == 'undefined') |         if (target.text() == 'undefined') | ||||||
|             target.html(''); |             target.html(''); | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								public/vendor/md-toc.js
									
									
									
									
										vendored
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										3
									
								
								public/vendor/md-toc.js
									
									
									
									
										vendored
									
									
										
										
										Normal file → Executable file
									
								
							| @ -13,6 +13,7 @@ | |||||||
|         this.ulClass = options['ulClass']; |         this.ulClass = options['ulClass']; | ||||||
|         this.tocTop = parseInt(options.top) || 0; |         this.tocTop = parseInt(options.top) || 0; | ||||||
|         this.elChilds = this.el.children; |         this.elChilds = this.el.children; | ||||||
|  |         this.process = options['process']; | ||||||
|         if (!this.elChilds.length) return; |         if (!this.elChilds.length) return; | ||||||
|         this._init(); |         this._init(); | ||||||
|     } |     } | ||||||
| @ -53,7 +54,7 @@ | |||||||
|             var j = i + 1; |             var j = i + 1; | ||||||
|             this._elTitleElement = this.elTitleElements[i]; |             this._elTitleElement = this.elTitleElements[i]; | ||||||
|             this._elTitleElementName = this._elTitleElement.tagName; |             this._elTitleElementName = this._elTitleElement.tagName; | ||||||
|             this._elTitleElementText = this._elTitleElement.innerHTML.replace(/<(?:.|\n)*?>/gm, ''); |             this._elTitleElementText = (typeof this.process === 'function' ? this.process(this._elTitleElement) : this._elTitleElement.innerHTML).replace(/<(?:.|\n)*?>/gm, ''); | ||||||
|             var id = this._elTitleElement.getAttribute('id'); |             var id = this._elTitleElement.getAttribute('id'); | ||||||
|             if (!id) { |             if (!id) { | ||||||
|                 this._elTitleElement.setAttribute('id', 'tip' + i); |                 this._elTitleElement.setAttribute('id', 'tip' + i); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user