From c075c0a619e8e0f2d3f70192e1788b24d6315067 Mon Sep 17 00:00:00 2001 From: abap34 Date: Fri, 22 Sep 2023 21:46:45 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=83=A9=E3=82=A4=E3=83=B3=E5=BC=95=E6=95=B0=E3=81=AE=E3=83=90?= =?UTF-8?q?=E3=83=AA=E3=83=87=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/almo.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/almo.cpp b/src/almo.cpp index 5e8263e..50dfbd5 100644 --- a/src/almo.cpp +++ b/src/almo.cpp @@ -3,20 +3,24 @@ #include "render.hpp" #include #include +#include int main(int argc, char *argv[]){ auto [meta_data, asts] = almo::parse_md_file(argv[1]); nlohmann::json json_meta_data = almo::make_meta_data_json(meta_data); nlohmann::json json_ir = almo::make_json(asts); - std::vector args = {"-o", "-t", "-d", "-h"}; - // default std::string theme = "light"; std::string out_path = "index.html"; for (int i = 2; i < argc; i++){ if (argv[i][0] == '-'){ + if (strlen(argv[i]) > 3){ + std::cerr << "Unkown command line arguments is passed." << std::endl; + std::cerr << "Please check the option by `almo -h`" << std::endl; + exit(1); + } if (argv[i][1] == 'o'){ out_path = argv[i + 1]; } @@ -43,6 +47,11 @@ int main(int argc, char *argv[]){ std::cout << " -h : show this help" << std::endl; return 0; } + else { + std::cerr << "Unkown command line arguments is passed." << std::endl; + std::cerr << "Please check the option by `almo -h`" << std::endl; + exit(1); + } } } From 78b2f249bd6cbfbdb6da13e4489c86b08a53e41f Mon Sep 17 00:00:00 2001 From: abap34 Date: Fri, 22 Sep 2023 21:47:19 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=83=86=E3=83=B3=E3=83=97=E3=83=AC?= =?UTF-8?q?=E3=83=BC=E3=83=88=E3=82=92=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dark.css | 279 ++++++++++++++++++++++++++++++++++ src/dark.html | 378 ---------------------------------------------- src/light.css | 281 ++++++++++++++++++++++++++++++++++ src/light.html | 376 --------------------------------------------- src/render.hpp | 25 +-- src/template.html | 103 +++++++++++++ 6 files changed, 678 insertions(+), 764 deletions(-) create mode 100644 src/dark.css delete mode 100644 src/dark.html create mode 100644 src/light.css delete mode 100644 src/light.html create mode 100644 src/template.html diff --git a/src/dark.css b/src/dark.css new file mode 100644 index 0000000..81d20b1 --- /dev/null +++ b/src/dark.css @@ -0,0 +1,279 @@ +R"( + body { + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + line-height: 1.6; + max-width: 800px; + margin: 0 auto; + padding: 20px; + background-color: #333; + color: #F7F7F7; + flex-direction: column; + display: flex; + width: 95%; +} + +h1, +h2 { + color: #F7F7F7; + text-align: center; + margin-bottom: 20px; +} + +h2 { + text-align: left; + padding-left: 10px; + border-bottom: solid 1px #5b5b5b; +} + +p { + color: #ccc; + margin-bottom: 10px; +} + +a { + color: #dcddfe; +} + +figure { + text-align: center; +} + +figcaption { + text-align: center; +} + +pre { + padding: 10px; + color: #F7F7F7; + border: solid 1px #a8a8a8; + overflow-x: auto; +} + + +img { + max-width: 100%; + height: auto; +} + +.date { + color: #ccc; + font-size: 14px; + margin: 0 auto; + text-align: center; +} + +.tag { + color: #ccc; + font-size: 14px; + margin: 0 auto; + text-align: center; +} + +.content { + flex: 1; + padding: 40px 40px; + margin-left: 0px; + margin-right: 10px; + margin-top: 0px; + margin-bottom: 0px; + background-color: #444; + border-radius: 5px; + overflow: auto; + width: 100%; +} + +@media (max-width: 768px) { + .content { + width: 100%; + padding: 20px; + } +} + +.sidebar { + flex: 3; + border-right: 1px solid #eee; + height: 100%; + width: 10%; + padding: 10px 10px; + left: 0; + overflow: auto; + position: fixed; + top: 0; + width: 220px; + z-index: 1000; + background-color: #333; +} + +@media (max-width: 1260px) { + .sidebar { + display: none; + } +} + +.links { + position: fixed; + right: 0; + top: 0; + width: 200px; + height: 100%; + padding: 10px 10px; + overflow: auto; + background-color: #333; +} + +@media (max-width: 1260px) { + .links { + display: none; + } +} + +#toc { + background-color: #444; + border-radius: 5px; + padding: 15px; + list-style: none; +} + +.toc_title { + font-size: 20px; + font-weight: bold; + margin-bottom: 10px; + color: #F7F7F7; + border-bottom: solid 1px #161616; +} + +#toc a { + text-decoration: none; + color: #ccc; + display: block; + margin: 5px 0; + transition: color 0.2s; +} + +#toc a:hover { + color: #007bff; +} + +#toc .active { + font-weight: bold; + color: #007bff; + font-size: 16px; +} + +.toc_H2 { + font-size: 16px; + font-weight: bold; + margin-bottom: 10px; + color: #006699; + font-weight: bold; +} + +.toc_H3 { + font-size: 14px; + margin-bottom: 10px; + color: #006699; +} + +.content_list_h1 { + font-size: 20px; + font-weight: bold; + margin-bottom: 10px; + border-bottom: solid 1px #006699; + color: #006699; +} + +.content_list_h2 { + font-size: 16px; + font-weight: bold; + margin-bottom: 10px; + color: #006699; +} + +.content_list_problem { + font-size: 14px; + font-weight: bold; + margin-bottom: 10px; + color: #006699; +} + +.badge { + padding: 8px 20px; + border-radius: 25px; + font-size: 14px; + font-weight: bold; + color: #ccc; + /* ダークテーマのテキスト色 */ + border: 1px solid #333; + margin: 0 8px; + float: left; +} + +.runbutton, +.submitbutton { + display: inline-block; + padding: 10px 20px; + border: none; + border-radius: 5px; + font-size: 16px; + color: #fff; + cursor: pointer; + text-align: center; + text-decoration: none; +} + +.runbutton { + background-color: #006699; +} + +.runbutton:hover { + background-color: #005580; +} + +.submitbutton { + background-color: #008000; +} + +.submitbutton:hover { + background-color: #006400; +} + +.problem_title { + font-size: 20px; + font-weight: bold; + color: #F7F7F7; +} + + +.editor { + width: 100%; + font-size: 16px; + font-family: monospace; + background-color: #444; + color: #F7F7F7; + border: solid 1px #a8a8a8; +} + + +.output, +.expect_out, +.sample_in, +.sample_out { + width: 100%; + padding: 5px 5px; + overflow-x: auto; + font-size: 16px; + font-family: monospace; + background-color: #444; + color: #F7F7F7; + border: solid 1px #a8a8a8; +} + +.box-title, +.problem_list { + font-size: 14px; + font-weight: bold; + margin-bottom: 10px; + color: #ccc; +} + +)" \ No newline at end of file diff --git a/src/dark.html b/src/dark.html deleted file mode 100644 index 30842f7..0000000 --- a/src/dark.html +++ /dev/null @@ -1,378 +0,0 @@ -R"( - - - - - - {{title}} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- -
- - -

