summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-04-28 21:04:25 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-28 21:04:25 +0200
commitea204ef05b99b65f7d7630936e891b595012f9f5 (patch)
tree54899bb6aabe6c71fae2cace16e7bff7c3c0899a
parent104969a9f5c4eaacbdc89b548729a8edeada5fff (diff)
downloadserenity-ea204ef05b99b65f7d7630936e891b595012f9f5.zip
LibMarkdown: Drop MD prefixes and move into "Markdown" namespace :^)
-rw-r--r--Applications/Help/main.cpp4
-rw-r--r--DevTools/HackStudio/Editor.cpp4
-rw-r--r--Libraries/LibMarkdown/Block.h (renamed from Libraries/LibMarkdown/MDBlock.h)9
-rw-r--r--Libraries/LibMarkdown/CodeBlock.cpp (renamed from Libraries/LibMarkdown/MDCodeBlock.cpp)20
-rw-r--r--Libraries/LibMarkdown/CodeBlock.h (renamed from Libraries/LibMarkdown/MDCodeBlock.h)16
-rw-r--r--Libraries/LibMarkdown/Document.cpp (renamed from Libraries/LibMarkdown/MDDocument.cpp)28
-rw-r--r--Libraries/LibMarkdown/Document.h (renamed from Libraries/LibMarkdown/MDDocument.h)10
-rw-r--r--Libraries/LibMarkdown/Heading.cpp (renamed from Libraries/LibMarkdown/MDHeading.cpp)12
-rw-r--r--Libraries/LibMarkdown/Heading.h (renamed from Libraries/LibMarkdown/MDHeading.h)14
-rw-r--r--Libraries/LibMarkdown/List.cpp (renamed from Libraries/LibMarkdown/MDList.cpp)14
-rw-r--r--Libraries/LibMarkdown/List.h (renamed from Libraries/LibMarkdown/MDList.h)14
-rw-r--r--Libraries/LibMarkdown/Makefile12
-rw-r--r--Libraries/LibMarkdown/Paragraph.cpp (renamed from Libraries/LibMarkdown/MDParagraph.cpp)12
-rw-r--r--Libraries/LibMarkdown/Paragraph.h (renamed from Libraries/LibMarkdown/MDParagraph.h)14
-rw-r--r--Libraries/LibMarkdown/Text.cpp (renamed from Libraries/LibMarkdown/MDText.cpp)12
-rw-r--r--Libraries/LibMarkdown/Text.h (renamed from Libraries/LibMarkdown/MDText.h)6
-rw-r--r--Userland/man.cpp4
-rw-r--r--Userland/md.cpp4
18 files changed, 131 insertions, 78 deletions
diff --git a/Applications/Help/main.cpp b/Applications/Help/main.cpp
index 81767dee17..057faa17b1 100644
--- a/Applications/Help/main.cpp
+++ b/Applications/Help/main.cpp
@@ -41,7 +41,7 @@
#include <LibGUI/ToolBarContainer.h>
#include <LibGUI/TreeView.h>
#include <LibGUI/Window.h>
-#include <LibMarkdown/MDDocument.h>
+#include <LibMarkdown/Document.h>
#include <LibWeb/HtmlView.h>
#include <LibWeb/Layout/LayoutNode.h>
#include <LibWeb/Parser/CSSParser.h>
@@ -128,7 +128,7 @@ int main(int argc, char* argv[])
auto buffer = file->read_all();
StringView source { (const char*)buffer.data(), buffer.size() };
- MDDocument md_document;
+ Markdown::Document md_document;
bool success = md_document.parse(source);
ASSERT(success);
diff --git a/DevTools/HackStudio/Editor.cpp b/DevTools/HackStudio/Editor.cpp
index 2813750949..9acbfef12e 100644
--- a/DevTools/HackStudio/Editor.cpp
+++ b/DevTools/HackStudio/Editor.cpp
@@ -36,7 +36,7 @@
#include <LibGUI/ScrollBar.h>
#include <LibGUI/SyntaxHighlighter.h>
#include <LibGUI/Window.h>
-#include <LibMarkdown/MDDocument.h>
+#include <LibMarkdown/Document.h>
#include <LibWeb/DOM/ElementFactory.h>
#include <LibWeb/DOM/HTMLHeadElement.h>
#include <LibWeb/DOM/Text.h>
@@ -166,7 +166,7 @@ void Editor::show_documentation_tooltip_if_available(const String& hovered_token
return;
}
- MDDocument man_document;
+ Markdown::Document man_document;
bool success = man_document.parse(file->read_all());
if (!success) {
diff --git a/Libraries/LibMarkdown/MDBlock.h b/Libraries/LibMarkdown/Block.h
index facceb359a..1b6e3cc3af 100644
--- a/Libraries/LibMarkdown/MDBlock.h
+++ b/Libraries/LibMarkdown/Block.h
@@ -26,13 +26,18 @@
#pragma once
+#include <AK/StringView.h>
#include <AK/Vector.h>
-class MDBlock {
+namespace Markdown {
+
+class Block {
public:
- virtual ~MDBlock() {}
+ virtual ~Block() {}
virtual String render_to_html() const = 0;
virtual String render_for_terminal() const = 0;
virtual bool parse(Vector<StringView>::ConstIterator& lines) = 0;
};
+
+}
diff --git a/Libraries/LibMarkdown/MDCodeBlock.cpp b/Libraries/LibMarkdown/CodeBlock.cpp
index 683285d670..c940cd5322 100644
--- a/Libraries/LibMarkdown/MDCodeBlock.cpp
+++ b/Libraries/LibMarkdown/CodeBlock.cpp
@@ -25,28 +25,30 @@
*/
#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())
return {};
return m_style_spec.spans()[0].style;
}
-String MDCodeBlock::style_language() const
+String CodeBlock::style_language() const
{
if (m_style_spec.spans().is_empty())
return {};
return m_style_spec.spans()[0].text;
}
-String MDCodeBlock::render_to_html() const
+String CodeBlock::render_to_html() const
{
StringBuilder builder;
String style_language = this->style_language();
- MDText::Style style = this->style();
+ Text::Style style = this->style();
if (style.strong)
builder.append("<b>");
@@ -81,11 +83,11 @@ String MDCodeBlock::render_to_html() const
return builder.build();
}
-String MDCodeBlock::render_for_terminal() const
+String CodeBlock::render_for_terminal() const
{
StringBuilder builder;
- MDText::Style style = this->style();
+ Text::Style style = this->style();
bool needs_styling = style.strong || style.emph;
if (needs_styling) {
builder.append("\033[");
@@ -112,7 +114,7 @@ String MDCodeBlock::render_for_terminal() const
return builder.build();
}
-bool MDCodeBlock::parse(Vector<StringView>::ConstIterator& lines)
+bool CodeBlock::parse(Vector<StringView>::ConstIterator& lines)
{
if (lines.is_end())
return false;
@@ -159,3 +161,5 @@ bool MDCodeBlock::parse(Vector<StringView>::ConstIterator& lines)
m_code = builder.build();
return true;
}
+
+}
diff --git a/Libraries/LibMarkdown/MDCodeBlock.h b/Libraries/LibMarkdown/CodeBlock.h
index 3d1ca9bf88..2410e9b0e4 100644
--- a/Libraries/LibMarkdown/MDCodeBlock.h
+++ b/Libraries/LibMarkdown/CodeBlock.h
@@ -26,12 +26,14 @@
#pragma once
-#include <LibMarkdown/MDBlock.h>
-#include <LibMarkdown/MDText.h>
+#include <LibMarkdown/Block.h>
+#include <LibMarkdown/Text.h>
-class MDCodeBlock final : public MDBlock {
+namespace Markdown {
+
+class CodeBlock final : public Block {
public:
- virtual ~MDCodeBlock() override {}
+ virtual ~CodeBlock() override {}
virtual String render_to_html() const override;
virtual String render_for_terminal() const override;
@@ -39,8 +41,10 @@ public:
private:
String style_language() const;
- MDText::Style style() const;
+ Text::Style style() const;
String m_code;
- MDText m_style_spec;
+ Text m_style_spec;
};
+
+}
diff --git a/Libraries/LibMarkdown/MDDocument.cpp b/Libraries/LibMarkdown/Document.cpp
index dae3ff2610..408bcf1435 100644
--- a/Libraries/LibMarkdown/MDDocument.cpp
+++ b/Libraries/LibMarkdown/Document.cpp
@@ -25,13 +25,15 @@
*/
#include <AK/StringBuilder.h>
-#include <LibMarkdown/MDCodeBlock.h>
-#include <LibMarkdown/MDDocument.h>
-#include <LibMarkdown/MDHeading.h>
-#include <LibMarkdown/MDList.h>
-#include <LibMarkdown/MDParagraph.h>
+#include <LibMarkdown/CodeBlock.h>
+#include <LibMarkdown/Document.h>
+#include <LibMarkdown/Heading.h>
+#include <LibMarkdown/List.h>
+#include <LibMarkdown/Paragraph.h>
-String MDDocument::render_to_html() const
+namespace Markdown {
+
+String Document::render_to_html() const
{
StringBuilder builder;
@@ -50,7 +52,7 @@ String MDDocument::render_to_html() const
return builder.build();
}
-String MDDocument::render_for_terminal() const
+String Document::render_for_terminal() const
{
StringBuilder builder;
@@ -62,10 +64,10 @@ String MDDocument::render_for_terminal() const
return builder.build();
}
-template<typename Block>
-static bool helper(Vector<StringView>::ConstIterator& lines, NonnullOwnPtrVector<MDBlock>& blocks)
+template<typename BlockType>
+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);
if (!success)
return false;
@@ -73,7 +75,7 @@ static bool helper(Vector<StringView>::ConstIterator& lines, NonnullOwnPtrVector
return true;
}
-bool MDDocument::parse(const StringView& str)
+bool Document::parse(const StringView& str)
{
const Vector<StringView> lines_vec = str.lines();
auto lines = lines_vec.begin();
@@ -87,9 +89,11 @@ bool MDDocument::parse(const StringView& str)
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)
return false;
}
}
+
+}
diff --git a/Libraries/LibMarkdown/MDDocument.h b/Libraries/LibMarkdown/Document.h
index 549066ae72..3cf4c769cb 100644
--- a/Libraries/LibMarkdown/MDDocument.h
+++ b/Libraries/LibMarkdown/Document.h
@@ -28,9 +28,11 @@
#include <AK/NonnullOwnPtrVector.h>
#include <AK/String.h>
-#include <LibMarkdown/MDBlock.h>
+#include <LibMarkdown/Block.h>
-class MDDocument final {
+namespace Markdown {
+
+class Document final {
public:
String render_to_html() const;
String render_for_terminal() const;
@@ -38,5 +40,7 @@ public:
bool parse(const StringView&);
private:
- NonnullOwnPtrVector<MDBlock> m_blocks;
+ NonnullOwnPtrVector<Block> m_blocks;
};
+
+}
diff --git a/Libraries/LibMarkdown/MDHeading.cpp b/Libraries/LibMarkdown/Heading.cpp
index 4085b8fedf..7997a0e0fd 100644
--- a/Libraries/LibMarkdown/MDHeading.cpp
+++ b/Libraries/LibMarkdown/Heading.cpp
@@ -25,9 +25,11 @@
*/
#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;
builder.appendf("<h%d>", m_level);
@@ -36,7 +38,7 @@ String MDHeading::render_to_html() const
return builder.build();
}
-String MDHeading::render_for_terminal() const
+String Heading::render_for_terminal() const
{
StringBuilder builder;
@@ -57,7 +59,7 @@ String MDHeading::render_for_terminal() const
return builder.build();
}
-bool MDHeading::parse(Vector<StringView>::ConstIterator& lines)
+bool Heading::parse(Vector<StringView>::ConstIterator& lines)
{
if (lines.is_end())
return false;
@@ -78,3 +80,5 @@ bool MDHeading::parse(Vector<StringView>::ConstIterator& lines)
++lines;
return true;
}
+
+}
diff --git a/Libraries/LibMarkdown/MDHeading.h b/Libraries/LibMarkdown/Heading.h
index 1be362c1dd..92f5ce71ef 100644
--- a/Libraries/LibMarkdown/MDHeading.h
+++ b/Libraries/LibMarkdown/Heading.h
@@ -28,18 +28,22 @@
#include <AK/StringView.h>
#include <AK/Vector.h>
-#include <LibMarkdown/MDBlock.h>
-#include <LibMarkdown/MDText.h>
+#include <LibMarkdown/Block.h>
+#include <LibMarkdown/Text.h>
-class MDHeading final : public MDBlock {
+namespace Markdown {
+
+class Heading final : public Block {
public:
- virtual ~MDHeading() override {}
+ virtual ~Heading() override {}
virtual String render_to_html() const override;
virtual String render_for_terminal() const override;
virtual bool parse(Vector<StringView>::ConstIterator& lines) override;
private:
- MDText m_text;
+ Text m_text;
int m_level { -1 };
};
+
+}
diff --git a/Libraries/LibMarkdown/MDList.cpp b/Libraries/LibMarkdown/List.cpp
index e892f98249..bf3bd14f88 100644
--- a/Libraries/LibMarkdown/MDList.cpp
+++ b/Libraries/LibMarkdown/List.cpp
@@ -25,9 +25,11 @@
*/
#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;
@@ -45,7 +47,7 @@ String MDList::render_to_html() const
return builder.build();
}
-String MDList::render_for_terminal() const
+String List::render_for_terminal() const
{
StringBuilder builder;
@@ -64,7 +66,7 @@ String MDList::render_for_terminal() const
return builder.build();
}
-bool MDList::parse(Vector<StringView>::ConstIterator& lines)
+bool List::parse(Vector<StringView>::ConstIterator& lines)
{
bool first = true;
while (true) {
@@ -104,7 +106,7 @@ bool MDList::parse(Vector<StringView>::ConstIterator& lines)
return false;
first = false;
- MDText text;
+ Text text;
bool success = text.parse(line.substring_view(offset, line.length() - offset));
ASSERT(success);
m_items.append(move(text));
@@ -113,3 +115,5 @@ bool MDList::parse(Vector<StringView>::ConstIterator& lines)
return !first;
}
+
+}
diff --git a/Libraries/LibMarkdown/MDList.h b/Libraries/LibMarkdown/List.h
index ec3b17f9c3..b66e5c8495 100644
--- a/Libraries/LibMarkdown/MDList.h
+++ b/Libraries/LibMarkdown/List.h
@@ -27,12 +27,14 @@
#pragma once
#include <AK/Vector.h>
-#include <LibMarkdown/MDBlock.h>
-#include <LibMarkdown/MDText.h>
+#include <LibMarkdown/Block.h>
+#include <LibMarkdown/Text.h>
-class MDList final : public MDBlock {
+namespace Markdown {
+
+class List final : public Block {
public:
- virtual ~MDList() override {}
+ virtual ~List() override {}
virtual String render_to_html() const override;
virtual String render_for_terminal() const override;
@@ -40,6 +42,8 @@ public:
private:
// TODO: List items should be considered blocks of their own kind.
- Vector<MDText> m_items;
+ Vector<Text> m_items;
bool m_is_ordered { false };
};
+
+}
diff --git a/Libraries/LibMarkdown/Makefile b/Libraries/LibMarkdown/Makefile
index 7828776bd4..b234cb7da5 100644
--- a/Libraries/LibMarkdown/Makefile
+++ b/Libraries/LibMarkdown/Makefile
@@ -1,10 +1,10 @@
OBJS = \
- MDDocument.o \
- MDParagraph.o \
- MDHeading.o \
- MDCodeBlock.o \
- MDList.o \
- MDText.o
+ Document.o \
+ Paragraph.o \
+ Heading.o \
+ CodeBlock.o \
+ List.o \
+ Text.o
LIBRARY = libmarkdown.a
diff --git a/Libraries/LibMarkdown/MDParagraph.cpp b/Libraries/LibMarkdown/Paragraph.cpp
index 12b7eecf73..c1c9208900 100644
--- a/Libraries/LibMarkdown/MDParagraph.cpp
+++ b/Libraries/LibMarkdown/Paragraph.cpp
@@ -25,9 +25,11 @@
*/
#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;
builder.appendf("<p>");
@@ -36,7 +38,7 @@ String MDParagraph::render_to_html() const
return builder.build();
}
-String MDParagraph::render_for_terminal() const
+String Paragraph::render_for_terminal() const
{
StringBuilder builder;
builder.append(m_text.render_for_terminal());
@@ -44,7 +46,7 @@ String MDParagraph::render_for_terminal() const
return builder.build();
}
-bool MDParagraph::parse(Vector<StringView>::ConstIterator& lines)
+bool Paragraph::parse(Vector<StringView>::ConstIterator& lines)
{
if (lines.is_end())
return false;
@@ -90,3 +92,5 @@ bool MDParagraph::parse(Vector<StringView>::ConstIterator& lines)
ASSERT(success);
return true;
}
+
+}
diff --git a/Libraries/LibMarkdown/MDParagraph.h b/Libraries/LibMarkdown/Paragraph.h
index 123e7b4182..98b3b9192b 100644
--- a/Libraries/LibMarkdown/MDParagraph.h
+++ b/Libraries/LibMarkdown/Paragraph.h
@@ -26,17 +26,21 @@
#pragma once
-#include <LibMarkdown/MDBlock.h>
-#include <LibMarkdown/MDText.h>
+#include <LibMarkdown/Block.h>
+#include <LibMarkdown/Text.h>
-class MDParagraph final : public MDBlock {
+namespace Markdown {
+
+class Paragraph final : public Block {
public:
- virtual ~MDParagraph() override {}
+ virtual ~Paragraph() override {}
virtual String render_to_html() const override;
virtual String render_for_terminal() const override;
virtual bool parse(Vector<StringView>::ConstIterator& lines) override;
private:
- MDText m_text;
+ Text m_text;
};
+
+}
diff --git a/Libraries/LibMarkdown/MDText.cpp b/Libraries/LibMarkdown/Text.cpp
index cb67d0840d..6bfe89d69c 100644
--- a/Libraries/LibMarkdown/MDText.cpp
+++ b/Libraries/LibMarkdown/Text.cpp
@@ -25,9 +25,11 @@
*/
#include <AK/StringBuilder.h>
-#include <LibMarkdown/MDText.h>
+#include <LibMarkdown/Text.h>
#include <string.h>
+namespace Markdown {
+
static String unescape(const StringView& text)
{
StringBuilder builder;
@@ -42,7 +44,7 @@ static String unescape(const StringView& text)
return builder.build();
}
-String MDText::render_to_html() const
+String Text::render_to_html() const
{
StringBuilder builder;
@@ -110,7 +112,7 @@ String MDText::render_to_html() const
return builder.build();
}
-String MDText::render_for_terminal() const
+String Text::render_for_terminal() const
{
StringBuilder builder;
@@ -149,7 +151,7 @@ String MDText::render_for_terminal() const
return builder.build();
}
-bool MDText::parse(const StringView& str)
+bool Text::parse(const StringView& str)
{
Style current_style;
size_t current_span_start = 0;
@@ -229,3 +231,5 @@ bool MDText::parse(const StringView& str)
return true;
}
+
+}
diff --git a/Libraries/LibMarkdown/MDText.h b/Libraries/LibMarkdown/Text.h
index a4f47b5e53..0d3ee89559 100644
--- a/Libraries/LibMarkdown/MDText.h
+++ b/Libraries/LibMarkdown/Text.h
@@ -29,7 +29,9 @@
#include <AK/String.h>
#include <AK/Vector.h>
-class MDText final {
+namespace Markdown {
+
+class Text final {
public:
struct Style {
bool emph { false };
@@ -53,3 +55,5 @@ public:
private:
Vector<Span> m_spans;
};
+
+}
diff --git a/Userland/man.cpp b/Userland/man.cpp
index 47c3d7d9d9..36900a984f 100644
--- a/Userland/man.cpp
+++ b/Userland/man.cpp
@@ -28,7 +28,7 @@
#include <AK/String.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
-#include <LibMarkdown/MDDocument.h>
+#include <LibMarkdown/Document.h>
#include <stdio.h>
#include <unistd.h>
@@ -101,7 +101,7 @@ int main(int argc, char* argv[])
printf("%s(%s)\t\tSerenityOS manual\n", name, section);
- MDDocument document;
+ Markdown::Document document;
bool success = document.parse(source);
ASSERT(success);
diff --git a/Userland/md.cpp b/Userland/md.cpp
index d9e77a8c22..17187fc06e 100644
--- a/Userland/md.cpp
+++ b/Userland/md.cpp
@@ -27,7 +27,7 @@
#include <AK/ByteBuffer.h>
#include <AK/String.h>
#include <LibCore/File.h>
-#include <LibMarkdown/MDDocument.h>
+#include <LibMarkdown/Document.h>
#include <stdio.h>
#include <string.h>
@@ -70,7 +70,7 @@ int main(int argc, char* argv[])
dbg() << "Read size " << buffer.size();
auto input = String::copy(buffer);
- MDDocument document;
+ Markdown::Document document;
success = document.parse(input);
if (!success) {