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 <iostream>
|
||||
#include <memory>
|
||||
|
||||
void Node::Inspect(int indent) {
|
||||
|
||||
if (this->children.size() > 0) {
|
||||
for (int i = 0; i <= indent; i++) {
|
||||
std::cout << "\t";
|
||||
}
|
||||
std::cout << "std::vector<Node> children: " << std::endl;
|
||||
}
|
||||
|
||||
for (const auto &child : this->children) {
|
||||
for (int i = 0; i <= indent; i++) {
|
||||
std::cout << "\t";
|
||||
}
|
||||
child->Inspect(indent + 1);
|
||||
}
|
||||
}
|
||||
#include "node.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
void Node::Inspect(int indent) {
|
||||
|
||||
if (this->children.size() > 0) {
|
||||
for (int i = 0; i <= indent; i++) {
|
||||
std::cout << "\t";
|
||||
}
|
||||
std::cout << "std::vector<Node> children: " << std::endl;
|
||||
}
|
||||
|
||||
for (const auto &child : this->children) {
|
||||
for (int i = 0; i <= indent; i++) {
|
||||
std::cout << "\t";
|
||||
}
|
||||
child->Inspect(indent + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,36 +1,36 @@
|
||||
#include "./parser.h"
|
||||
#include "./util.h"
|
||||
#include <cctype>
|
||||
#include <stdexcept>
|
||||
|
||||
using std::string;
|
||||
|
||||
Parser::Parser(string input_file_path, string output_file_path) {
|
||||
// NOTE: Remove any white space AROUND the inputs
|
||||
removeWhitespace(input_file_path);
|
||||
removeWhitespace(output_file_path);
|
||||
|
||||
if (input_file_path == "") {
|
||||
throw std::runtime_error("input_file_path cannot be empty");
|
||||
}
|
||||
|
||||
this->input_file_path = input_file_path;
|
||||
|
||||
// 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.
|
||||
if (output_file_path == "") {
|
||||
int ext_idx = input_file_path.find_last_of('.');
|
||||
string output_cleaned = input_file_path.substr(0, ext_idx) + ".html";
|
||||
this->output_file_path = output_cleaned;
|
||||
return;
|
||||
}
|
||||
|
||||
this->output_file_path = output_file_path;
|
||||
}
|
||||
|
||||
void Parser::Inspect() {
|
||||
std::cout << "std::string input_file_path: " << this->input_file_path
|
||||
<< std::endl;
|
||||
std::cout << "std::string output_file_path: " << this->output_file_path
|
||||
<< std::endl;
|
||||
}
|
||||
#include "parser.h"
|
||||
#include "util.h"
|
||||
#include <cctype>
|
||||
#include <stdexcept>
|
||||
|
||||
using std::string;
|
||||
|
||||
Parser::Parser(string input_file_path, string output_file_path) {
|
||||
// NOTE: Remove any white space AROUND the inputs
|
||||
removeWhitespace(input_file_path);
|
||||
removeWhitespace(output_file_path);
|
||||
|
||||
if (input_file_path == "") {
|
||||
throw std::runtime_error("input_file_path cannot be empty");
|
||||
}
|
||||
|
||||
this->input_file_path = input_file_path;
|
||||
|
||||
// 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.
|
||||
if (output_file_path == "") {
|
||||
int ext_idx = input_file_path.find_last_of('.');
|
||||
string output_cleaned = input_file_path.substr(0, ext_idx) + ".html";
|
||||
this->output_file_path = output_cleaned;
|
||||
return;
|
||||
}
|
||||
|
||||
this->output_file_path = output_file_path;
|
||||
}
|
||||
|
||||
void Parser::Inspect() {
|
||||
std::cout << "std::string input_file_path: " << this->input_file_path
|
||||
<< std::endl;
|
||||
std::cout << "std::string output_file_path: " << this->output_file_path
|
||||
<< 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"
|
||||
|
||||
void removeTrailingWhitespace(std::string &input) {
|
||||
size_t start = input.find_first_not_of(" \t\n\r\f\v");
|
||||
if (start != std::string::npos) {
|
||||
input.erase(0, start);
|
||||
} else {
|
||||
input.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void removeLeadingWhitespace(std::string &input) {
|
||||
size_t end = input.find_last_not_of(" \t\n\r\f\v");
|
||||
if (end != std::string::npos) {
|
||||
input.erase(end + 1);
|
||||
} else {
|
||||
input.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void removeWhitespace(std::string &input) {
|
||||
removeLeadingWhitespace(input);
|
||||
removeTrailingWhitespace(input);
|
||||
}
|
||||
#include "util.h"
|
||||
|
||||
void removeTrailingWhitespace(std::string &input) {
|
||||
size_t start = input.find_first_not_of(" \t\n\r\f\v");
|
||||
if (start != std::string::npos) {
|
||||
input.erase(0, start);
|
||||
} else {
|
||||
input.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void removeLeadingWhitespace(std::string &input) {
|
||||
size_t end = input.find_last_not_of(" \t\n\r\f\v");
|
||||
if (end != std::string::npos) {
|
||||
input.erase(end + 1);
|
||||
} else {
|
||||
input.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void removeWhitespace(std::string &input) {
|
||||
removeLeadingWhitespace(input);
|
||||
removeTrailingWhitespace(input);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user