mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:22:43 +00:00 
			
		
		
		
	LibMarkdown: Drop MD prefixes and move into "Markdown" namespace :^)
This commit is contained in:
		
							parent
							
								
									104969a9f5
								
							
						
					
					
						commit
						ea204ef05b
					
				
					 18 changed files with 131 additions and 78 deletions
				
			
		|  | @ -41,7 +41,7 @@ | ||||||
| #include <LibGUI/ToolBarContainer.h> | #include <LibGUI/ToolBarContainer.h> | ||||||
| #include <LibGUI/TreeView.h> | #include <LibGUI/TreeView.h> | ||||||
| #include <LibGUI/Window.h> | #include <LibGUI/Window.h> | ||||||
| #include <LibMarkdown/MDDocument.h> | #include <LibMarkdown/Document.h> | ||||||
| #include <LibWeb/HtmlView.h> | #include <LibWeb/HtmlView.h> | ||||||
| #include <LibWeb/Layout/LayoutNode.h> | #include <LibWeb/Layout/LayoutNode.h> | ||||||
| #include <LibWeb/Parser/CSSParser.h> | #include <LibWeb/Parser/CSSParser.h> | ||||||
|  | @ -128,7 +128,7 @@ int main(int argc, char* argv[]) | ||||||
|         auto buffer = file->read_all(); |         auto buffer = file->read_all(); | ||||||
|         StringView source { (const char*)buffer.data(), buffer.size() }; |         StringView source { (const char*)buffer.data(), buffer.size() }; | ||||||
| 
 | 
 | ||||||
