1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +00:00

TextEditor: Add live preview when editing markdown :^)

This works by hooking into the change notifications from the TextEditor
widget and parsing the document content as markdown, and generating an
HTML document from it which is displayed using LibWeb.

This will make it a bit easier to write man pages! :^)
This commit is contained in:
Andreas Kling 2020-04-28 21:42:45 +02:00
parent ea204ef05b
commit 5eaa7ff406
3 changed files with 58 additions and 6 deletions

View file

@ -33,7 +33,7 @@
#include <LibGUI/TextEditor.h>
#include <LibGUI/Widget.h>
#include <LibGUI/Window.h>
#include <LibWeb/Forward.h>
class TextEditorWidget final : public GUI::Widget {
C_OBJECT(TextEditorWidget)
public:
@ -43,10 +43,13 @@ public:
GUI::TextEditor& editor() { return *m_editor; }
void set_markdown_preview_enabled(bool);
private:
TextEditorWidget();
void set_path(const FileSystemPath& file);
void update_title();
void update_markdown_preview();
virtual void drop_event(GUI::DropEvent&) override;
@ -60,6 +63,7 @@ private:
RefPtr<GUI::Action> m_save_as_action;
RefPtr<GUI::Action> m_find_replace_action;
RefPtr<GUI::Action> m_line_wrapping_setting_action;
RefPtr<GUI::Action> m_markdown_preview_action;
RefPtr<GUI::Action> m_find_next_action;
RefPtr<GUI::Action> m_find_previous_action;
RefPtr<GUI::Action> m_replace_next_action;
@ -84,6 +88,9 @@ private:
RefPtr<GUI::Action> m_cpp_highlight;
RefPtr<GUI::Action> m_js_highlight;
RefPtr<Web::HtmlView> m_html_view;
bool m_document_dirty { false };
bool m_document_opening { false };
bool m_markdown_preview_enabled { false };
};