Merge branch 'feature/nodes-implementation' of https://git.gophernest.net/azpect/MarkdownToHtmlCompiler into feature/nodes-implementation
This commit is contained in:
commit
485798de98
42
lib/node.cpp
42
lib/node.cpp
@ -1,21 +1,21 @@
|
|||||||
#include "./node.h"
|
#include "node.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
void Node::Inspect(int indent) {
|
void Node::Inspect(int indent) {
|
||||||
|
|
||||||
if (this->children.size() > 0) {
|
if (this->children.size() > 0) {
|
||||||
for (int i = 0; i <= indent; i++) {
|
for (int i = 0; i <= indent; i++) {
|
||||||
std::cout << "\t";
|
std::cout << "\t";
|
||||||
}
|
}
|
||||||
std::cout << "std::vector<Node> children: " << std::endl;
|
std::cout << "std::vector<Node> children: " << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &child : this->children) {
|
for (const auto &child : this->children) {
|
||||||
for (int i = 0; i <= indent; i++) {
|
for (int i = 0; i <= indent; i++) {
|
||||||
std::cout << "\t";
|
std::cout << "\t";
|
||||||
}
|
}
|
||||||
child->Inspect(indent + 1);
|
child->Inspect(indent + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,36 +1,36 @@
|
|||||||
#include "./parser.h"
|
#include "parser.h"
|
||||||
#include "./util.h"
|
#include "util.h"
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
Parser::Parser(string input_file_path, string output_file_path) {
|
Parser::Parser(string input_file_path, string output_file_path) {
|
||||||
// NOTE: Remove any white space AROUND the inputs
|
// NOTE: Remove any white space AROUND the inputs
|
||||||
removeWhitespace(input_file_path);
|
removeWhitespace(input_file_path);
|
||||||
removeWhitespace(output_file_path);
|
removeWhitespace(output_file_path);
|
||||||
|
|
||||||
if (input_file_path == "") {
|
if (input_file_path == "") {
|
||||||
throw std::runtime_error("input_file_path cannot be empty");
|
throw std::runtime_error("input_file_path cannot be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
this->input_file_path = input_file_path;
|
this->input_file_path = input_file_path;
|
||||||
|
|
||||||
// NOTE: If the user does not provide an output file, then we should construct
|
// NOTE: If the user does not provide an output file, then we should construct
|
||||||
// one using the input file with .md swapped with the extension.
|
// one using the input file with .md swapped with the extension.
|
||||||
if (output_file_path == "") {
|
if (output_file_path == "") {
|
||||||
int ext_idx = input_file_path.find_last_of('.');
|
int ext_idx = input_file_path.find_last_of('.');
|
||||||
string output_cleaned = input_file_path.substr(0, ext_idx) + ".html";
|
string output_cleaned = input_file_path.substr(0, ext_idx) + ".html";
|
||||||
this->output_file_path = output_cleaned;
|
this->output_file_path = output_cleaned;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->output_file_path = output_file_path;
|
this->output_file_path = output_file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::Inspect() {
|
void Parser::Inspect() {
|
||||||
std::cout << "std::string input_file_path: " << this->input_file_path
|
std::cout << "std::string input_file_path: " << this->input_file_path
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::cout << "std::string output_file_path: " << this->output_file_path
|
std::cout << "std::string output_file_path: " << this->output_file_path
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
1
lib/structureNode.cpp
Normal file
1
lib/structureNode.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "structureNode.h"
|
||||||
13
lib/structureNode.h
Normal file
13
lib/structureNode.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef STRUCTURENODE_H
|
||||||
|
#define STRUCTURENODE_H
|
||||||
|
|
||||||
|
#include "node.h"
|
||||||
|
|
||||||
|
class StructureNode : public Node {};
|
||||||
|
|
||||||
|
class ListNode : public StructureNode {};
|
||||||
|
class HeadingNode : public StructureNode {};
|
||||||
|
class DocumentNode : public StructureNode {};
|
||||||
|
class ParagraphNode : public StructureNode {};
|
||||||
|
|
||||||
|
#endif
|
||||||
48
lib/util.cpp
48
lib/util.cpp
@ -1,24 +1,24 @@
|
|||||||
#include "./util.h"
|
#include "util.h"
|
||||||
|
|
||||||
void removeTrailingWhitespace(std::string &input) {
|
void removeTrailingWhitespace(std::string &input) {
|
||||||
size_t start = input.find_first_not_of(" \t\n\r\f\v");
|
size_t start = input.find_first_not_of(" \t\n\r\f\v");
|
||||||
if (start != std::string::npos) {
|
if (start != std::string::npos) {
|
||||||
input.erase(0, start);
|
input.erase(0, start);
|
||||||
} else {
|
} else {
|
||||||
input.clear();
|
input.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeLeadingWhitespace(std::string &input) {
|
void removeLeadingWhitespace(std::string &input) {
|
||||||
size_t end = input.find_last_not_of(" \t\n\r\f\v");
|
size_t end = input.find_last_not_of(" \t\n\r\f\v");
|
||||||
if (end != std::string::npos) {
|
if (end != std::string::npos) {
|
||||||
input.erase(end + 1);
|
input.erase(end + 1);
|
||||||
} else {
|
} else {
|
||||||
input.clear();
|
input.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeWhitespace(std::string &input) {
|
void removeWhitespace(std::string &input) {
|
||||||
removeLeadingWhitespace(input);
|
removeLeadingWhitespace(input);
|
||||||
removeTrailingWhitespace(input);
|
removeTrailingWhitespace(input);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user