Skip to content

Commit

Permalink
✨ html export experience
Browse files Browse the repository at this point in the history
  • Loading branch information
tw93 committed Sep 12, 2023
1 parent 2eebb11 commit 09ce1c6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Mac/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1775,10 +1775,10 @@ CA
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Export" id="LoU-Gc-oM3">
<items>
<menuItem title="PDF" alternate="YES" keyEquivalent="P" id="UcZ-Ne-qv1">
<menuItem title="HTML" alternate="YES" keyEquivalent="H" id="Ge6-vi-x3q">
<modifierMask key="keyEquivalentModifierMask" control="YES"/>
<connections>
<action selector="exportPdf:" target="XfG-lQ-9wD" id="DiT-Ue-MTm"/>
<action selector="exportHtml:" target="XfG-lQ-9wD" id="pZF-N2-y4v"/>
</connections>
</menuItem>
<menuItem title="Image" alternate="YES" keyEquivalent="I" id="GsA-uj-XlT">
Expand All @@ -1787,10 +1787,10 @@ CA
<action selector="exportImage:" target="XfG-lQ-9wD" id="CHV-dY-HtD"/>
</connections>
</menuItem>
<menuItem title="HTML" alternate="YES" keyEquivalent="H" id="Ge6-vi-x3q">
<menuItem title="PDF" alternate="YES" keyEquivalent="P" id="UcZ-Ne-qv1">
<modifierMask key="keyEquivalentModifierMask" control="YES"/>
<connections>
<action selector="exportHtml:" target="XfG-lQ-9wD" id="pZF-N2-y4v"/>
<action selector="exportPdf:" target="XfG-lQ-9wD" id="DiT-Ue-MTm"/>
</connections>
</menuItem>
<menuItem title="MiaoYan PPT PDF" alternate="YES" keyEquivalent="P" id="DhD-mk-T1u">
Expand Down
15 changes: 10 additions & 5 deletions Mac/View/MPreviewView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class MPreviewView: WKWebView, WKUIDelegate, WKNavigationDelegate {
menuItem.identifier?.rawValue == "WKMenuItemIdentifierTranslate" ||
menuItem.identifier?.rawValue == "WKMenuItemIdentifierSearchWeb" ||
menuItem.identifier?.rawValue == "WKMenuItemIdentifierShareMenu" ||
menuItem.identifier?.rawValue == "WKMenuItemIdentifierLookUp" {
menuItem.identifier?.rawValue == "WKMenuItemIdentifierLookUp"
{
menuItem.isHidden = true
}
}
Expand Down Expand Up @@ -550,7 +551,8 @@ class MPreviewView: WKWebView, WKUIDelegate, WKNavigationDelegate {

class HandlerCheckbox: NSObject, WKScriptMessageHandler {
func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
didReceive message: WKScriptMessage)
{
guard let position = message.body as? String else { return }
guard let note = EditTextView.note else { return }

Expand Down Expand Up @@ -590,7 +592,8 @@ class HandlerCodeCopy: NSObject, WKScriptMessageHandler {
}

func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
didReceive message: WKScriptMessage)
{
let message = (message.body as! String).trimmingCharacters(in: .whitespacesAndNewlines)

HandlerCodeCopy.selectionString = message
Expand All @@ -601,7 +604,8 @@ class HandlerSelection: NSObject, WKScriptMessageHandler {
public static var selectionString: String?

func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
didReceive message: WKScriptMessage)
{
let message = (message.body as! String).trimmingCharacters(in: .whitespacesAndNewlines)

HandlerSelection.selectionString = message
Expand All @@ -611,7 +615,8 @@ class HandlerSelection: NSObject, WKScriptMessageHandler {
// 用于解决ppt模式下背景颜色变化左侧边框颜色的适配
class HandlerRevealBackgroundColor: NSObject, WKScriptMessageHandler {
func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
didReceive message: WKScriptMessage)
{
guard let vc = ViewController.shared() else { return }
let message = (message.body as! String).trimmingCharacters(in: .whitespacesAndNewlines)
if message == "" {
Expand Down
13 changes: 9 additions & 4 deletions Mac/View/MarkdownView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ open class MarkdownView: WKWebView {
return "html {font-size: \(UserDefaultsManagement.presentationFontSize)px} :root { --text-font: \(UserDefaultsManagement.previewFontName), sans-serif; --code-text-font: \(codeFontName),sans-serif; } #write { max-width: 100%;}"
} else {
let paddingStyle = UserDefaultsManagement.isOnExport ? " padding-top: 24px" : ""
return "html {font-size: \(UserDefaultsManagement.previewFontSize)px; \(paddingStyle)} :root { --text-font: \(UserDefaultsManagement.previewFontName), sans-serif; --code-text-font: \(codeFontName),sans-serif; } #write { max-width: \(UserDefaultsManagement.previewWidth);}"
let writeCSS = UserDefaultsManagement.isOnExportHtml ? " max-width: 800px; margin: 0 auto" : "max-width: \(UserDefaultsManagement.previewWidth);"

return "html {font-size: \(UserDefaultsManagement.previewFontSize)px; \(paddingStyle)} :root { --text-font: \(UserDefaultsManagement.previewFontName), sans-serif; --code-text-font: \(codeFontName),sans-serif; } #write { \(writeCSS)}"
}
}

Expand Down Expand Up @@ -239,7 +241,8 @@ extension MarkdownView: WKNavigationDelegate {

class HandlerCopyCode: NSObject, WKScriptMessageHandler {
func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
didReceive message: WKScriptMessage)
{
let message = (message.body as! String).trimmingCharacters(in: .whitespacesAndNewlines)
let pasteboard = NSPasteboard.general
pasteboard.declareTypes([NSPasteboard.PasteboardType.string], owner: nil)
Expand All @@ -249,14 +252,16 @@ class HandlerCopyCode: NSObject, WKScriptMessageHandler {

class HandlerMouseOver: NSObject, WKScriptMessageHandler {
func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
didReceive message: WKScriptMessage)
{
NSCursor.pointingHand.set()
}
}

class HandlerMouseOut: NSObject, WKScriptMessageHandler {
func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
didReceive message: WKScriptMessage)
{
NSCursor.arrow.set()
}
}

0 comments on commit 09ce1c6

Please sign in to comment.