|         MDDocument md_document; |         Markdown::Document md_document; | ||||||
|         bool success = md_document.parse(source); |         bool success = md_document.parse(source); | ||||||
|         ASSERT(success); |         ASSERT(success); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -36,7 +36,7 @@ | ||||||
| #include <LibGUI/ScrollBar.h> | #include <LibGUI/ScrollBar.h> | ||||||
| #include <LibGUI/SyntaxHighlighter.h> | #include <LibGUI/SyntaxHighlighter.h> | ||||||
| #include <LibGUI/Window.h> | #include <LibGUI/Window.h> | ||||||
| #include <LibMarkdown/MDDocument.h> | #include <LibMarkdown/Document.h> | ||||||
| #include <LibWeb/DOM/ElementFactory.h> | #include <LibWeb/DOM/ElementFactory.h> | ||||||
| #include <LibWeb/DOM/HTMLHeadElement.h> | #include <LibWeb/DOM/HTMLHeadElement.h> | ||||||
| #include <LibWeb/DOM/Text.h> | #include <LibWeb/DOM/Text.h> | ||||||
|  | @ -166,7 +166,7 @@ void Editor::show_documentation_tooltip_if_available(const String& hovered_token | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     MDDocument man_document; |     Markdown::Document man_document; | ||||||
|     bool success = man_document.parse(file->read_all()); |     bool success = man_document.parse(file->read_all()); | ||||||
| 
 | 
 | ||||||
|     if (!success) { |     if (!success) { | ||||||
|  |  | ||||||
|  | @ -26,13 +26,18 @@ | ||||||
| 
 | 
 | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
|  | #include <AK/StringView.h> | ||||||
| #include <AK/Vector.h> | #include <AK/Vector.h> | ||||||
| 
 | 
 | ||||||
| class MDBlock { | namespace Markdown { | ||||||
|  | 
 | ||||||
|  | class Block { | ||||||
| public: | public: | ||||||
|     virtual ~MDBlock() {} |     virtual ~Block() {} | ||||||
| 
 | 
 | ||||||
|     virtual String render_to_html() const = 0; |     virtual String render_to_html() const = 0; | ||||||
|     virtual String render_for_terminal() const = 0; |     virtual String render_for_terminal() const = 0; | ||||||
|     virtual bool parse(Vector<StringView>::ConstIterator& lines) = 0; |     virtual bool parse(Vector<StringView>::ConstIterator& lines) = 0; | ||||||
| }; | }; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -25,28 +25,30 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <AK/StringBuilder.h> | #include <AK/StringBuilder.h> | ||||||
| #include <LibMarkdown/MDCodeBlock.h> | #include <LibMarkdown/CodeBlock.h> | ||||||
| 
 | 
 | ||||||
| MDText::Style MDCodeBlock::style() const | namespace Markdown { | ||||||
|  | 
 | ||||||
|  | Text::Style CodeBlock::style() const | ||||||
| { | { | ||||||
|     if (m_style_spec.spans().is_empty()) |     if (m_style_spec.spans().is_empty()) | ||||||
|         return {}; |         return {}; | ||||||
|     return m_style_spec.spans()[0].style; |     return m_style_spec.spans()[0].style; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| String MDCodeBlock::style_language() const | String CodeBlock::style_language() const | ||||||
| { | { | ||||||
|     if (m_style_spec.spans().is_empty()) |     if (m_style_spec.spans().is_empty()) | ||||||
|         return {}; |         return {}; | ||||||
|     return m_style_spec.spans()[0].text; |     return m_style_spec.spans()[0].text; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| String MDCodeBlock::render_to_html() const | String CodeBlock::render_to_html() const | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
| 
 | 
 | ||||||
|     String style_language = this->style_language(); |     String style_language = this->style_language(); | ||||||
|     MDText::Style style = this->style(); |     Text::Style style = this->style(); | ||||||
| 
 | 
 | ||||||
|     if (style.strong) |     if (style.strong) | ||||||
|         builder.append("<b>"); |         builder.append("<b>"); | ||||||
|  | @ -81,11 +83,11 @@ String MDCodeBlock::render_to_html() const | ||||||
|     return builder.build(); |     return builder.build(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| String MDCodeBlock::render_for_terminal() const | String CodeBlock::render_for_terminal() const | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
| 
 | 
 | ||||||
|     MDText::Style style = this->style(); |     Text::Style style = this->style(); | ||||||
|     bool needs_styling = style.strong || style.emph; |     bool needs_styling = style.strong || style.emph; | ||||||
|     if (needs_styling) { |     if (needs_styling) { | ||||||
|         builder.append("\033["); |         builder.append("\033["); | ||||||
|  | @ -112,7 +114,7 @@ String MDCodeBlock::render_for_terminal() const | ||||||
|     return builder.build(); |     return builder.build(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool MDCodeBlock::parse(Vector<StringView>::ConstIterator& lines) | bool CodeBlock::parse(Vector<StringView>::ConstIterator& lines) | ||||||
| { | { | ||||||
|     if (lines.is_end()) |     if (lines.is_end()) | ||||||
|         return false; |         return false; | ||||||
|  | @ -159,3 +161,5 @@ bool MDCodeBlock::parse(Vector<StringView>::ConstIterator& lines) | ||||||
|     m_code = builder.build(); |     m_code = builder.build(); | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -26,12 +26,14 @@ | ||||||
| 
 | 
 | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #include <LibMarkdown/MDBlock.h> | #include <LibMarkdown/Block.h> | ||||||
| #include <LibMarkdown/MDText.h> | #include <LibMarkdown/Text.h> | ||||||
| 
 | 
 | ||||||
| class MDCodeBlock final : public MDBlock { | namespace Markdown { | ||||||
|  | 
 | ||||||
|  | class CodeBlock final : public Block { | ||||||
| public: | public: | ||||||
|     virtual ~MDCodeBlock() override {} |     virtual ~CodeBlock() override {} | ||||||
| 
 | 
 | ||||||
|     virtual String render_to_html() const override; |     virtual String render_to_html() const override; | ||||||
|     virtual String render_for_terminal() const override; |     virtual String render_for_terminal() const override; | ||||||
|  | @ -39,8 +41,10 @@ public: | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     String style_language() const; |     String style_language() const; | ||||||
|     MDText::Style style() const; |     Text::Style style() const; | ||||||
| 
 | 
 | ||||||
|     String m_code; |     String m_code; | ||||||
|     MDText m_style_spec; |     Text m_style_spec; | ||||||
| }; | }; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -25,13 +25,15 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <AK/StringBuilder.h> | #include <AK/StringBuilder.h> | ||||||
| #include <LibMarkdown/MDCodeBlock.h> | #include <LibMarkdown/CodeBlock.h> | ||||||
| #include <LibMarkdown/MDDocument.h> | #include <LibMarkdown/Document.h> | ||||||
| #include <LibMarkdown/MDHeading.h> | #include <LibMarkdown/Heading.h> | ||||||
| #include <LibMarkdown/MDList.h> | #include <LibMarkdown/List.h> | ||||||
| #include <LibMarkdown/MDParagraph.h> | #include <LibMarkdown/Paragraph.h> | ||||||
| 
 | 
 | ||||||
| String MDDocument::render_to_html() const | namespace Markdown { | ||||||
|  | 
 | ||||||
|  | String Document::render_to_html() const | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
| 
 | 
 | ||||||
|  | @ -50,7 +52,7 @@ String MDDocument::render_to_html() const | ||||||
|     return builder.build(); |     return builder.build(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| String MDDocument::render_for_terminal() const | String Document::render_for_terminal() const | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
| 
 | 
 | ||||||
|  | @ -62,10 +64,10 @@ String MDDocument::render_for_terminal() const | ||||||
|     return builder.build(); |     return builder.build(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| template<typename Block> | template<typename BlockType> | ||||||
| static bool helper(Vector<StringView>::ConstIterator& lines, NonnullOwnPtrVector<MDBlock>& blocks) | static bool helper(Vector<StringView>::ConstIterator& lines, NonnullOwnPtrVector<Block>& blocks) | ||||||
| { | { | ||||||
|     NonnullOwnPtr<Block> block = make<Block>(); |     NonnullOwnPtr<BlockType> block = make<BlockType>(); | ||||||
|     bool success = block->parse(lines); |     bool success = block->parse(lines); | ||||||
|     if (!success) |     if (!success) | ||||||
|         return false; |         return false; | ||||||
|  | @ -73,7 +75,7 @@ static bool helper(Vector<StringView>::ConstIterator& lines, NonnullOwnPtrVector | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool MDDocument::parse(const StringView& str) | bool Document::parse(const StringView& str) | ||||||
| { | { | ||||||
|     const Vector<StringView> lines_vec = str.lines(); |     const Vector<StringView> lines_vec = str.lines(); | ||||||
|     auto lines = lines_vec.begin(); |     auto lines = lines_vec.begin(); | ||||||
|  | @ -87,9 +89,11 @@ bool MDDocument::parse(const StringView& str) | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         bool any = helper<MDList>(lines, m_blocks) || helper<MDParagraph>(lines, m_blocks) || helper<MDCodeBlock>(lines, m_blocks) || helper<MDHeading>(lines, m_blocks); |         bool any = helper<List>(lines, m_blocks) || helper<Paragraph>(lines, m_blocks) || helper<CodeBlock>(lines, m_blocks) || helper<Heading>(lines, m_blocks); | ||||||
| 
 | 
 | ||||||
|         if (!any) |         if (!any) | ||||||
|             return false; |             return false; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -28,9 +28,11 @@ | ||||||
| 
 | 
 | ||||||
| #include <AK/NonnullOwnPtrVector.h> | #include <AK/NonnullOwnPtrVector.h> | ||||||
| #include <AK/String.h> | #include <AK/String.h> | ||||||
| #include <LibMarkdown/MDBlock.h> | #include <LibMarkdown/Block.h> | ||||||
| 
 | 
 | ||||||
| class MDDocument final { | namespace Markdown { | ||||||
|  | 
 | ||||||
|  | class Document final { | ||||||
| public: | public: | ||||||
|     String render_to_html() const; |     String render_to_html() const; | ||||||
|     String render_for_terminal() const; |     String render_for_terminal() const; | ||||||
|  | @ -38,5 +40,7 @@ public: | ||||||
|     bool parse(const StringView&); |     bool parse(const StringView&); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     NonnullOwnPtrVector<MDBlock> m_blocks; |     NonnullOwnPtrVector<Block> m_blocks; | ||||||
| }; | }; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -25,9 +25,11 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <AK/StringBuilder.h> | #include <AK/StringBuilder.h> | ||||||
| #include <LibMarkdown/MDHeading.h> | #include <LibMarkdown/Heading.h> | ||||||
| 
 | 
 | ||||||
| String MDHeading::render_to_html() const | namespace Markdown { | ||||||
|  | 
 | ||||||
|  | String Heading::render_to_html() const | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
|     builder.appendf("<h%d>", m_level); |     builder.appendf("<h%d>", m_level); | ||||||
|  | @ -36,7 +38,7 @@ String MDHeading::render_to_html() const | ||||||
|     return builder.build(); |     return builder.build(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| String MDHeading::render_for_terminal() const | String Heading::render_for_terminal() const | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
| 
 | 
 | ||||||
|  | @ -57,7 +59,7 @@ String MDHeading::render_for_terminal() const | ||||||
|     return builder.build(); |     return builder.build(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool MDHeading::parse(Vector<StringView>::ConstIterator& lines) | bool Heading::parse(Vector<StringView>::ConstIterator& lines) | ||||||
| { | { | ||||||
|     if (lines.is_end()) |     if (lines.is_end()) | ||||||
|         return false; |         return false; | ||||||
|  | @ -78,3 +80,5 @@ bool MDHeading::parse(Vector<StringView>::ConstIterator& lines) | ||||||
|     ++lines; |     ++lines; | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -28,18 +28,22 @@ | ||||||
| 
 | 
 | ||||||
| #include <AK/StringView.h> | #include <AK/StringView.h> | ||||||
| #include <AK/Vector.h> | #include <AK/Vector.h> | ||||||
| #include <LibMarkdown/MDBlock.h> | #include <LibMarkdown/Block.h> | ||||||
| #include <LibMarkdown/MDText.h> | #include <LibMarkdown/Text.h> | ||||||
| 
 | 
 | ||||||
| class MDHeading final : public MDBlock { | namespace Markdown { | ||||||
|  | 
 | ||||||
|  | class Heading final : public Block { | ||||||
| public: | public: | ||||||
|     virtual ~MDHeading() override {} |     virtual ~Heading() override {} | ||||||
| 
 | 
 | ||||||
|     virtual String render_to_html() const override; |     virtual String render_to_html() const override; | ||||||
|     virtual String render_for_terminal() const override; |     virtual String render_for_terminal() const override; | ||||||
|     virtual bool parse(Vector<StringView>::ConstIterator& lines) override; |     virtual bool parse(Vector<StringView>::ConstIterator& lines) override; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     MDText m_text; |     Text m_text; | ||||||
|     int m_level { -1 }; |     int m_level { -1 }; | ||||||
| }; | }; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -25,9 +25,11 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <AK/StringBuilder.h> | #include <AK/StringBuilder.h> | ||||||
| #include <LibMarkdown/MDList.h> | #include <LibMarkdown/List.h> | ||||||
| 
 | 
 | ||||||
| String MDList::render_to_html() const | namespace Markdown { | ||||||
|  | 
 | ||||||
|  | String List::render_to_html() const | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
| 
 | 
 | ||||||
|  | @ -45,7 +47,7 @@ String MDList::render_to_html() const | ||||||
|     return builder.build(); |     return builder.build(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| String MDList::render_for_terminal() const | String List::render_for_terminal() const | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
| 
 | 
 | ||||||
|  | @ -64,7 +66,7 @@ String MDList::render_for_terminal() const | ||||||
|     return builder.build(); |     return builder.build(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool MDList::parse(Vector<StringView>::ConstIterator& lines) | bool List::parse(Vector<StringView>::ConstIterator& lines) | ||||||
| { | { | ||||||
|     bool first = true; |     bool first = true; | ||||||
|     while (true) { |     while (true) { | ||||||
|  | @ -104,7 +106,7 @@ bool MDList::parse(Vector<StringView>::ConstIterator& lines) | ||||||
|             return false; |             return false; | ||||||
| 
 | 
 | ||||||
|         first = false; |         first = false; | ||||||
|         MDText text; |         Text text; | ||||||
|         bool success = text.parse(line.substring_view(offset, line.length() - offset)); |         bool success = text.parse(line.substring_view(offset, line.length() - offset)); | ||||||
|         ASSERT(success); |         ASSERT(success); | ||||||
|         m_items.append(move(text)); |         m_items.append(move(text)); | ||||||
|  | @ -113,3 +115,5 @@ bool MDList::parse(Vector<StringView>::ConstIterator& lines) | ||||||
| 
 | 
 | ||||||
|     return !first; |     return !first; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -27,12 +27,14 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #include <AK/Vector.h> | #include <AK/Vector.h> | ||||||
| #include <LibMarkdown/MDBlock.h> | #include <LibMarkdown/Block.h> | ||||||
| #include <LibMarkdown/MDText.h> | #include <LibMarkdown/Text.h> | ||||||
| 
 | 
 | ||||||
| class MDList final : public MDBlock { | namespace Markdown { | ||||||
|  | 
 | ||||||
|  | class List final : public Block { | ||||||
| public: | public: | ||||||
|     virtual ~MDList() override {} |     virtual ~List() override {} | ||||||
| 
 | 
 | ||||||
|     virtual String render_to_html() const override; |     virtual String render_to_html() const override; | ||||||
|     virtual String render_for_terminal() const override; |     virtual String render_for_terminal() const override; | ||||||
|  | @ -40,6 +42,8 @@ public: | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     // TODO: List items should be considered blocks of their own kind.
 |     // TODO: List items should be considered blocks of their own kind.
 | ||||||
|     Vector<MDText> m_items; |     Vector<Text> m_items; | ||||||
|     bool m_is_ordered { false }; |     bool m_is_ordered { false }; | ||||||
| }; | }; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -1,10 +1,10 @@ | ||||||
| OBJS = \
 | OBJS = \
 | ||||||
|     MDDocument.o \
 |     Document.o \
 | ||||||
|     MDParagraph.o \
 |     Paragraph.o \
 | ||||||
|     MDHeading.o \
 |     Heading.o \
 | ||||||
|     MDCodeBlock.o \
 |     CodeBlock.o \
 | ||||||
|     MDList.o \
 |     List.o \
 | ||||||
|     MDText.o |     Text.o | ||||||
| 
 | 
 | ||||||
| LIBRARY = libmarkdown.a | LIBRARY = libmarkdown.a | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -25,9 +25,11 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <AK/StringBuilder.h> | #include <AK/StringBuilder.h> | ||||||
| #include <LibMarkdown/MDParagraph.h> | #include <LibMarkdown/Paragraph.h> | ||||||
| 
 | 
 | ||||||
| String MDParagraph::render_to_html() const | namespace Markdown { | ||||||
|  | 
 | ||||||
|  | String Paragraph::render_to_html() const | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
|     builder.appendf("<p>"); |     builder.appendf("<p>"); | ||||||
|  | @ -36,7 +38,7 @@ String MDParagraph::render_to_html() const | ||||||
|     return builder.build(); |     return builder.build(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| String MDParagraph::render_for_terminal() const | String Paragraph::render_for_terminal() const | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
|     builder.append(m_text.render_for_terminal()); |     builder.append(m_text.render_for_terminal()); | ||||||
|  | @ -44,7 +46,7 @@ String MDParagraph::render_for_terminal() const | ||||||
|     return builder.build(); |     return builder.build(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool MDParagraph::parse(Vector<StringView>::ConstIterator& lines) | bool Paragraph::parse(Vector<StringView>::ConstIterator& lines) | ||||||
| { | { | ||||||
|     if (lines.is_end()) |     if (lines.is_end()) | ||||||
|         return false; |         return false; | ||||||
|  | @ -90,3 +92,5 @@ bool MDParagraph::parse(Vector<StringView>::ConstIterator& lines) | ||||||
|     ASSERT(success); |     ASSERT(success); | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -26,17 +26,21 @@ | ||||||
| 
 | 
 | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #include <LibMarkdown/MDBlock.h> | #include <LibMarkdown/Block.h> | ||||||
| #include <LibMarkdown/MDText.h> | #include <LibMarkdown/Text.h> | ||||||
| 
 | 
 | ||||||
| class MDParagraph final : public MDBlock { | namespace Markdown { | ||||||
|  | 
 | ||||||
|  | class Paragraph final : public Block { | ||||||
| public: | public: | ||||||
|     virtual ~MDParagraph() override {} |     virtual ~Paragraph() override {} | ||||||
| 
 | 
 | ||||||
|     virtual String render_to_html() const override; |     virtual String render_to_html() const override; | ||||||
|     virtual String render_for_terminal() const override; |     virtual String render_for_terminal() const override; | ||||||
|     virtual bool parse(Vector<StringView>::ConstIterator& lines) override; |     virtual bool parse(Vector<StringView>::ConstIterator& lines) override; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     MDText m_text; |     Text m_text; | ||||||
| }; | }; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -25,9 +25,11 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <AK/StringBuilder.h> | #include <AK/StringBuilder.h> | ||||||
| #include <LibMarkdown/MDText.h> | #include <LibMarkdown/Text.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
| 
 | 
 | ||||||
|  | namespace Markdown { | ||||||
|  | 
 | ||||||
| static String unescape(const StringView& text) | static String unescape(const StringView& text) | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
|  | @ -42,7 +44,7 @@ static String unescape(const StringView& text) | ||||||
|     return builder.build(); |     return builder.build(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| String MDText::render_to_html() const | String Text::render_to_html() const | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
| 
 | 
 | ||||||
|  | @ -110,7 +112,7 @@ String MDText::render_to_html() const | ||||||
|     return builder.build(); |     return builder.build(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| String MDText::render_for_terminal() const | String Text::render_for_terminal() const | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
| 
 | 
 | ||||||
|  | @ -149,7 +151,7 @@ String MDText::render_for_terminal() const | ||||||
|     return builder.build(); |     return builder.build(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool MDText::parse(const StringView& str) | bool Text::parse(const StringView& str) | ||||||
| { | { | ||||||
|     Style current_style; |     Style current_style; | ||||||
|     size_t current_span_start = 0; |     size_t current_span_start = 0; | ||||||
|  | @ -229,3 +231,5 @@ bool MDText::parse(const StringView& str) | ||||||
| 
 | 
 | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -29,7 +29,9 @@ | ||||||
| #include <AK/String.h> | #include <AK/String.h> | ||||||
| #include <AK/Vector.h> | #include <AK/Vector.h> | ||||||
| 
 | 
 | ||||||
| class MDText final { | namespace Markdown { | ||||||
|  | 
 | ||||||
|  | class Text final { | ||||||
| public: | public: | ||||||
|     struct Style { |     struct Style { | ||||||
|         bool emph { false }; |         bool emph { false }; | ||||||
|  | @ -53,3 +55,5 @@ public: | ||||||
| private: | private: | ||||||
|     Vector<Span> m_spans; |     Vector<Span> m_spans; | ||||||
| }; | }; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -28,7 +28,7 @@ | ||||||
| #include <AK/String.h> | #include <AK/String.h> | ||||||
| #include <LibCore/ArgsParser.h> | #include <LibCore/ArgsParser.h> | ||||||
| #include <LibCore/File.h> | #include <LibCore/File.h> | ||||||
| #include <LibMarkdown/MDDocument.h> | #include <LibMarkdown/Document.h> | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
| 
 | 
 | ||||||
|  | @ -101,7 +101,7 @@ int main(int argc, char* argv[]) | ||||||
| 
 | 
 | ||||||
|     printf("%s(%s)\t\tSerenityOS manual\n", name, section); |     printf("%s(%s)\t\tSerenityOS manual\n", name, section); | ||||||
| 
 | 
 | ||||||
|     MDDocument document; |     Markdown::Document document; | ||||||
|     bool success = document.parse(source); |     bool success = document.parse(source); | ||||||
|     ASSERT(success); |     ASSERT(success); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -27,7 +27,7 @@ | ||||||
| #include <AK/ByteBuffer.h> | #include <AK/ByteBuffer.h> | ||||||
| #include <AK/String.h> | #include <AK/String.h> | ||||||
| #include <LibCore/File.h> | #include <LibCore/File.h> | ||||||
| #include <LibMarkdown/MDDocument.h> | #include <LibMarkdown/Document.h> | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
| 
 | 
 | ||||||
|  | @ -70,7 +70,7 @@ int main(int argc, char* argv[]) | ||||||
|     dbg() << "Read size " << buffer.size(); |     dbg() << "Read size " << buffer.size(); | ||||||
| 
 | 
 | ||||||
|     auto input = String::copy(buffer); |     auto input = String::copy(buffer); | ||||||
|     MDDocument document; |     Markdown::Document document; | ||||||
|     success = document.parse(input); |     success = document.parse(input); | ||||||
| 
 | 
 | ||||||
|     if (!success) { |     if (!success) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling