diff --git a/MDtoHTMLUML.pdf b/MDtoHTMLUML.pdf deleted file mode 100644 index 4fe9f11..0000000 Binary files a/MDtoHTMLUML.pdf and /dev/null differ diff --git a/UMLClassDiagram.pdf b/UMLClassDiagram.pdf new file mode 100644 index 0000000..e7350f0 Binary files /dev/null and b/UMLClassDiagram.pdf differ diff --git a/UMLClassDiagram.png b/UMLClassDiagram.png new file mode 100644 index 0000000..1e89f73 Binary files /dev/null and b/UMLClassDiagram.png differ diff --git a/lib/commandLineParser.cpp b/lib/commandLineParser.cpp index b443b52..09d4e53 100644 --- a/lib/commandLineParser.cpp +++ b/lib/commandLineParser.cpp @@ -20,41 +20,41 @@ CLI::CLI(int argc, char **argv) { } ParseArgs(argc, argv); - } catch (const std::invalid_argument &e) { - std::cerr << e.what() << "\n"; - PrintHelp(); - std::exit(EXIT_FAILURE); + std::cerr << e.what() << "\n"; + PrintHelp(); + std::exit(EXIT_FAILURE); } } -void CLI::ParseArgs(int argc, char** argv){ - for (int i = 2; i < argc; i++) { - std::string arg = argv[i]; +void CLI::ParseArgs(int argc, char **argv) { + for (int i = 2; i < argc; i++) { + std::string arg = argv[i]; - if (arg == "-w" || arg == "--watch") { - watchdog_enabled = true; - continue; - } - - if ((arg == "-o" || arg == "--output") && i + 1 < argc) { - output_file = argv[++i]; - - if (!(IsHtmlFile(output_file))) { - throw std::invalid_argument("Error: Invalid file extension. Expected a '.html' (HTML) file."); - } - - continue; - } - - if (arg == "-o" || arg == "--output") { - throw std::invalid_argument("Error: Missing filename after '-o' or '--output'."); - } - - std::cerr << "Warning: Unrecognized argument '" << arg << "' ignored.\n"; + if (arg == "-w" || arg == "--watch") { + watchdog_enabled = true; + continue; } + if ((arg == "-o" || arg == "--output") && i + 1 < argc) { + output_file = argv[++i]; + + if (!(IsHtmlFile(output_file))) { + throw std::invalid_argument( + "Error: Invalid file extension. Expected a '.html' (HTML) file."); + } + + continue; + } + + if (arg == "-o" || arg == "--output") { + throw std::invalid_argument( + "Error: Missing filename after '-o' or '--output'."); + } + + std::cerr << "Warning: Unrecognized argument '" << arg << "' ignored.\n"; + } } bool CLI::IsMarkupFile(const std::string &filename) { @@ -80,16 +80,17 @@ bool CLI::IsMarkupFile(const std::string &filename) { } bool CLI::IsHtmlFile(const std::string &filename) { - // HTML file extension - const std::string requiredExtension = ".html"; + // HTML file extension + const std::string requiredExtension = ".html"; - // Ensure the filename is long enough to contain the extension - if (filename.size() <= requiredExtension.size()) { - return false; - } + // Ensure the filename is long enough to contain the extension + if (filename.size() <= requiredExtension.size()) { + return false; + } - // Check if the filename ends with ".html" - return filename.substr(filename.size() - requiredExtension.size()) == requiredExtension; + // Check if the filename ends with ".html" + return filename.substr(filename.size() - requiredExtension.size()) == + requiredExtension; } void CLI::PrintHelp() const { @@ -99,5 +100,3 @@ void CLI::PrintHelp() const { << "\t-o, --output , optional output filename\n" << "\t-w, --watch, enables watchdog\n"; } - -// ./parser input_file -w dhuahdakhk -o output diff --git a/lib/commandLineParser.h b/lib/commandLineParser.h index f66253c..b55381d 100644 --- a/lib/commandLineParser.h +++ b/lib/commandLineParser.h @@ -31,13 +31,6 @@ public: */ CLI(int argc, char **argv); - /** - * @brief Runs Commands - * - * @author Preston Shultz (shultzp1@my.erau.edu) - */ - void RunCommands(); - /** * @brief Prints a list of commands that can be used * diff --git a/lib/documentConverter.h b/lib/documentConverter.h index 082ecf2..e263aae 100644 --- a/lib/documentConverter.h +++ b/lib/documentConverter.h @@ -1,9 +1,9 @@ #ifndef DOCUMENT_CONVERTER_H #define DOCUMENT_CONVERTER_H +#include "commandLineParser.h" #include "parser.h" #include "watchdog.h" -#include "commandLineParser.h" #include class DocumentConverter { @@ -13,11 +13,19 @@ private: Watchdog watchdog; public: - DocumentConverter(int argc, char** argv) - : cli(argc, argv), - parser(cli.GetInputFile(), cli.GetOutputFile()), - watchdog(cli.GetInputFile()) {} + DocumentConverter(int argc, char **argv) + : cli(argc, argv), parser(cli.GetInputFile(), cli.GetOutputFile()), + watchdog(cli.GetInputFile()) {} + void Start() { + if (this->cli.WatchDogEnabled()) { + this->ConvertWatcher(); + } else { + this->Convert(); + } + } + +private: void Convert() { this->parser.ParseDocument(); this->parser.WriteOutput(); @@ -30,7 +38,7 @@ public: this->parser.ParseDocument(); this->parser.WriteOutput(); }; - if (cli.WatchDogEnabled()){ + if (cli.WatchDogEnabled()) { this->watchdog.Start(callback); } } diff --git a/src/main.cpp b/src/main.cpp index 5607075..cd465fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,89 +1,6 @@ #include "../lib/documentConverter.h" -#include "../lib/inlineNode.h" -#include "../lib/parser.h" -#include "../lib/structureNode.h" -#include "../lib/watchdog.h" -#include -#include - -void test_nodes() { - // For simplicity - using std::make_unique; - using std::unique_ptr; - - DocumentNode root; - unique_ptr node = make_unique("text node"); - unique_ptr bold = make_unique("bold node"); - unique_ptr italic = make_unique("italic node"); - unique_ptr bolditalic = - make_unique("bold italic node"); - - unique_ptr heading = make_unique(2); - heading->AddChild(std::move(node)); - heading->AddChild(std::move(bold)); - - std::unique_ptr para = std::make_unique(); - para->AddChild(std::move(italic)); - para->AddChild(std::move(bolditalic)); - - unique_ptr list = make_unique(); - - root.AddChild(std::move(heading)); - root.AddChild(std::move(para)); - root.AddChild(std::move(list)); - - std::cout << root << std::endl; -} - -/** - *Preston: Test to see if watchdog works :) - */ -void test_watchdog() { - Watchdog wd("test/input.md"); - wd.Start(nullptr); -} - -void test_input(int argc, char **argv) { - if (argc <= 1) { - std::cerr << "Usage: " << std::endl; - return; - } - - try { - if (argc >= 3) { - Parser p(argv[1], argv[2]); - p.Inspect(); - } else { - Parser p(argv[1]); - p.Inspect(); - } - } catch (const std::runtime_error &e) { - std::cout << "Caught an error: " << e.what() << std::endl; - } catch (...) { - std::cout << "Caught an error: UNKNOWN" << std::endl; - } - - std::cout << std::endl; -} - -void test_document_converter() { - // Simulate command line: - // program name, input file, watch flag, output file - const char* argv[] = { - "program", // argv[0] - program name - "test/input.md", // argv[1] - input file - "-w", // argv[2] - enable watchdog - "-o", // argv[3] - output flag - "test/output.html" // argv[4] - output filename - }; - int argc = 5; - - // Construct DocumentConverter with simulated command line - DocumentConverter dc(argc, const_cast(argv)); - - // Run the watcher (or use dc.Convert() for single conversion) - dc.ConvertWatcher(); -} - -int main(int argc, char **argv) { test_document_converter(); } +int main(int argc, char **argv) { + DocumentConverter dc(argc, const_cast(argv)); + dc.Start(); +}; diff --git a/test/hello.html b/test/hello.html new file mode 100644 index 0000000..b15db82 --- /dev/null +++ b/test/hello.html @@ -0,0 +1,55 @@ + + + + + + Document + + +

MarkdownToHtmlTranspiler

+

Project Overview

+

The goal is to create a program that reads a file containing text formatted in a simple version of Markdown and converts it into a valid HTML file. The program will need to identify and translate specific syntax (e.g., # Heading to

Heading

, *text* to text).

+

Implementation Requirements (Generated by Gemini)

+

Class Hierarchy: Design a class hierarchy to represent the components of your Markdown document. An abstract base class, Element, can define common behavior. Derived classes would then represent specific types of elements, such as Heading, Paragraph, BoldText, and ListItem. This is a perfect example of inheritance and polymorphism.

+

Object Composition: A Document class can be composed of multiple Element objects, representing the entire file. A Parser class would be composed of helper methods to break down the input string and build the Document object. This shows how you can build a complex system from smaller, self-contained objects.

+

File I/O and Exceptions: You will need to use ifstream to read the Markdown file and ofstream to write the generated HTML file. Your code should use exceptions to gracefully handle potential errors, such as a file not being found.

+

Operator Overloading: Overload the << stream insertion operator for your Element and Document classes. This would allow you to easily print the generated HTML to the console or write it to a file, making your code cleaner and more readable.

+

UML Diagram: The complexity of the class relationships makes a UML diagram an essential part of the project. It will help you plan your design and will be a key component of your submission.

+

Recursive Descent Parser: This is the primary algorithm you'll use. It's a top-down parsing technique where a set of recursive functions "descend" through the grammar of your simple Markdown language. For example, a parse_document() function would call parse_line(), which in turn might call parse_bold_text() or parse_italic_text(). This method is intuitive and easy to implement for a simple grammar.

+

Stack: A stack is essential for handling nested elements. For instance, if you allow bold text inside italic text (_This is bold and italic text_), you can push the _ token onto the stack and then push the token. When you encounter the closing , you check if the top of the stack matches. This ensures that all tags are correctly opened and closed. Your presentation can visually demonstrate this process with a stack diagram.

+

Hash Map or Map: A hash map (std::unordered_map) or a map (std::map) can be used to efficiently store and retrieve the HTML equivalent for each Markdown tag. For example, you could map # to

or * to . This provides O(1) average-case lookup time.

+

Contribution Policy

+
Branching When working on this project, please use a feature branch (i.e. feature/parser) with a descriptive name. feature/a is not a descriptive name. These branches should be branched off the most recent main branch, we will not make use of a dev or staging branch since the project is small in scale as well as time. However, if the project becomes larger or out-of-control, a dev/staging branch will be implemented.
+
Commits
+

When working, it is best practice to commit code as much as possible, without being over zealous. For example, when a feature or bug is complete, its time to commit. But when you have to make a new function, that does not mean its time. Each team member should use their best judgment.

+

Commit messages a little bit more important, when working in a team, it is important to provide strong, clear and concise commit messages. In this project, the team will use a simple formula:

+

(SUBJECT) Title: textual description

+

i.e. (FIX) Rendering completed: explain what changed in short.

+
Pushing
+

When working in a feature branch, pushing and pulling has no restrictions. Feel free to do as much (or as little) as possible. However, you CANNOT push directly to main, the VCS will not allow you to do so, but do not make that mistake. When you are ready to merge a feature, you will create a PR and once it has been reviewed and approved it will be automatically merged in.

+
Pull Requests (PR)
+

Once a feature is complete, you will create a pull request. Before a request can be merged into main, one approval is required (which cannot be the author). This practice is to promote team work and encourage code reviews. Each team member is expected to check in frequently and review as often as they are able to, however, there is no defined time requirement. Personal communication is totally acceptable as a means to request approval, since I am unsure if this platform will notify members.

+
Issues
+

If a bug, issue, or otherwise concern is noticed the first thing the team member should do is create an issue. An issue should be descriptive and contain everything another team member needs to understand the issue and its context. This way, a new team member can tackle the issue without contextual gaps.

+

If a member would like to work on the issue themself, the assignee field is where this should be defined. If a member would like help from another member, they should assign the other team member to the issue, and leave a comment in the issue itself describing what help is needed.

+

Labels are important for understanding what type of issues/bugs exist in the application. When a bug is created, make sure the proper labels are applied. These labels will be abstract, such as: bug, fix or feature and they will also be specific, such as: parser, i/o or processer. A combination of both styles of labels allows other team members to understand what is going on. If a member feels an issue is missing, they are free to create new ones, but there is a such thing as too many labels a few per issue is totally fine. They are not meant to replace the description.

+

Priority is the final important factor to consider. In this project, priority will be defined using labels as well. The policy defined above will apply here to priority labels as well. However, these labels are mutually exclusive.

+
Projects (Sprints)
+

The use of the projects tab in the VCS will allow the team to remain organized as create notes and action items that should be completed before one another. These resemble sprints from the AGILE development life cycle. A new "project" should be created when a large piece of functionality needs to be created. Issues can and should be attached to the projects they are related too. This will continue to encourage teamwork and organization.

+

Projects should have defined criteria, such as input and outputs, expectations and a semi-defined timeline. Once a description and is defined, tasks can be added and moved around as needed. The team will use Kanban project types, as they are simple and easy to understand for new team members. Reference [here](https://www.markdownguide.org/basic-syntax/)

+

Headings, h# tags

+

Header Level 1 ->

Content

## Header Level 2 ->

Content

### Header Level 3 ->

Content

#### Header Level 4 ->

Content

##### Header Level 5 ->
Content
###### Header Level 6 ->
Content

+

Alternate syntax (n number of =/-)

+

Header Level 1 ->

Content

================

+

Header Level 2 ->

Content

----------------

+

Paragraph tags

+

Hello world ->

Hello world

+

This is also a paragraph ->

this is also a paragraph regardless

regardless

+

However this is a break, because it ends with two spaces ->

However
this is a break, because it ends with two spaces

+

Double returns also

+

yields new paragraphs ->

Double returns also

yields new paragraphs

+

italic -> italic bold -> bold italic bold -> italic bold

+

hello world -> [TextClass: hello, BoldClass: world]

+ + + \ No newline at end of file diff --git a/test/input.md b/test/input.md index 2ba0eb3..800f927 100644 --- a/test/input.md +++ b/test/input.md @@ -1,3 +1,118 @@ +# MarkdownToHtmlTranspiler + +### Project Overview + +The goal is to create a program that reads a file containing text formatted in a simple version of +Markdown and converts it into a valid HTML file. The program will need to identify and translate +specific syntax (e.g., `# Heading` to `

Heading

`, `*text*` to `text`). + + +### Implementation Requirements (Generated by Gemini) + +Class Hierarchy: Design a class hierarchy to represent the components of your Markdown document. An +abstract base class, Element, can define common behavior. Derived classes would then represent specific +types of elements, such as Heading, Paragraph, BoldText, and ListItem. This is a perfect example of +inheritance and polymorphism. + +Object Composition: A Document class can be composed of multiple Element objects, representing the +entire file. A Parser class would be composed of helper methods to break down the input string and +build the Document object. This shows how you can build a complex system from smaller, self-contained +objects. + +File I/O and Exceptions: You will need to use ifstream to read the Markdown file and ofstream to write +the generated HTML file. Your code should use exceptions to gracefully handle potential errors, such +as a file not being found. + +Operator Overloading: Overload the << stream insertion operator for your Element and Document classes. +This would allow you to easily print the generated HTML to the console or write it to a file, making +your code cleaner and more readable. + +UML Diagram: The complexity of the class relationships makes a UML diagram an essential part of the +project. It will help you plan your design and will be a key component of your submission. + +Recursive Descent Parser: This is the primary algorithm you'll use. It's a top-down parsing technique +where a set of recursive functions "descend" through the grammar of your simple Markdown language. For +example, a parse_document() function would call parse_line(), which in turn might call parse_bold_text() +or parse_italic_text(). This method is intuitive and easy to implement for a simple grammar. + +Stack: A stack is essential for handling nested elements. For instance, if you allow bold text inside +italic text (_This is *bold and italic* text_), you can push the _ token onto the stack and then push +the * token. When you encounter the closing *, you check if the top of the stack matches. This ensures +that all tags are correctly opened and closed. Your presentation can visually demonstrate this process +with a stack diagram. + +Hash Map or Map: A hash map (std::unordered_map) or a map (std::map) can be used to efficiently store +and retrieve the HTML equivalent for each Markdown tag. For example, you could map `#` to `

`or `*` +to ``. This provides O(1) average-case lookup time. + + +### Contribution Policy + +###### Branching +When working on this project, please use a feature branch (i.e. `feature/parser`) with a descriptive name. +`feature/a` is not a descriptive name. These branches should be branched off the most recent `main` branch, +we will not make use of a `dev` or `staging` branch since the project is small in scale as well as time. +**However, if the project becomes larger or out-of-control, a dev/staging branch will be implemented.** + +###### Commits + +When working, it is best practice to commit code as much as possible, without being over zealous. For +example, when a feature or bug is complete, its time to commit. But when you have to make a new function, +that does not mean its time. Each team member should use their best judgment. + +Commit messages a little bit more important, when working in a team, it is important to provide strong, +clear and concise commit messages. In this project, the team will use a simple formula: + +**(SUBJECT) Title: textual description** + +i.e. (FIX) Rendering completed: explain what changed in short. + +###### Pushing + +When working in a feature branch, pushing and pulling has no restrictions. Feel free to do as much +(or as little) as possible. However, you **CANNOT** push directly to `main`, the VCS will not allow you +to do so, but do not make that mistake. When you are ready to merge a feature, you will create a PR +and once it has been reviewed and approved it will be automatically merged in. + +###### Pull Requests (PR) + +Once a feature is complete, you will create a pull request. Before a request can be merged into `main`, +one approval is required (which cannot be the author). This practice is to promote team work and encourage +code reviews. Each team member is expected to check in frequently and review as often as they are able to, +however, there is no defined time requirement. Personal communication is totally acceptable as a means to +request approval, since I am unsure if this platform will notify members. + +###### Issues + +If a bug, issue, or otherwise concern is noticed the first thing the team member should do is create an +issue. An issue should be descriptive and contain everything another team member needs to understand the +issue and its context. This way, a new team member can tackle the issue without contextual gaps. + +If a member would like to work on the issue themself, the `assignee` field is where this should be defined. +If a member would like help from another member, they should assign the other team member to the issue, and +leave a comment in the issue itself describing what help is needed. + +**Labels** are important for understanding what type of issues/bugs exist in the application. When a bug is +created, make sure the proper labels are applied. These labels will be abstract, such as: `bug`, `fix` or `feature` +and they will also be specific, such as: `parser`, `i/o` or `processer`. A combination of both styles of labels +allows other team members to understand what is going on. If a member feels an issue is missing, they are free +to create new ones, but there is a such thing as **too many labels** a few per issue is totally fine. They are +not meant to replace the description. + +**Priority** is the final important factor to consider. In this project, priority will be defined using labels +as well. The policy defined above will apply here to priority labels as well. However, these labels are +**mutually exclusive**. + +###### Projects (Sprints) + +The use of the `projects` tab in the VCS will allow the team to remain organized as create notes and action +items that should be completed before one another. These resemble `sprints` from the `AGILE` development life cycle. +A new "project" should be created when a large piece of functionality needs to be created. Issues can **and should** +be attached to the projects they are related too. This will continue to encourage teamwork and organization. + +Projects should have defined criteria, such as input and outputs, expectations and a semi-defined timeline. +Once a description and is defined, tasks can be added and moved around as needed. The team will use **Kanban** +project types, as they are simple and easy to understand for new team members. Reference [here](https://www.markdownguide.org/basic-syntax/) Headings, h# tags