Skip to content

Commit

Permalink
generate preview.html at markdown path
Browse files Browse the repository at this point in the history
  • Loading branch information
fungaren committed Jun 17, 2021
1 parent 7e07c8b commit dbf8c5a
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 60 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ Makefile
cmake_install.cmake
/**/CMakeFiles

# CMake generated
.vscode
inc/config.h
install_manifest.txt
static/mynotepad.desktop
mynotepad
preview.html
14 changes: 2 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.0)
project(mynotepad)

if (COMMAND cmake_policy)
# Works around warnings libraries linked against that don't
# have absolute paths (e.g. -lpthreads)
cmake_policy(SET CMP0003 NEW)

# Qt5 qt5_use_modules usage was causing "Policy CMP0043 is not set:
# Ignore COMPILE_DEFINITIONS_<Config> properties." warnings
cmake_policy(SET CMP0043 NEW)
endif()

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
#add_definitions("$<$<CONFIG:Debug>:-D_DEBUG>")

Expand Down Expand Up @@ -39,7 +29,7 @@ endif()

set(MYNOTEPAD_VERSION_MAJOR 1)
set(MYNOTEPAD_VERSION_MINOR 0)
set(MYNOTEPAD_VERSION_PATCH 5)
set(MYNOTEPAD_VERSION_PATCH 6)
message(STATUS "MyNotePad version: ${MYNOTEPAD_VERSION_MAJOR}."
"${MYNOTEPAD_VERSION_MINOR}.${MYNOTEPAD_VERSION_PATCH}")

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MyNotePad
# MyNotePad

![logo](static/MyNotePad.ico)
![logo](static/mynotepad.ico)

## Synopsis

Expand Down Expand Up @@ -40,7 +40,7 @@ That's all. Run `mynotepad` to launch the program.

2. Extract them to the same folder and merge the `lib/vc14x_x64_dll` folder. For example, the directory tree is like:

```
```text
D:\
|----wxWidgets-3.1.3
|---------------include
Expand All @@ -55,6 +55,7 @@ D:\
|-------------wxrc.exe
......
```

See [CMakeLists.txt](CMakeLists.txt) for more detail.

3. Then open CMake-GUI, click `Browse Source` and `Browse Build` to choose a correct place.
Expand Down
2 changes: 1 addition & 1 deletion inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const char* MNP_APPNAME_C = "MyNotePad";
const wchar_t* MNP_APPNAME = L"MyNotePad";
const char* MNP_DOC_TITLE = " - MyNotePad";
const char* MNP_DOC_NOTITLE = "Untitled";
const wchar_t* MNP_COPYRIGHT = L"\nCopyright(c) moooc.cc 2020";
const wchar_t* MNP_COPYRIGHT = L"\nCopyright(c) moooc.cc";

int MNP_PADDING_LEFT = 16; // space for line number
const int MNP_LINENUM_MARGIN_LEFT = 4;
Expand Down
3 changes: 2 additions & 1 deletion md2html/src/parser.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "lex_parse.h"
#include <sstream>
#include "lex_parse.h"
bool isTableItem(const MD_TOKEN token)
{
return token == MD_TOKEN::TABLE_COLUMN_LEFT ||
Expand Down
40 changes: 22 additions & 18 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ void MyFrame::loadSettings()
article->SetMarginWidth(wxSTC_MARGINOPTION_NONE, FromDIP(MNP_PADDING_LEFT * 2));

#ifdef _WIN32
confFilePath = wxStandardPaths::Get().GetExecutablePath();
while (confFilePath.back() != '\\')
confFilePath.pop_back();
confFilePath = wxPathOnly(wxStandardPaths::Get().GetExecutablePath()) + '\\';
#else
confFilePath = wxStandardPaths::Get().GetUserDataDir();
confFilePath += '/';
Expand Down Expand Up @@ -384,17 +382,15 @@ void MyFrame::saveHTML(const std::string pathname)
return;
}

f << "<!DOCTYPE><html><head><meta charset=\"utf-8\"/>";
f << "<!DOCTYPE><html><head><meta charset='utf-8'/>";
#ifdef WIN32
f << R"raw(
<link href="style.css" rel="stylesheet">
<link href="highlight.css" rel="stylesheet">
<script type="text/javascript" src="highlight.pack.js"></script>
)raw";
f << "<link href='file:///" << confFilePath << "style.css' rel='stylesheet'>\n"
<< "<link href='file:///" << confFilePath << "highlight.css' rel='stylesheet'>\n"
<< "<script type='text/javascript' src='file:///" << confFilePath << "highlight.pack.js'></script>\n";
#else
f << "<link href='" << MNP_INSTALL_PATH << "style.css' rel='stylesheet'>\n";
f << "<link href='" << MNP_INSTALL_PATH << "highlight.css' rel='stylesheet'>\n";
f << "<script type='text/javascript' src='" << MNP_INSTALL_PATH << "highlight.pack.js'></script>\n";
f << "<link href='file:///" << MNP_INSTALL_PATH << "style.css' rel='stylesheet'>\n"
<< "<link href='file:///" << MNP_INSTALL_PATH << "highlight.css' rel='stylesheet'>\n"
<< "<script type='text/javascript' src='file:///" << MNP_INSTALL_PATH << "highlight.pack.js'></script>\n";
#endif
f << R"raw(<script type="text/javascript">
window.onload = function() {
Expand All @@ -410,8 +406,8 @@ void MyFrame::saveHTML(const std::string pathname)
md2html(str);

f << cvt.to_bytes(str);
f << "</main><center><small>Created by <a href=\"https:/"\
"/github.com/mooction/MyNotePad\">MyNotePad</a>.</small></center>";
f << "</main><center><small>Created by <a href='https:/"\
"/github.com/mooction/MyNotePad'>MyNotePad</a>.</small></center>";
if (str.find(L'$') != std::string::npos ||
str.find(L"\\[") != std::string::npos ||
str.find(L"\\(") != std::string::npos)
Expand Down Expand Up @@ -456,7 +452,7 @@ void MyFrame::md2html(std::wstring& str)
clock_t end = clock();
double t = double(end - begin) / CLOCKS_PER_SEC;
wos << L"<br><p>elapsed time: " << std::setprecision(2) << t << L" s</p>";
#endif // SHOW_PARSING_TIME
#endif

str = wos.str();
}
Expand Down Expand Up @@ -897,12 +893,20 @@ void MyFrame::OnFontSelect(wxCommandEvent& WXUNUSED(event))

void MyFrame::OnBrowser(wxCommandEvent& WXUNUSED(event))
{
std::string s;
if (openedFile == MNP_DOC_NOTITLE) {
#ifdef _WIN32
std::string s = confFilePath + "preview.html";
s = confFilePath + "preview.html";
} else {
s = wxPathOnly(openedFile).ToStdString() + "\\preview.html";
#else
wxString path = wxStandardPaths::Get().GetTempDir() + "/preview.html";
std::string s = path.ToStdString();
wxString path = wxStandardPaths::Get().GetTempDir() + "/preview.html";
s = path.ToStdString();
} else {
s = wxPathOnly(openedFile).ToStdString() + "/preview.html";
#endif
}

saveHTML(s);
LOG_MESSAGE(s);
wxLaunchDefaultApplication(s);
Expand Down
54 changes: 30 additions & 24 deletions static/style.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
body {
font-family: Noto Sans CJK SC, Microsoft JhengHei UI, Microsoft Yahei, WenQuanYi Micro Hei, helvetica, arial, sans-serif;
font-size: 20px;
color: #444;
background-color: #eee;
word-wrap: break-word;
font-size: 20px;
color: #444;
background-color: #eee;
word-wrap: break-word;
}

body, div, dl, dt, dd, ul, ol, li, code, h1, h2, h3, h4, h5, h6, form,
Expand Down Expand Up @@ -43,7 +43,7 @@ img {max-width: 100%}
pre {
background: #f7f7f7 !important;
overflow-x: scroll;
font-size: 18px;
font-size: 18px;
font-family: Noto Mono, Consolas, Lucida Console, Noto Mono, DejaVu Sans Mono, Courier New;
}
code {
Expand All @@ -60,45 +60,51 @@ blockquote {
}
ul {
margin: 18px;
padding-left: 8px;
padding-left: 8px;
}
ol {
padding-left: 40px;
}
li {
margin: 2px 0;
}

/* Table
===============================================*/
table {
width: 100%;
border-spacing:0;
border-left: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
border-left: 1px solid #ccc;
margin: 18px 0;
}
}
th {
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
color: #444;
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
font-size: 20px;
padding: 6px 6px 6px 12px;
background: #CAE8EA no-repeat;
}
background: #eee no-repeat;
}
td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
padding: 6px 6px 6px 12px;
color: #4f6b72;
color: #444;
font-size: 17px;
word-break: break-all;
}
td.alt {background: #F5FAFA;color: #797268;}
th.spec,td.spec {border-left: 1px solid #C1DAD7;}
tr:nth-child(odd) {background: #fff;}
tr:nth-child(even) {background: #F5FAFA;}
td.alt {background: #fff;color: #fff;}
th.spec,td.spec {border-left: 1px solid #ccc;}
tr:nth-child(odd) {background: #fff;}
tr:nth-child(even) {background: #f7f7f7;}

::selection {background:rgba(0,144,255,0.15)}
::-moz-selection {background:rgba(0,144,255,0.15)}
main {
margin: 60px auto;
width: 61.8%;
min-width: 900px;
background-color: #fff;
padding: 32px;
background-color: #fff;
padding: 32px;
}
Binary file modified static/wx.rc
Binary file not shown.

0 comments on commit dbf8c5a

Please sign in to comment.