Skip to content

Commit

Permalink
💩 merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tw93 committed Jul 31, 2022
2 parents 4fefca5 + 96eb467 commit 473884c
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 103 deletions.
1 change: 0 additions & 1 deletion Mac/AppDelegate+URLRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ extension AppDelegate {
}

// MARK: - MiaoYan routes

func MiaoYanRouter(_ url: URL) {
guard let directive = url.host else { return }

Expand Down
5 changes: 5 additions & 0 deletions Mac/Helpers/NotesTextProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,10 @@ public class NotesTextProcessor {

public static let todoInlineRegex = MarklightRegex(pattern: todoInlinePattern, options: [.allowCommentsAndWhitespace, .anchorsMatchLines])

fileprivate static let allTodoInlinePattern = "((-\\ \\[(?:\\ |x)\\])\\ )"

public static let allTodoInlineRegex = MarklightRegex(pattern: allTodoInlinePattern, options: [.allowCommentsAndWhitespace, .anchorsMatchLines])

// MARK: Code

/*
Expand Down Expand Up @@ -1347,6 +1351,7 @@ public class NotesTextProcessor {
attributedString.addAttribute(NoteAttribute.highlight, value: true, range: subRange)
}
attributedString.addAttribute(NSAttributedString.Key.backgroundColor, value: titleColor, range: subRange)
attributedString.addAttribute(.foregroundColor, value: NotesTextProcessor.syntaxColor, range: subRange)
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion Mac/Helpers/UserDefaultsManagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public enum UserDefaultsManagement {
if let dl = UserDefaults.standard.object(forKey: Constants.EditorLineBreak) as? String {
return dl
}
return "Default"
return "MiaoYan"
}
set {
UserDefaults.standard.set(newValue, forKey: Constants.EditorLineBreak)
Expand Down
68 changes: 50 additions & 18 deletions Mac/MPreviewView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MPreviewView: WKWebView, WKUIDelegate, WKNavigationDelegate {
init(frame: CGRect, note: Note, closure: MPreviewViewClosure?) {
self.closure = closure
let userContentController = WKUserContentController()
userContentController.add(HandlerCheckbox(), name: "checkbox")
userContentController.add(HandlerSelection(), name: "newSelectionDetected")
userContentController.add(HandlerCodeCopy(), name: "notification")

Expand Down Expand Up @@ -89,10 +90,11 @@ class MPreviewView: WKWebView, WKUIDelegate, WKNavigationDelegate {
override func willOpenMenu(_ menu: NSMenu, with event: NSEvent) {
for menuItem in menu.items {
if menuItem.identifier?.rawValue == "WKMenuItemIdentifierSpeechMenu" ||
menuItem.identifier?.rawValue == "WKMenuItemIdentifierTranslate" ||
menuItem.identifier?.rawValue == "WKMenuItemIdentifierSearchWeb" ||
menuItem.identifier?.rawValue == "WKMenuItemIdentifierShareMenu" ||
menuItem.identifier?.rawValue == "WKMenuItemIdentifierLookUp" {
menuItem.identifier?.rawValue == "WKMenuItemIdentifierTranslate" ||
menuItem.identifier?.rawValue == "WKMenuItemIdentifierSearchWeb" ||
menuItem.identifier?.rawValue == "WKMenuItemIdentifierShareMenu" ||
menuItem.identifier?.rawValue == "WKMenuItemIdentifierLookUp"
{
menuItem.isHidden = true
}
}
Expand Down Expand Up @@ -125,8 +127,7 @@ class MPreviewView: WKWebView, WKUIDelegate, WKNavigationDelegate {
}
}
}
} else {
}
} else {}
}

public func scrollToPosition(pre: CGFloat) {
Expand All @@ -153,8 +154,7 @@ class MPreviewView: WKWebView, WKUIDelegate, WKNavigationDelegate {
}
})
}
} else {
}
} else {}
}

public func exportImage() {
Expand Down Expand Up @@ -192,8 +192,7 @@ class MPreviewView: WKWebView, WKUIDelegate, WKNavigationDelegate {
}
})
}
} else {
}
} else {}
}

public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
Expand Down Expand Up @@ -282,9 +281,9 @@ class MPreviewView: WKWebView, WKUIDelegate, WKNavigationDelegate {

private func isFootNotes(url: URL) -> Bool {
let webkitPreview = URL(fileURLWithPath: NSTemporaryDirectory())
.appendingPathComponent("wkPreview")
.appendingPathComponent("index.html")
.absoluteString
.appendingPathComponent("wkPreview")
.appendingPathComponent("index.html")
.absoluteString

let link = url.absoluteString.replacingOccurrences(of: webkitPreview, with: "")
if link.starts(with: "#") {
Expand Down Expand Up @@ -403,8 +402,8 @@ class MPreviewView: WKWebView, WKUIDelegate, WKNavigationDelegate {
let webkitPreview = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("wkPreview")

let create = webkitPreview
.appendingPathComponent(localPathClean)
.deletingLastPathComponent()
.appendingPathComponent(localPathClean)
.deletingLastPathComponent()
let destination = webkitPreview.appendingPathComponent(localPathClean)

try? FileManager.default.createDirectory(atPath: create.path, withIntermediateDirectories: true, attributes: nil)
Expand Down Expand Up @@ -444,7 +443,7 @@ class MPreviewView: WKWebView, WKUIDelegate, WKNavigationDelegate {

template = template.replacingOccurrences(of: "DOWN_CSS", with: css) as NSString

if (UserDefaultsManagement.isOnExport) {
if UserDefaultsManagement.isOnExport {
template = template.replacingOccurrences(of: "DOWN_EXPORT_TYPE", with: "ppt") as NSString
}

Expand Down Expand Up @@ -475,6 +474,37 @@ class MPreviewView: WKWebView, WKUIDelegate, WKNavigationDelegate {
}
}

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

let content = note.content.unLoadCheckboxes().unLoadImages()
let string = content.string
let range = NSRange(0 ..< string.count)

var i = 0
NotesTextProcessor.allTodoInlineRegex.matches(string, range: range) { result in
guard let range = result?.range else { return }

if i == Int(position) {
let substring = content.mutableString.substring(with: range)

if substring.contains("- [x] ") {
content.replaceCharacters(in: range, with: "- [ ] ")
} else {
content.replaceCharacters(in: range, with: "- [x] ")
}
note.save(content: content)
}

i = i + 1
}
}
}

class HandlerCodeCopy: NSObject, WKScriptMessageHandler {
public static var selectionString: String? {
didSet {
Expand All @@ -487,7 +517,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 @@ -498,7 +529,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 Down
2 changes: 0 additions & 2 deletions Mac/View/NotesTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class NotesTableView: NSTableView, NSTableViewDataSource,
} else {
scrollRowToVisible(row)
}


} else {
scrollRowToVisible(row)
}
Expand Down
7 changes: 1 addition & 6 deletions Mac/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1975,23 +1975,18 @@ class ViewController: NSViewController,

UserDefaultsManagement.preview = false

guard let vc = ViewController.shared() else {
return
}
editArea.markdownView?.removeFromSuperview()
editArea.markdownView = nil

guard let editor = editArea else {
return
}
editor.subviews.removeAll(where: { $0.isKind(of: MPreviewView.self) })

refillEditArea()
notesTableView.deselectNotes()
editArea.string = text
EditTextView.note = note
search.stringValue.removeAll()
vc.titleLabel.isEditable = true
titleLabel.isEditable = true
emptyEditAreaView.isHidden = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
vc.titleLabel.editModeOn()
Expand Down
4 changes: 2 additions & 2 deletions Mac/en.lproj/Main.strings
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@
/* Class = "NSMenuItem"; title = "Search"; ObjectID = "hPY-aY-QOE"; */
"hPY-aY-QOE.title" = "Search";

/* Class = "NSMenuItem"; title = "Pin/unpin"; ObjectID = "jFN-Dp-LON"; */
"jFN-Dp-LON.title" = "Pin/unpin";
/* Class = "NSMenuItem"; title = "Pin/unPin"; ObjectID = "jFN-Dp-LON"; */
"jFN-Dp-LON.title" = "Pin/unPin";

/* Class = "NSMenuItem"; title = "Rename"; ObjectID = "jLq-8F-n0X"; */
"jLq-8F-n0X.title" = "Rename";
Expand Down
8 changes: 4 additions & 4 deletions MiaoYan.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.1.0;
CURRENT_PROJECT_VERSION = 1.1.1;
DEVELOPMENT_TEAM = 5EH69Y5X38;
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -1199,7 +1199,7 @@
INFOPLIST_FILE = Mac/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tw93.MiaoYan;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1222,7 +1222,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.1.0;
CURRENT_PROJECT_VERSION = 1.1.1;
DEPLOYMENT_LOCATION = NO;
DEVELOPMENT_TEAM = 5EH69Y5X38;
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
Expand All @@ -1236,7 +1236,7 @@
INFOPLIST_FILE = Mac/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tw93.MiaoYan;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,12 @@
- 🏌🏽‍♂️ ****:使用 Swift5 原生开发,相比 Web 套壳方式性能体验好
- 🩴 ****:很轻巧,纯编辑器输入体验,众多快捷键助你快人一步

## 为什么要做妙言

- 之前有尝试过众多的笔记应用,大学时期为知笔记、印象笔记,工作时候用过 Ulysses、Quiver、MWeb、Bear、Typora,种种原因,没有找到一个习惯的 Markdown 应用,才有了做妙言的想法。
- 本职工作为前端开发,会一点 iOS 开发,喜欢折腾,借妙言来玩一下 Swift 以及 macOS 开发,当做一个很愉快的事情。

## 安装

- 方式一:从 <a href="https://github.com/tw93/MiaoYan/releases" target="_blank">GitHub Releases</a> 中下载最新的 MiaoYan.dmg 安装包,双击安装即可,如果慢,可试试 [镜像](https://miaoyan-tw93.vercel.app/Release/MiaoYan.dmg) 下载,如遇无法安装情况,请参考 [文档](https://zhuanlan.zhihu.com/p/52389383)
- 方式二:使用命令行安装 ```brew install miaoyan --cask```
## 首次使用

## 初始化使用

1. 可以在 iCloud 或根目录下创建一个 `MiaoYan` 的文件夹,打开妙言的设置,将默认存储地址修改成这个。
2. 点击妙言左上角新增文件夹的图标,创建好自己的文档分类文件夹,就可以开始使用了。
3. 同样假如你不习惯默认的字体,可以在设置中修改成其他的正常字体。
1. 从 <a href="https://github.com/tw93/MiaoYan/releases" target="_blank">GitHub Releases</a> 中 **下载** 最新的 MiaoYan.dmg 安装包,双击安装即可,如安装出现问题请参考 [文档](https://zhuanlan.zhihu.com/p/52389383)
2. 可以在 iCloud 或根目录下创建一个 `MiaoYan` 的文件夹,打开妙言的设置,将默认存储地址修改成这个。
3. 点击妙言左上角新增文件夹的图标,创建好自己的文档分类文件夹,就可以开始使用了。
4. 同样假如你不习惯默认的字体,可以在设置中修改成其他的正常字体。

## 快捷键

Expand Down Expand Up @@ -78,6 +69,11 @@
3. 只有在有 `---` 分隔符标志的文档中,才可启用 PPT 模式,演示过程中你可以 `回车键` 预览演讲大纲,`ESC` 键可退出 PPT 模式。
4. 你可以使用 HTML 来自定义效果,更多复杂的用法可以参考 [Reveal](https://revealjs.com/markdown/) 文档。

## 为什么要做妙言

- 之前有尝试过众多的笔记应用,大学时期为知笔记、印象笔记,工作时候用过 Ulysses、Quiver、MWeb、Bear、Typora,种种原因,没有找到一个习惯的 Markdown 应用,才有了做妙言的想法。
- 本职工作为前端开发,会一点 iOS 开发,喜欢折腾,借妙言来玩一下 Swift 以及 macOS 开发,当做一个很愉快的事情。

## 支持

- 我有两只猫,一只叫汤圆,一只叫可乐,假如觉得妙言让你生活更美好,可以给汤圆可乐 <a href="https://miaoyan.app/cats.html" target="_blank">喂罐头 🥩🍤</a>。
Expand Down
24 changes: 9 additions & 15 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,12 @@
- 🏌🏽‍♂️ **Fast**: Using Swift5 native development, the performance experience is much better compared to the Web.
- 🩴 **Simple**: Very light, pure editor input experience, many shortcut keys to help you fast.

## Why do this

- I have tried many note-taking applications before, such as WizNote, Ulysses, Quiver, MWeb, Bear, Typora, for various reasons, I did not find a conventional Markdown application, so I had the idea of doing MiaoYan.
- My job is front-end development, but also can develop iOS App, love to toss new things, so develop MiaoYan as a fun leisure.

## Install

- Way1: Download the latest `MiaoYan.dmg` installation package from <a href="https://github.com/tw93/MiaoYan/releases/latest" target="_blank">GitHub Releases</a> and double-click to install it.
- Way2: Install with brew ```brew install miaoyan --cask```.

## First Use

1. You can create a `MiaoYan` folder in iCloud or the root directory, open MiaoYan's Settings, and change the default storage address to this.
2. Click icon of the new folder in the upper left corner of MiaoYan, create your own document category folder, and you can start using it.
3. Similarly, if you are not used to the default font, you can change it to other normal fonts in the settings.
1. **Download** the latest `MiaoYan.dmg` installation package from <a href="https://github.com/tw93/MiaoYan/releases/latest" target="_blank">GitHub Releases</a> and double-click to install it.
2. You can create a `MiaoYan` folder in iCloud or the root directory, open MiaoYan's Settings, and change the default storage address to this.
3. Click icon of the new folder in the upper left corner of MiaoYan, create your own document category folder, and you can start using it.
4. Similarly, if you are not used to the default font, you can change it to other normal fonts in the settings.

## Shortcut Keys

Expand Down Expand Up @@ -78,13 +69,16 @@
3. PPT mode can be enabled only in documents marked with `---` separator. During the presentation, You can preview the outline of the speech with `Enter` Key and exit ppt mode with `ESC` Key.
4. You can use HTML to customize the effect. For more complex usage, Please refer to [reveal](https://revealjs.com/markdown/) Documentation.

## Why do this

- I have tried many note-taking applications before, such as WizNote, Ulysses, Quiver, MWeb, Bear, Typora, for various reasons, I did not find a conventional Markdown application, so I had the idea of doing MiaoYan.
- My job is front-end development, but also can develop iOS App, love to toss new things, so develop MiaoYan as a fun leisure.

## Support

- I have two cats, one is called TangYuan, and one is called Coke, If you think MiaoYan makes your life better, you can give my cats <a href="https://miaoyan.app/cats.html" target="_blank">feed canned food 🥩🍤</a>.
- If you like MiaoYan, you can star it in Github. We are more welcome to [recommend MiaoYan](https://twitter.com/intent/tweet?text=%23%E5%A6%99%E8%A8%80%20MiaoYan%20-%20a%20simple%20and%20good-looking%20open-source%20mac%20markdown%20editor,%20without%20any%20redundant%20functions,%20is%20developed%20using%20swift,%20pure%20local%20use,%20has%20functions%20such%20as%20syntax%20highlighting,%20automatic%20formatting,%20presentation%20mode%20etc.&url=https://github.com/tw93/MiaoYan&via=HiTw93) to your like-minded friends.



## Thanks

- Thanks to <a href="https://vercel.com?utm_source=miaoyan&utm_campaign=oss"><a href="https://vercel.com?utm_source=tw93&utm_campaign=oss"><img src="https://gw.alipayobjects.com/zos/k/app/vercel-logotype-dark.jpg" height="13px"></a> for providing static rendering capability to [MiaoYan](https://miaoyan.app/). <a href="https://vercel.com?utm_source=tw93&utm_campaign=oss">
Expand Down
Loading

0 comments on commit 473884c

Please sign in to comment.