mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:22:45 +00:00 
			
		
		
		
	LibHTML: Optionally pass document URL to the HTML parser
This makes the document URL available to all the parse_attributes() callbacks, in case they need it for anything.
This commit is contained in:
		
							parent
							
								
									a239ef34d5
								
							
						
					
					
						commit
						66caa7af2b
					
				
					 3 changed files with 4 additions and 4 deletions
				
			
		|  | @ -175,8 +175,7 @@ void HtmlView::load(const URL& url) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     String html = String::copy(f->read_all()); |     String html = String::copy(f->read_all()); | ||||||
|     auto document = parse_html(html); |     auto document = parse_html(html, url); | ||||||
|     document->set_url(url); |  | ||||||
|     document->normalize(); |     document->normalize(); | ||||||
| 
 | 
 | ||||||
|     set_document(document); |     set_document(document); | ||||||
|  |  | ||||||
|  | @ -72,11 +72,12 @@ static bool is_self_closing_tag(const String& tag_name) | ||||||
|         || tag_name == "wbr"; |         || tag_name == "wbr"; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| NonnullRefPtr<Document> parse_html(const String& html) | NonnullRefPtr<Document> parse_html(const String& html, const URL& url) | ||||||
| { | { | ||||||
|     NonnullRefPtrVector<ParentNode> node_stack; |     NonnullRefPtrVector<ParentNode> node_stack; | ||||||
| 
 | 
 | ||||||
|     auto document = adopt(*new Document); |     auto document = adopt(*new Document); | ||||||
|  |     document->set_url(url); | ||||||
|     node_stack.append(document); |     node_stack.append(document); | ||||||
| 
 | 
 | ||||||
|     enum class State { |     enum class State { | ||||||
|  |  | ||||||
|  | @ -3,5 +3,5 @@ | ||||||
| #include <AK/NonnullRefPtr.h> | #include <AK/NonnullRefPtr.h> | ||||||
| #include <LibHTML/DOM/Document.h> | #include <LibHTML/DOM/Document.h> | ||||||
| 
 | 
 | ||||||
| NonnullRefPtr<Document> parse_html(const String&); | NonnullRefPtr<Document> parse_html(const String&, const URL& = URL()); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling