Skip to content

Commit

Permalink
Add new themes, add RTL support, fix list syntax highlighting
Browse files Browse the repository at this point in the history
- Now using a custom Highlightr fork
- Added support for RTL writing direction
- Fixed indented markdown list syntax highlighting not working
- Added a menu item under Format > Writing Direction to change writing direction
  • Loading branch information
lukakerr committed Mar 13, 2019
1 parent 90527f4 commit 296d9a8
Show file tree
Hide file tree
Showing 39 changed files with 1,641 additions and 586 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
[Unreleased]
### New Features
- Added support for WikiLink (`[[Description|./path/to/note.md]]`) markdown extensions
- Added RTL writing direction support in editor and preview
- Added 9 new themes:
- a11y-dark
- a11y-light
- an-old-hope
- gml
- isbl-editor-dark
- isbl-editor-light
- lightfair
- nord
- shades-of-purple

### Fixes
- Fix some themes having incorrect colors
- Fix `open -a` not working at times
- Fix indented markdown lists not getting syntax highlighted

### Other
- Refactored sidebar and tabs
- Now using [custom Highlightr fork](https://github.com/lukakerr/Highlightr)

## [0.0.8] - 2019-03-10
### New Features
Expand Down
3 changes: 3 additions & 0 deletions Pine/Assets.xcassets/DownArrow.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
3 changes: 3 additions & 0 deletions Pine/Assets.xcassets/Plus.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
3 changes: 3 additions & 0 deletions Pine/Assets.xcassets/Sidebar.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
58 changes: 45 additions & 13 deletions Pine/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -523,29 +523,61 @@
<action selector="HTMLImageWithSender:" target="Ady-hI-5gd" id="oYi-RG-595"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="B5f-vr-Mjt"/>
<menuItem title="Writing Direction" id="ZcV-iK-7Qq">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Writing Direction" id="6xY-VH-WYX">
<items>
<menuItem title="Paragraph" enabled="NO" id="HPh-FH-2cG">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem id="br4-5E-o8d">
<string key="title"> Default</string>
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="makeBaseWritingDirectionNatural:" target="Ady-hI-5gd" id="b7q-nf-Odu"/>
</connections>
</menuItem>
<menuItem id="gyK-rZ-Ygc">
<string key="title"> Left to Right</string>
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="makeBaseWritingDirectionLeftToRight:" target="Ady-hI-5gd" id="fG8-kc-xwl"/>
</connections>
</menuItem>
<menuItem id="IVV-m1-iqq">
<string key="title"> Right to Left</string>
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="makeBaseWritingDirectionRightToLeft:" target="Ady-hI-5gd" id="8rR-kw-MNt"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Window" id="aUF-d1-5bR">
<menuItem title="Window" id="zcS-xL-2Wp">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
<menu key="submenu" title="Window" systemMenu="window" id="asC-cO-ILV">
<items>
<menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV">
<menuItem title="Minimize" keyEquivalent="m" id="w79-Ym-U7w">
<connections>
<action selector="performMiniaturize:" target="Ady-hI-5gd" id="VwT-WD-YPe"/>
<action selector="performMiniaturize:" target="Ady-hI-5gd" id="VDN-Oc-YbE"/>
</connections>
</menuItem>
<menuItem title="Zoom" id="R4o-n2-Eq4">
<menuItem title="Zoom" id="W2h-fi-Yqy">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="performZoom:" target="Ady-hI-5gd" id="DIl-cC-cCs"/>
<action selector="performZoom:" target="Ady-hI-5gd" id="Xxo-zx-Tts"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
<menuItem title="Bring All to Front" id="LE2-aR-0XJ">
<menuItem isSeparatorItem="YES" id="uFE-Uu-iox"/>
<menuItem title="Bring All to Front" id="mz7-LD-Mau">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="arrangeInFront:" target="Ady-hI-5gd" id="DRN-fu-gQh"/>
<action selector="arrangeInFront:" target="Ady-hI-5gd" id="CHi-QZ-5rl"/>
</connections>
</menuItem>
</items>
Expand Down Expand Up @@ -982,13 +1014,13 @@
<rect key="frame" x="0.0" y="0.0" width="200" height="404"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<subviews>
<scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="17" horizontalPageScroll="10" verticalLineScroll="17" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kJX-pd-nWK">
<scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="30" horizontalPageScroll="10" verticalLineScroll="30" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kJX-pd-nWK">
<rect key="frame" x="0.0" y="40" width="200" height="364"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="leX-9o-K0T">
<rect key="frame" x="0.0" y="0.0" width="200" height="364"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="sourceList" multipleSelection="NO" autosaveColumns="NO" autosaveName="" rowSizeStyle="automatic" viewBased="YES" indentationPerLevel="14" outlineTableColumn="yMB-qM-qvc" id="16N-MH-33n" customClass="SidebarView" customModule="Pine" customModuleProvider="target">
<outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="sourceList" multipleSelection="NO" autosaveColumns="NO" autosaveName="" rowHeight="30" rowSizeStyle="automatic" viewBased="YES" indentationPerLevel="14" outlineTableColumn="yMB-qM-qvc" id="16N-MH-33n" customClass="SidebarView" customModule="Pine" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="200" height="364"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="0.0"/>
Expand Down Expand Up @@ -1126,7 +1158,7 @@
<resources>
<image name="NSFolder" width="32" height="32"/>
<image name="NSLinenBackgroundPattern" width="256" height="256"/>
<image name="Plus" width="64" height="64"/>
<image name="Sidebar" width="64" height="64"/>
<image name="Plus" width="75" height="75"/>
<image name="Sidebar" width="75" height="75"/>
</resources>
</document>
17 changes: 16 additions & 1 deletion Pine/Controllers/MarkdownViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,29 @@ class MarkdownViewController: NSViewController, NSTextViewDelegate, HighlightDel
let doc = self.windowController?.document as? Document
let fileURL = doc?.fileURL ?? URL(fileURLWithPath: "/")

let styledHTML = html.getHTML(
with: parsed,
direction: self.markdownTextView.baseWritingDirection
)

self.previewViewController?.setPermissions(for: fileURL)
self.previewViewController?.setContent(with: html.getHTML(with: parsed))
self.previewViewController?.setContent(with: styledHTML)
}
}
}
}
}

/// Whenever typing attributes in the text view are changed, regenerate the preview
func textView(
_ textView: NSTextView,
shouldChangeTypingAttributes oldTypingAttributes: [String : Any] = [:],
toAttributes newTypingAttributes: [NSAttributedString.Key : Any] = [:]) -> [NSAttributedString.Key : Any]
{
self.generatePreview()
return newTypingAttributes
}

}

extension MarkdownViewController {
Expand Down
1 change: 1 addition & 0 deletions Pine/Controllers/SidebarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class SidebarViewController: NSViewController {
/// Update the sidebar appearance based on any preferences and the theme
@objc private func updateSidebarAppearance() {
sidebar.appearance = NSAppearance(named: .current)
sidebarActionsView.appearance = NSAppearance(named: .current)
sidebarSplitViewItem?.isCollapsed = !preferences[Preference.showSidebar]

var backgroundColor: NSColor = .clear
Expand Down
14 changes: 6 additions & 8 deletions Pine/Helpers/SyntaxThemes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@ struct SyntaxThemes {

public static let ThemeList: [String] = getThemes()

// Read theme file names from application support directory
// This allows users to create their own themes
// Read theme file names from resources directory
private static func getThemes() -> [String] {
if let supportFolder = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first {
let stylesFolder = supportFolder.appendingPathComponent("highlight-js/styles")

if let stylesFolder = Bundle.main.path(forResource: "highlight-js/styles", ofType: nil) {
let contents = try? FileManager.default.contentsOfDirectory(
at: stylesFolder,
at: URL(fileURLWithPath: stylesFolder),
includingPropertiesForKeys: nil,
options: []
)

if let cssFiles = contents?
return contents?
.filter({ $0.pathExtension == "css" })
.map({ $0.deletingPathExtension().lastPathComponent })
.sorted() { return cssFiles }
.sorted() ?? []
}

return []
}

Expand Down
54 changes: 13 additions & 41 deletions Pine/Models/HTML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2018 Luka Kerr. All rights reserved.
//

import Cocoa
import Foundation

class HTML {
Expand All @@ -17,7 +18,6 @@ class HTML {
// This file IO only happens when the singleton is instantiated, but the WKWebView
// has to re-parse the entire HTML returned from getHTML()
private init() {
self.copyFiles()
self.loadCSS()
self.loadJS()
}
Expand All @@ -29,10 +29,13 @@ class HTML {

// The innerHTML contents are passed in here rather than stored
// to prevent asynchronous race conditions changing the content on startup
public func getHTML(with contents: String) -> String {
public func getHTML(with contents: String, direction: NSWritingDirection? = .natural) -> String {
// If using system appearance, let window background control the color used
let bodyBackground = preferences[Preference.useSystemAppearance] ? "transparent" : theme.background.hex

// Direction of text, by default is auto
let dir = direction == .rightToLeft ? "rtl" : "auto"

return(
"""
<!DOCTYPE html>
Expand All @@ -55,7 +58,7 @@ class HTML {
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0-rc/katex.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0-rc/contrib/auto-render.min.js"></script>
</head>
<body>
<body dir="\(dir)">
\(contents)
<script>
window.scrollTo(0, \(y));
Expand All @@ -78,56 +81,25 @@ class HTML {

// MARK: - Private functions for setting up the HTML contents

fileprivate func getApplicationSupportFolder() -> URL? {
return FileManager.default.urls(
for: .applicationSupportDirectory,
in: .userDomainMask).first
}

fileprivate func loadJS() {
guard
let jsFile = getApplicationSupportFolder()?.appendingPathComponent("highlight-js/highlight.js"),
let jsResult = try? String(contentsOf: jsFile, encoding: .utf8)
let jsFile = Bundle.main.path(forResource: "highlight-js/highlight", ofType: "js"),
let jsResult = try? String(contentsOf: URL(fileURLWithPath: jsFile), encoding: .utf8)
else { return }

js = jsResult
}

fileprivate func loadCSS() {
guard
let folder = getApplicationSupportFolder(),
let bundlePath = Bundle.main.resourcePath,
let baseCSSResult = try? String(contentsOf: folder.appendingPathComponent("Markdown.css"), encoding: .utf8)
else { return }

let cssFolder = URL(fileURLWithPath: bundlePath + "/highlight-js/styles/\(theme.syntax).css")

if let cssResult = try? String(contentsOf: cssFolder as URL, encoding: .utf8) {
css = cssResult
baseCSS = baseCSSResult
}
}

fileprivate func copyFiles() {
guard
let folder = getApplicationSupportFolder(),
let cssFile = Bundle.main.path(forResource: "Markdown", ofType: "css"),
let bundlePath = Bundle.main.resourcePath
let cssThemeFile = Bundle.main.path(forResource: "/highlight-js/styles/\(theme.syntax)", ofType: "css"),
let cssContents = try? String(contentsOf: URL(fileURLWithPath: cssFile), encoding: .utf8),
let cssThemeContents = try? String(contentsOf: URL(fileURLWithPath: cssThemeFile), encoding: .utf8)
else { return }

let highlightFolder = URL(fileURLWithPath: (String(describing: bundlePath) + "/highlight-js"))

try? FileManager.default.copyItem(
at: highlightFolder as URL,
to: folder.appendingPathComponent("highlight-js")
)

try? FileManager.default.removeItem(at: folder.appendingPathComponent("Markdown.css"))

try? FileManager.default.copyItem(
at: URL(fileURLWithPath: cssFile),
to: folder.appendingPathComponent("Markdown.css")
)
css = cssThemeContents
baseCSS = cssContents
}

}
Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use_frameworks!
platform :osx, '10.13'

target 'Pine' do
pod 'Highlightr', :git => 'https://github.com/raspu/Highlightr.git'
pod 'Highlightr', :git => 'https://github.com/lukakerr/Highlightr.git'
pod 'cmark-gfm-swift', :git =>
'https://github.com/lukakerr/cmark-gfm-swift.git'
end
14 changes: 7 additions & 7 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
PODS:
- cmark-gfm-swift (0.1.0)
- Highlightr (2.0.1)
- Highlightr (2.1.0)

DEPENDENCIES:
- cmark-gfm-swift (from `https://github.com/lukakerr/cmark-gfm-swift.git`)
- Highlightr (from `https://github.com/raspu/Highlightr.git`)
- Highlightr (from `https://github.com/lukakerr/Highlightr.git`)

EXTERNAL SOURCES:
cmark-gfm-swift:
:git: https://github.com/lukakerr/cmark-gfm-swift.git
Highlightr:
:git: https://github.com/raspu/Highlightr.git
:git: https://github.com/lukakerr/Highlightr.git

CHECKOUT OPTIONS:
cmark-gfm-swift:
:commit: a8f6fcf3eecc6292f8876ac7a825e9651f0297b7
:git: https://github.com/lukakerr/cmark-gfm-swift.git
Highlightr:
:commit: bd57404c28527b4d40ee15ce9f61fad734ad50a1
:git: https://github.com/raspu/Highlightr.git
:commit: b32a617fef4822ab7ae6818a7d3e47765feecdf0
:git: https://github.com/lukakerr/Highlightr.git

SPEC CHECKSUMS:
cmark-gfm-swift: 9915dfe0cd7feda740ab01fc2a1882989b6d5128
Highlightr: 8162b4faba588963fb8852390ea9a78f166a6b99
Highlightr: 595f3e100737c8de41113385da8bd0b5b65212c6

PODFILE CHECKSUM: 12a1dfb7c19862ddb1dabaf06f643889239bfadd
PODFILE CHECKSUM: d78e2fa1bb6f326685c91947eace08ae217e92ce

COCOAPODS: 1.5.0
17 changes: 2 additions & 15 deletions Pods/Highlightr/Pod/Assets/Highlighter/highlight.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Pods/Highlightr/Pod/Assets/styles/a11y-dark.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/Highlightr/Pod/Assets/styles/a11y-light.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 296d9a8

Please sign in to comment.