mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-27 14:02:07 +00:00 
			
		
		
		
	 5cc984d74c
			
		
	
	
		5cc984d74c
		
	
	
	
	
		
			
			With this patch, the blocks in a markdown document render a vector of lines. These lines get concatenated in Document::render_to_terminal, so this does not change any external APIs of LibMarkdown. This change makes it possible to indent individual lines in the rendered markdown. So, rendering blockquotes in a similar way to code blocks :^)
		
			
				
	
	
		
			45 lines
		
	
	
	
		
			961 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
	
		
			961 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <AK/Forward.h>
 | |
| #include <AK/StringBuilder.h>
 | |
| #include <LibMarkdown/Paragraph.h>
 | |
| #include <LibMarkdown/Visitor.h>
 | |
| 
 | |
| namespace Markdown {
 | |
| 
 | |
| DeprecatedString Paragraph::render_to_html(bool tight) const
 | |
| {
 | |
|     StringBuilder builder;
 | |
| 
 | |
|     if (!tight)
 | |
|         builder.append("<p>"sv);
 | |
| 
 | |
|     builder.append(m_text.render_to_html());
 | |
| 
 | |
|     if (!tight)
 | |
|         builder.append("</p>"sv);
 | |
| 
 | |
|     builder.append('\n');
 | |
| 
 | |
|     return builder.build();
 | |
| }
 | |
| 
 | |
| Vector<DeprecatedString> Paragraph::render_lines_for_terminal(size_t) const
 | |
| {
 | |
|     return Vector<DeprecatedString> { DeprecatedString::formatted("  {}", m_text.render_for_terminal()), "" };
 | |
| }
 | |
| 
 | |
| RecursionDecision Paragraph::walk(Visitor& visitor) const
 | |
| {
 | |
|     RecursionDecision rd = visitor.visit(*this);
 | |
|     if (rd != RecursionDecision::Recurse)
 | |
|         return rd;
 | |
| 
 | |
|     return m_text.walk(visitor);
 | |
| }
 | |
| 
 | |
| }
 |