Start adding markdown conversion to site generator.
This commit is contained in:
parent
f0091f9e04
commit
f44c79dc1f
31 changed files with 692 additions and 461 deletions
|
@ -1,6 +1,7 @@
|
|||
#include "TemplatingEngine.h"
|
||||
|
||||
#include "Directory.h"
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -13,10 +14,11 @@ TemplatingEngine::TemplatingEngine(const Path& workingDirectory)
|
|||
void TemplatingEngine::loadTemplateFiles()
|
||||
{
|
||||
const auto files = Directory::getFilesWithExtension(mWorkingDirectory, mTemplateExtension);
|
||||
for (const auto& file : files)
|
||||
for (const auto& path : files)
|
||||
{
|
||||
mTemplateFiles.push_back(std::make_unique<TemplateFile>(file));
|
||||
mTemplateFiles[path.stem().string()] = std::make_unique<TemplateFile>(path);
|
||||
}
|
||||
MLOG_INFO("Found: " << mTemplateFiles.size() << " templates in " << mWorkingDirectory);
|
||||
}
|
||||
|
||||
std::string TemplatingEngine::processTemplate(const std::string& name)
|
||||
|
@ -35,15 +37,7 @@ TemplateFile* TemplatingEngine::getTemplateFile(const Path& path)
|
|||
|
||||
TemplateFile* TemplatingEngine::getTemplateFile(const std::string& name)
|
||||
{
|
||||
//std::cout << "Looking for template file with name: " << name << std::endl;
|
||||
for (const auto& file : mTemplateFiles)
|
||||
{
|
||||
if (file->getName() == name)
|
||||
{
|
||||
return file.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
return mTemplateFiles[name].get();
|
||||
}
|
||||
|
||||
std::string TemplatingEngine::processTemplate(TemplateFile* file, TemplateNode* parent)
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
class TemplatingEngine
|
||||
{
|
||||
|
@ -14,7 +16,6 @@ public:
|
|||
void loadTemplateFiles();
|
||||
|
||||
std::string processTemplate(const std::string& name);
|
||||
|
||||
private:
|
||||
TemplateFile* getTemplateFile(const std::string& name);
|
||||
TemplateFile* getTemplateFile(const Path& path);
|
||||
|
@ -22,7 +23,7 @@ private:
|
|||
|
||||
std::string processTemplate(TemplateFile* file, TemplateNode* parent = nullptr);
|
||||
|
||||
std::vector<std::unique_ptr<TemplateFile> > mTemplateFiles;
|
||||
std::unordered_map<std::string, std::unique_ptr<TemplateFile> > mTemplateFiles;
|
||||
Path mWorkingDirectory;
|
||||
std::string mTemplateExtension{ ".html" };
|
||||
};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
set(MODULE_NAME core)
|
||||
|
||||
list(APPEND core_HEADERS
|
||||
AbstractApp.h
|
||||
Dictionary.h
|
||||
|
@ -8,6 +10,7 @@ list(APPEND core_HEADERS
|
|||
file_utilities/Directory.h
|
||||
file_utilities/File.h
|
||||
file_utilities/FileFormats.h
|
||||
file_utilities/PathUtils.h
|
||||
StringUtils.h
|
||||
http/HttpResponse.h
|
||||
serializers/TomlReader.h
|
||||
|
@ -25,6 +28,7 @@ list(APPEND core_LIB_INCLUDES
|
|||
file_utilities/Directory.cpp
|
||||
file_utilities/File.cpp
|
||||
file_utilities/FileFormats.cpp
|
||||
file_utilities/PathUtils.cpp
|
||||
memory/SharedMemory.cpp
|
||||
RandomUtils.cpp
|
||||
StringUtils.cpp
|
||||
|
@ -38,18 +42,17 @@ list(APPEND core_LIB_INCLUDES
|
|||
http/HttpRequest.cpp
|
||||
serializers/TomlReader.cpp)
|
||||
|
||||
# add the executable
|
||||
add_library(core SHARED ${core_LIB_INCLUDES} ${core_HEADERS})
|
||||
add_library(${MODULE_NAME} SHARED ${core_LIB_INCLUDES} ${core_HEADERS})
|
||||
|
||||
target_include_directories(core PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/file_utilities"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/loggers"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/memory"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/streams"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/http"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/data_structures"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/serializers"
|
||||
target_include_directories(${MODULE_NAME} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/file_utilities
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/loggers
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/streams
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/http
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/data_structures
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/serializers
|
||||
)
|
||||
set_target_properties( core PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
||||
set_property(TARGET core PROPERTY FOLDER src)
|
||||
set_target_properties( ${MODULE_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
||||
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER src)
|
|
@ -1,6 +1,6 @@
|
|||
#include "Directory.h"
|
||||
|
||||
std::vector<Path> Directory::getFilesWithExtension(const Path& path, const std::string& extension)
|
||||
std::vector<Path> Directory::getFilesWithExtension(const Path& path, const std::string& extension, bool recursive)
|
||||
{
|
||||
std::vector<Path> paths;
|
||||
if (std::filesystem::is_directory(path))
|
||||
|
@ -11,6 +11,11 @@ std::vector<Path> Directory::getFilesWithExtension(const Path& path, const std::
|
|||
{
|
||||
paths.push_back(entry.path());
|
||||
}
|
||||
else if(recursive && std::filesystem::is_directory(entry))
|
||||
{
|
||||
const auto child_paths = getFilesWithExtension(entry, extension, recursive);
|
||||
paths.insert(paths.end(), child_paths.begin(), child_paths.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
|
|
|
@ -9,5 +9,5 @@ class Directory
|
|||
{
|
||||
public:
|
||||
|
||||
static std::vector<Path> getFilesWithExtension(const Path& path, const std::string& extension);
|
||||
static std::vector<Path> getFilesWithExtension(const Path& path, const std::string& extension, bool recursive=false);
|
||||
};
|
||||
|
|
|
@ -197,11 +197,6 @@ std::string File::read()
|
|||
return buffer.str();
|
||||
}
|
||||
|
||||
std::string File::getBaseFilename(const Path& path)
|
||||
{
|
||||
return path.stem().string();
|
||||
}
|
||||
|
||||
std::string File::readText()
|
||||
{
|
||||
if (!pathExists())
|
||||
|
|
|
@ -20,7 +20,6 @@ public:
|
|||
};
|
||||
|
||||
public:
|
||||
|
||||
File(std::filesystem::path fullPath);
|
||||
|
||||
~File();
|
||||
|
@ -29,8 +28,6 @@ public:
|
|||
|
||||
std::string dumpBinary();
|
||||
|
||||
static std::string getBaseFilename(const Path& path);
|
||||
|
||||
std::string getExtension() const;
|
||||
|
||||
std::ifstream* getInHandle() const;
|
||||
|
|
33
src/core/file_utilities/PathUtils.cpp
Normal file
33
src/core/file_utilities/PathUtils.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "PathUtils.h"
|
||||
|
||||
|
||||
std::string PathUtils::getBaseFilename(const Path& path)
|
||||
{
|
||||
return path.stem().string();
|
||||
}
|
||||
|
||||
Path PathUtils::getRelativePath(const Path& input, const Path& relativeTo)
|
||||
{
|
||||
return std::filesystem::relative(input, relativeTo);
|
||||
}
|
||||
|
||||
std::string PathUtils::getPathDelimited(const Path& path, char delimiter)
|
||||
{
|
||||
std::string name;
|
||||
|
||||
unsigned count = 0;
|
||||
for(const auto& element : path)
|
||||
{
|
||||
if (count == 0)
|
||||
{
|
||||
name += element.stem().string();
|
||||
}
|
||||
else
|
||||
{
|
||||
name += delimiter + element.stem().string();
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
17
src/core/file_utilities/PathUtils.h
Normal file
17
src/core/file_utilities/PathUtils.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using Path = std::filesystem::path;
|
||||
|
||||
class PathUtils
|
||||
{
|
||||
public:
|
||||
static std::string getBaseFilename(const Path& path);
|
||||
|
||||
static Path getRelativePath(const Path& path, const Path& relativeTo);
|
||||
|
||||
static std::string getPathDelimited(const Path& path, char delimiter='-');
|
||||
};
|
|
@ -15,6 +15,10 @@ list(APPEND web_LIB_INCLUDES
|
|||
markdown/MarkdownConverter.cpp
|
||||
markdown/MarkdownDocument.h
|
||||
markdown/MarkdownDocument.cpp
|
||||
markdown/MarkdownComponents.h
|
||||
markdown/MarkdownComponents.cpp
|
||||
markdown/MarkdownElement.h
|
||||
markdown/MarkdownElement.cpp
|
||||
html/HtmlWriter.cpp
|
||||
html/HtmlDocument.cpp
|
||||
html/HtmlElement.cpp
|
||||
|
|
122
src/web/markdown/MarkdownComponents.cpp
Normal file
122
src/web/markdown/MarkdownComponents.cpp
Normal file
|
@ -0,0 +1,122 @@
|
|||
#include "MarkdownComponents.h"
|
||||
|
||||
MarkdownTextSpan::Type MarkdownTextSpan::getType() const
|
||||
{
|
||||
return Type::TEXT_SPAN;
|
||||
}
|
||||
|
||||
MarkdownParagraph::Type MarkdownParagraph::getType() const
|
||||
{
|
||||
return Type::PARAGRAPH;
|
||||
}
|
||||
|
||||
void MarkdownParagraph::addChild(std::unique_ptr<MarkdownInlineElement> child)
|
||||
{
|
||||
mChildren.push_back(std::move(child));
|
||||
}
|
||||
|
||||
std::size_t MarkdownParagraph::getNumChildren() const
|
||||
{
|
||||
return mChildren.size();
|
||||
}
|
||||
|
||||
MarkdownInlineElement* MarkdownParagraph::getChild(std::size_t idx) const
|
||||
{
|
||||
return mChildren[idx].get();
|
||||
}
|
||||
|
||||
MarkdownBulletItem::Type MarkdownBulletItem::getType() const
|
||||
{
|
||||
return Type::BULLET_ITEM;
|
||||
}
|
||||
|
||||
MarkdownBulletList::Type MarkdownBulletList::getType() const
|
||||
{
|
||||
return Type::BULLET_LIST;
|
||||
}
|
||||
|
||||
void MarkdownBulletList::addChild(std::unique_ptr<MarkdownBulletItem> child)
|
||||
{
|
||||
mChildren.push_back(std::move(child));
|
||||
}
|
||||
|
||||
std::size_t MarkdownBulletList::getNumChildren() const
|
||||
{
|
||||
return mChildren.size();
|
||||
}
|
||||
|
||||
MarkdownBulletItem* MarkdownBulletList::getChild(std::size_t idx) const
|
||||
{
|
||||
return mChildren[idx].get();
|
||||
}
|
||||
|
||||
MarkdownHeading::MarkdownHeading(unsigned level)
|
||||
: mLevel(level)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MarkdownHeading::Type MarkdownHeading::getType() const
|
||||
{
|
||||
return Type::HEADING;
|
||||
}
|
||||
|
||||
unsigned MarkdownHeading::getLevel() const
|
||||
{
|
||||
return mLevel;
|
||||
}
|
||||
|
||||
MarkdownInlineQuote::Type MarkdownInlineQuote::getType() const
|
||||
{
|
||||
return Type::INLINE_QUOTE;
|
||||
}
|
||||
|
||||
MarkdownLink::MarkdownLink(const std::string& target)
|
||||
: mTarget(target)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const std::string& MarkdownLink::getTarget() const
|
||||
{
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
MarkdownLink::Type MarkdownLink::getType() const
|
||||
{
|
||||
return Type::LINK;
|
||||
}
|
||||
|
||||
|
||||
MarkdownImage::MarkdownImage(const std::string& source, const std::string& alt)
|
||||
: mSource(source),
|
||||
mAlt(alt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MarkdownImage::Type MarkdownImage::getType() const
|
||||
{
|
||||
return Type::IMAGE;
|
||||
}
|
||||
|
||||
const std::string& MarkdownImage::getSource() const
|
||||
{
|
||||
return mSource;
|
||||
}
|
||||
|
||||
const std::string& MarkdownImage::getAlt() const
|
||||
{
|
||||
return mAlt;
|
||||
}
|
||||
|
||||
MarkdownMultilineQuote::MarkdownMultilineQuote(const std::string& tag)
|
||||
: mTag(tag)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MarkdownMultilineQuote::Type MarkdownMultilineQuote::getType() const
|
||||
{
|
||||
return Type::MULTILINE_QUOTE;
|
||||
}
|
124
src/web/markdown/MarkdownComponents.h
Normal file
124
src/web/markdown/MarkdownComponents.h
Normal file
|
@ -0,0 +1,124 @@
|
|||
#pragma once
|
||||
|
||||
#include "MarkdownElement.h"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
class MarkdownTextSpan : public MarkdownInlineElement
|
||||
{
|
||||
public:
|
||||
virtual ~MarkdownTextSpan() = default;
|
||||
|
||||
Type getType() const override;
|
||||
};
|
||||
|
||||
class MarkdownParagraph : public MarkdownElement
|
||||
{
|
||||
public:
|
||||
virtual ~MarkdownParagraph() = default;
|
||||
|
||||
Type getType() const override;
|
||||
|
||||
void addChild(std::unique_ptr<MarkdownInlineElement> child);
|
||||
|
||||
std::size_t getNumChildren() const;
|
||||
|
||||
MarkdownInlineElement* getChild(std::size_t idx) const;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<MarkdownInlineElement> > mChildren;
|
||||
};
|
||||
|
||||
class MarkdownBulletItem : public MarkdownElement
|
||||
{
|
||||
public:
|
||||
virtual ~MarkdownBulletItem() = default;
|
||||
|
||||
Type getType() const override;
|
||||
};
|
||||
|
||||
class MarkdownBulletList : public MarkdownElement
|
||||
{
|
||||
public:
|
||||
virtual ~MarkdownBulletList() = default;
|
||||
|
||||
Type getType() const override;
|
||||
|
||||
void addChild(std::unique_ptr<MarkdownBulletItem> child);
|
||||
|
||||
std::size_t getNumChildren() const;
|
||||
|
||||
MarkdownBulletItem* getChild(std::size_t idx) const;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<MarkdownBulletItem> > mChildren;
|
||||
};
|
||||
|
||||
class MarkdownHeading : public MarkdownElement
|
||||
{
|
||||
public:
|
||||
MarkdownHeading(unsigned level);
|
||||
|
||||
virtual ~MarkdownHeading() = default;
|
||||
|
||||
Type getType() const override;
|
||||
|
||||
unsigned getLevel() const;
|
||||
|
||||
private:
|
||||
unsigned mLevel{1};
|
||||
};
|
||||
|
||||
class MarkdownInlineQuote : public MarkdownInlineElement
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~MarkdownInlineQuote() = default;
|
||||
|
||||
Type getType() const override;
|
||||
};
|
||||
|
||||
class MarkdownLink : public MarkdownInlineElement
|
||||
{
|
||||
public:
|
||||
MarkdownLink(const std::string& target);
|
||||
|
||||
virtual ~MarkdownLink() = default;
|
||||
|
||||
const std::string& getTarget() const;
|
||||
|
||||
Type getType() const override;
|
||||
private:
|
||||
std::string mTarget;
|
||||
};
|
||||
|
||||
class MarkdownImage : public MarkdownInlineElement
|
||||
{
|
||||
public:
|
||||
MarkdownImage(const std::string& source, const std::string& alt);
|
||||
|
||||
virtual ~MarkdownImage() = default;
|
||||
|
||||
Type getType() const override;
|
||||
|
||||
const std::string& getSource() const;
|
||||
|
||||
const std::string& getAlt() const;
|
||||
|
||||
private:
|
||||
std::string mSource;
|
||||
std::string mAlt;
|
||||
};
|
||||
|
||||
class MarkdownMultilineQuote : public MarkdownElement
|
||||
{
|
||||
public:
|
||||
MarkdownMultilineQuote(const std::string& tag);
|
||||
|
||||
virtual ~MarkdownMultilineQuote() = default;
|
||||
|
||||
Type getType() const override;
|
||||
private:
|
||||
std::string mTag;
|
||||
};
|
|
@ -4,6 +4,8 @@
|
|||
#include "HtmlElement.h"
|
||||
#include "HtmlParagraphElement.h"
|
||||
#include "HtmlTextRun.h"
|
||||
#include "MarkdownElement.h"
|
||||
#include "MarkdownComponents.h"
|
||||
|
||||
#include "MarkdownDocument.h"
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#include "MarkdownDocument.h"
|
||||
|
||||
#include "MarkdownElement.h"
|
||||
|
||||
void MarkdownDocument::addElement(std::unique_ptr<MarkdownElement> element)
|
||||
{
|
||||
mElements.push_back(std::move(element));
|
||||
}
|
||||
|
||||
std::size_t MarkdownDocument::getNumElements() const
|
||||
{
|
||||
return mElements.size();
|
||||
}
|
||||
|
||||
MarkdownElement* MarkdownDocument::getElement(std::size_t idx) const
|
||||
{
|
||||
return mElements[idx].get();
|
||||
}
|
|
@ -3,262 +3,16 @@
|
|||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
class MarkdownElement
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
HEADING,
|
||||
PARAGRAPH,
|
||||
TEXT_SPAN,
|
||||
INLINE_CODE,
|
||||
MULTILINE_CODE,
|
||||
INLINE_QUOTE,
|
||||
MULTILINE_QUOTE,
|
||||
INLINE_SPECIAL,
|
||||
MULTILINE_SPECIAL,
|
||||
LINK,
|
||||
IMAGE,
|
||||
BULLET_ITEM,
|
||||
BULLET_LIST
|
||||
};
|
||||
|
||||
virtual ~MarkdownElement() = default;
|
||||
|
||||
void appendTextContent(const std::string& content)
|
||||
{
|
||||
mTextContent += content;
|
||||
}
|
||||
|
||||
const std::string& getTextContent() const
|
||||
{
|
||||
return mTextContent;
|
||||
}
|
||||
|
||||
virtual Type getType() const = 0;
|
||||
private:
|
||||
std::string mTextContent;
|
||||
};
|
||||
|
||||
class MarkdownInlineElement : public MarkdownElement
|
||||
{
|
||||
public:
|
||||
virtual ~MarkdownInlineElement() = default;
|
||||
};
|
||||
|
||||
class MarkdownTextSpan : public MarkdownInlineElement
|
||||
{
|
||||
public:
|
||||
virtual ~MarkdownTextSpan() = default;
|
||||
|
||||
Type getType() const override
|
||||
{
|
||||
return Type::TEXT_SPAN;
|
||||
}
|
||||
};
|
||||
|
||||
class MarkdownParagraph : public MarkdownElement
|
||||
{
|
||||
public:
|
||||
virtual ~MarkdownParagraph() = default;
|
||||
|
||||
Type getType() const override
|
||||
{
|
||||
return Type::PARAGRAPH;
|
||||
}
|
||||
|
||||
void addChild(std::unique_ptr<MarkdownInlineElement> child)
|
||||
{
|
||||
mChildren.push_back(std::move(child));
|
||||
}
|
||||
|
||||
std::size_t getNumChildren() const
|
||||
{
|
||||
return mChildren.size();
|
||||
}
|
||||
|
||||
MarkdownInlineElement* getChild(std::size_t idx) const
|
||||
{
|
||||
return mChildren[idx].get();
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<MarkdownInlineElement> > mChildren;
|
||||
};
|
||||
|
||||
class MarkdownBulletItem : public MarkdownElement
|
||||
{
|
||||
public:
|
||||
virtual ~MarkdownBulletItem() = default;
|
||||
|
||||
Type getType() const override
|
||||
{
|
||||
return Type::BULLET_ITEM;
|
||||
}
|
||||
};
|
||||
|
||||
class MarkdownBulletList : public MarkdownElement
|
||||
{
|
||||
public:
|
||||
virtual ~MarkdownBulletList() = default;
|
||||
|
||||
Type getType() const override
|
||||
{
|
||||
return Type::BULLET_LIST;
|
||||
}
|
||||
|
||||
void addChild(std::unique_ptr<MarkdownBulletItem> child)
|
||||
{
|
||||
mChildren.push_back(std::move(child));
|
||||
}
|
||||
|
||||
std::size_t getNumChildren() const
|
||||
{
|
||||
return mChildren.size();
|
||||
}
|
||||
|
||||
MarkdownBulletItem* getChild(std::size_t idx) const
|
||||
{
|
||||
return mChildren[idx].get();
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<MarkdownBulletItem> > mChildren;
|
||||
};
|
||||
|
||||
class MarkdownHeading : public MarkdownElement
|
||||
{
|
||||
public:
|
||||
MarkdownHeading(unsigned level)
|
||||
: mLevel(level)
|
||||
{
|
||||
|
||||
}
|
||||
virtual ~MarkdownHeading() = default;
|
||||
|
||||
Type getType() const override
|
||||
{
|
||||
return Type::HEADING;
|
||||
}
|
||||
|
||||
unsigned getLevel() const
|
||||
{
|
||||
return mLevel;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned mLevel{1};
|
||||
};
|
||||
|
||||
|
||||
|
||||
class MarkdownInlineQuote : public MarkdownInlineElement
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~MarkdownInlineQuote() = default;
|
||||
|
||||
Type getType() const override
|
||||
{
|
||||
return Type::INLINE_QUOTE;
|
||||
}
|
||||
};
|
||||
|
||||
class MarkdownLink : public MarkdownInlineElement
|
||||
{
|
||||
public:
|
||||
|
||||
MarkdownLink(const std::string& target)
|
||||
: mTarget(target)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual ~MarkdownLink() = default;
|
||||
|
||||
const std::string& getTarget() const
|
||||
{
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
Type getType() const override
|
||||
{
|
||||
return Type::LINK;
|
||||
}
|
||||
private:
|
||||
std::string mTarget;
|
||||
};
|
||||
|
||||
class MarkdownImage : public MarkdownInlineElement
|
||||
{
|
||||
public:
|
||||
MarkdownImage(const std::string& source, const std::string& alt)
|
||||
: mSource(source),
|
||||
mAlt(alt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual ~MarkdownImage() = default;
|
||||
|
||||
Type getType() const override
|
||||
{
|
||||
return Type::IMAGE;
|
||||
}
|
||||
|
||||
const std::string& getSource() const
|
||||
{
|
||||
return mSource;
|
||||
}
|
||||
|
||||
const std::string& getAlt() const
|
||||
{
|
||||
return mAlt;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string mSource;
|
||||
std::string mAlt;
|
||||
};
|
||||
|
||||
class MarkdownMultilineQuote : public MarkdownElement
|
||||
{
|
||||
public:
|
||||
MarkdownMultilineQuote(const std::string& tag)
|
||||
: mTag(tag)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual ~MarkdownMultilineQuote() = default;
|
||||
|
||||
Type getType() const override
|
||||
{
|
||||
return Type::MULTILINE_QUOTE;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string mTag;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class MarkdownElement;
|
||||
|
||||
class MarkdownDocument
|
||||
{
|
||||
public:
|
||||
void addElement(std::unique_ptr<MarkdownElement> element)
|
||||
{
|
||||
mElements.push_back(std::move(element));
|
||||
}
|
||||
void addElement(std::unique_ptr<MarkdownElement> element);
|
||||
|
||||
std::size_t getNumElements() const
|
||||
{
|
||||
return mElements.size();
|
||||
}
|
||||
std::size_t getNumElements() const;
|
||||
|
||||
MarkdownElement* getElement(std::size_t idx) const
|
||||
{
|
||||
return mElements[idx].get();
|
||||
}
|
||||
MarkdownElement* getElement(std::size_t idx) const;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<MarkdownElement> > mElements;
|
||||
|
|
11
src/web/markdown/MarkdownElement.cpp
Normal file
11
src/web/markdown/MarkdownElement.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "MarkdownElement.h"
|
||||
|
||||
void MarkdownElement::appendTextContent(const std::string& content)
|
||||
{
|
||||
mTextContent += content;
|
||||
}
|
||||
|
||||
const std::string& MarkdownElement::getTextContent() const
|
||||
{
|
||||
return mTextContent;
|
||||
}
|
40
src/web/markdown/MarkdownElement.h
Normal file
40
src/web/markdown/MarkdownElement.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class MarkdownElement
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
HEADING,
|
||||
PARAGRAPH,
|
||||
TEXT_SPAN,
|
||||
INLINE_CODE,
|
||||
MULTILINE_CODE,
|
||||
INLINE_QUOTE,
|
||||
MULTILINE_QUOTE,
|
||||
INLINE_SPECIAL,
|
||||
MULTILINE_SPECIAL,
|
||||
LINK,
|
||||
IMAGE,
|
||||
BULLET_ITEM,
|
||||
BULLET_LIST
|
||||
};
|
||||
|
||||
virtual ~MarkdownElement() = default;
|
||||
|
||||
void appendTextContent(const std::string& content);
|
||||
|
||||
const std::string& getTextContent() const;
|
||||
|
||||
virtual Type getType() const = 0;
|
||||
private:
|
||||
std::string mTextContent;
|
||||
};
|
||||
|
||||
class MarkdownInlineElement : public MarkdownElement
|
||||
{
|
||||
public:
|
||||
virtual ~MarkdownInlineElement() = default;
|
||||
};
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "MarkdownDocument.h"
|
||||
#include "StringUtils.h"
|
||||
#include "MarkdownComponents.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue