Render Markdown HTML and save viewer appearance in Files Options
Refs #38 Refs #8
This commit is contained in:
1 parent
eaae5389d9
commit
b28789a4f5
16 files changed
+349
-40
No files matched your search
@@ -83,6 +83,15 @@ TextSettings loadTextPreferences()
|
||||
const auto data = nlohmann::json::parse(readFile(combined, 64 * 1024));
|
||||
for (size_t i = 0; i < profiles.size(); ++i)
|
||||
if (data.contains(profileNames[i])) readTextProfile(profiles[i], data.at(profileNames[i]));
|
||||
if (const auto markdown=data.find("markdown");markdown!=data.end() && markdown->is_object())
|
||||
{
|
||||
if (const auto width=markdown->find("width");width!=markdown->end() && width->is_number_unsigned() && *width<=999999)
|
||||
settings.markdown.width=width->get<unsigned>();
|
||||
if (const auto size=markdown->find("fontSize");size!=markdown->end() && size->is_number_unsigned() && *size>=8 && *size<=72)
|
||||
settings.markdown.fontSize=size->get<unsigned>();
|
||||
if (const auto family=markdown->find("font");family!=markdown->end() && family->is_string())
|
||||
settings.markdown.font=wide(family->get<std::string>()).substr(0,LF_FACESIZE-1);
|
||||
}
|
||||
if (data.contains("schemes") && data.at("schemes").is_array())
|
||||
for (const auto &entry : data.at("schemes"))
|
||||
{
|
||||
@@ -126,6 +135,8 @@ void saveTextPreferences(const TextSettings &settings)
|
||||
auto &schemes = data["schemes"] = nlohmann::json::array();
|
||||
for (const auto &scheme : settings.schemes)
|
||||
schemes.push_back({{"name", utf8(scheme.name)}, {"colors", scheme.colors}});
|
||||
data["markdown"]={{"width",settings.markdown.width},{"fontSize",settings.markdown.fontSize},
|
||||
{"font",utf8(settings.markdown.font)}};
|
||||
const auto json = data.dump(2);
|
||||
atomicWrite(dataDirectory() / L"files-text.json", Bytes(json.begin(), json.end()));
|
||||
}
|
||||
@@ -863,6 +874,7 @@ private:
|
||||
void updatePreview();
|
||||
void stopPreview(bool refresh=true,bool keepBrowser=false);
|
||||
void renderPreview(bool keepPosition=false);
|
||||
void applyMarkdownPreferences(const MarkdownPreferences &preferences);
|
||||
std::optional<FileStamp> previewFileStamp() const;
|
||||
void refreshPreview();
|
||||
void cancelPreviewImages();
|
||||
@@ -1134,7 +1146,9 @@ void TextWindow::reloadPreferences()
|
||||
return;
|
||||
}
|
||||
pendingPreferences = false;
|
||||
auto profile = loadTextPreferences().profiles[edit];
|
||||
auto settings = loadTextPreferences();
|
||||
applyMarkdownPreferences(settings.markdown);
|
||||
auto &profile = settings.profiles[edit];
|
||||
const auto font = search.style.readFont();
|
||||
const bool fontChanged = font.tenthsOfPoint != filesFont.tenthsOfPoint ||
|
||||
std::memcmp(&font.font, &filesFont.font, sizeof(LOGFONTW)) != 0;
|
||||
@@ -1547,6 +1561,7 @@ std::optional<TextWindow::FileStamp> TextWindow::previewFileStamp() const
|
||||
|
||||
void TextWindow::renderPreview(bool keepPosition)
|
||||
{
|
||||
applyMarkdownPreferences(loadTextPreferences().markdown);
|
||||
previewDeadline=GetTickCount64()+30000;
|
||||
std::string text;
|
||||
for(uint64_t index=0;index<document->pages();++index)
|
||||
@@ -1560,6 +1575,13 @@ void TextWindow::renderPreview(bool keepPosition)
|
||||
preview.post(wide(message.dump(-1,' ',false,nlohmann::json::error_handler_t::replace)));
|
||||
}
|
||||
|
||||
void TextWindow::applyMarkdownPreferences(const MarkdownPreferences &preferences)
|
||||
{
|
||||
if(!preview.initialized()) return;
|
||||
preview.post(wide(nlohmann::json{{"action","appearance"},{"width",preferences.width},
|
||||
{"fontSize",preferences.fontSize},{"font",utf8(preferences.font)}}.dump()));
|
||||
}
|
||||
|
||||
void TextWindow::refreshPreview()
|
||||
{
|
||||
if(remote || !previewVisible || navigation.valid() || GetTickCount64()<nextFileCheck) return;
|
||||
|
||||
Reference in new issue
Block a user