{{title}}

- -
-
-
-
- - - - {{contents}} - -
- - - - - - - -)" \ No newline at end of file diff --git a/src/light.css b/src/light.css new file mode 100644 index 0000000..1abc0bd --- /dev/null +++ b/src/light.css @@ -0,0 +1,281 @@ +R"( +body { + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + line-height: 1.6; + max-width: 800px; + margin: 0 auto; + padding: 20px; + background-color: #F7F7F7; + color: #333; + flex-direction: column; + display: flex; + width: 95%; + +} + +h1, +h2 { + color: #323232; + text-align: center; + margin-bottom: 20px; +} + +h2 { + text-align: left; + padding-left: 10px; + border-bottom: solid 1px #5b5b5b; +} + +p { + color: #666; + margin-bottom: 10px; +} + +a { + color: #006699; +} + +figure { + text-align: center; +} + +figcaption { + text-align: center; +} + +pre { + padding: 10px; + color: #333; + border: solid 1px #a8a8a8; + overflow-x: auto; +} + +img { + max-width: 100%; + height: auto; +} + + +.date { + color: #666; + font-size: 14px; + margin: 0 auto; + text-align: center; +} + +.tag { + color: #666; + font-size: 14px; + margin: 0 auto; + text-align: center; +} + +.content { + flex: 1; + padding: 40px 40px; + margin-left: 0px; + margin-right: 10px; + margin-top: 0px; + margin-bottom: 0px; + background-color: #ffffff; + border-radius: 5px; + overflow: auto; + width: 100%; +} + + +@media (max-width: 768px) { + .content { + width: 100%; + padding: 20px; + } +} + +.sidebar { + flex: 3; + border-right: 1px solid #eee; + height: 100%; + width: 10%; + padding: 10px 10px; + left: 0; + overflow: auto; + position: fixed; + top: 0; + width: 220px; + z-index: 1000; + background-color: #F2F2F2; +} + +@media (max-width: 1260px) { + .sidebar { + display: none; + } +} + +.links { + position: fixed; + right: 0; + top: 0; + width: 200px; + height: 100%; + padding: 10px 10px; + overflow: auto; + background-color: #F2F2F2; +} + +@media (max-width: 1260px) { + .links { + display: none; + } +} + +#toc { + background-color: #f4f4f4; + border-radius: 5px; + padding: 15px; + list-style: none; +} + +.toc_title { + font-size: 20px; + font-weight: bold; + margin-bottom: 10px; + color: #2a2a2a; + border-bottom: solid 1px #161616; +} + +#toc a { + text-decoration: none; + color: #333; + display: block; + margin: 5px 0; + transition: color 0.2s; +} + +#toc a:hover { + color: #007bff; +} + +#toc .active { + font-weight: bold; + color: #007bff; + font-size: 16px; +} + +.toc_H2 { + font-size: 16px; + font-weight: bold; + margin-bottom: 10px; + color: #006699; + font-weight: bold; +} + +.toc_H3 { + font-size: 14px; + margin-bottom: 10px; + color: #006699; +} + +.content_list_h1 { + font-size: 20px; + font-weight: bold; + margin-bottom: 10px; + border-bottom: solid 1px #006699; + color: #006699; +} + + +.content_list_h2 { + font-size: 16px; + font-weight: bold; + margin-bottom: 10px; + color: #006699; +} + +.content_list_problem { + font-size: 14px; + font-weight: bold; + margin-bottom: 10px; + color: #006699; +} + +.badge { + padding: 8px 20px; + border-radius: 25px; + font-size: 14px; + font-weight: bold; + color: #666; + border: 1px solid #333; + margin: 0 8px; + float: left; +} + +.runbutton, +.submitbutton { + display: inline-block; + padding: 10px 20px; + border: none; + border-radius: 5px; + font-size: 16px; + color: #fff; + cursor: pointer; + text-align: center; + text-decoration: none; +} + +.runbutton { + background-color: #006699; +} + +.runbutton:hover { + background-color: #005580; +} + +.submitbutton { + background-color: #008000; +} + +.submitbutton:hover { + background-color: #006400; +} + +.problem_title { + font-size: 20px; + font-weight: bold; + color: #333; +} + +.editor { + width: 100%; + height: 300px; + font-size: 16px; + font-family: monospace; + background-color: #F2F2F2; + color: #333; + padding: 10px; + border: solid 1px #a8a8a8; +} + +.output, +.expect_out, +.sample_in, +.sample_out { + width: 100%; + padding: 5px 5px; + overflow-x: auto; + font-size: 16px; + font-family: monospace; + background-color: #F2F2F2; + color: #333; + border: solid 1px #a8a8a8; +} + +.box-title, +.problem_list { + font-size: 14px; + font-weight: bold; + margin-bottom: 10px; + color: #666; +} + +)" \ No newline at end of file diff --git a/src/light.html b/src/light.html deleted file mode 100644 index 5afccee..0000000 --- a/src/light.html +++ /dev/null @@ -1,376 +0,0 @@ -R"( - - - - - {{title}} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- -
- - -

{{title}}

- -
-
-
-
- - - - {{contents}} - -
- - - - - - -)" \ No newline at end of file diff --git a/src/render.hpp b/src/render.hpp index 77d295f..bc0e945 100644 --- a/src/render.hpp +++ b/src/render.hpp @@ -11,16 +11,20 @@ namespace almo { std::string LIGHT_THEME = - #include "light.html" + #include "light.css" ; std::string DARK_THEME = - #include "dark.html" + #include "dark.css" ; std::string RUNNER = #include "runner.js" ; + std::string TEMPLATE = + #include "template.html" + ; + std::string SIDEBAR_BULDER = #include "sidebar.js" ; @@ -55,12 +59,13 @@ namespace almo { } std::string load_html_template(std::string theme) { - std::string html_template; + std::string result; if (theme == "light") { - html_template = LIGHT_THEME; + // replace {{style}} in TEMPLATE + result = std::regex_replace(TEMPLATE, std::regex("\\{\\{style\\}\\}"), LIGHT_THEME); } else if (theme == "dark") { - html_template = DARK_THEME; + result = std::regex_replace(TEMPLATE, std::regex("\\{\\{style\\}\\}"), DARK_THEME); } else { std::cerr << "Invalid theme: " << theme << ", available themes are 'dark' and 'light'" << std::endl; exit(1); @@ -69,27 +74,27 @@ namespace almo { // find and put runner.js before it std::string runner = RUNNER; std::string sidebar_builder = SIDEBAR_BULDER; - std::string::size_type pos = html_template.find(""); + std::string::size_type pos = result.find(""); if (pos != std::string::npos) { - html_template.insert(pos, runner); + result.insert(pos, runner); } else { std::cerr << "Invalid html template" << std::endl; exit(1); } - pos = html_template.find(""); + pos = result.find(""); if (pos != std::string::npos) { - html_template.insert(pos, sidebar_builder); + result.insert(pos, sidebar_builder); } else { std::cerr << "Invalid html template" << std::endl; exit(1); } - return html_template; + return result; } std::string replace_template(std::string html_template, nlohmann::json json_meta_data, std::string contents) { diff --git a/src/template.html b/src/template.html new file mode 100644 index 0000000..a96aff3 --- /dev/null +++ b/src/template.html @@ -0,0 +1,103 @@ +R"( + + + + + + {{title}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ + +

{{title}}

+ +
+
+
+
+ + + + {{contents}} + +
+ + + + + + + +)" \ No newline at end of file From 3eeec4d90c707f39412dd925663b98a1905e977e Mon Sep 17 00:00:00 2001 From: abap34 Date: Sat, 23 Sep 2023 16:44:27 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E3=83=87=E3=83=90=E3=83=83=E3=82=B0?= =?UTF-8?q?=E3=81=A7=E5=87=BA=E5=8A=9B=E5=85=88=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E5=90=8D=E3=82=82=E8=A8=98=E9=8C=B2=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/almo.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/almo.cpp b/src/almo.cpp index 50dfbd5..793aab6 100644 --- a/src/almo.cpp +++ b/src/almo.cpp @@ -13,6 +13,7 @@ int main(int argc, char *argv[]){ // default std::string theme = "light"; std::string out_path = "index.html"; + bool debug = false; for (int i = 2; i < argc; i++){ if (argv[i][0] == '-'){ @@ -28,11 +29,7 @@ int main(int argc, char *argv[]){ theme = argv[i + 1]; } else if (argv[i][1] == 'd'){ - nlohmann::json all_data; - all_data["meta_data"] = json_meta_data; - all_data["ir"] = json_ir; - std::cout << all_data.dump(4) << std::endl; - return 0; + debug = true; } else if (argv[i][1] == 'h'){ if (argc > 3){ @@ -56,6 +53,15 @@ int main(int argc, char *argv[]){ } json_meta_data["theme"] = theme; + json_meta_data["out_path"] = out_path; + + if (debug) { + nlohmann::json all_data; + all_data["meta"] = json_meta_data; + all_data["ir"] = json_ir; + std::cout << all_data.dump(4) << std::endl; + } + almo::render(json_ir, json_meta_data, out_path); return 0; } \ No newline at end of file