Skip to content

Commit

Permalink
Fixed a bug and set the font
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseidhof committed Jun 18, 2015
1 parent dc58dd3 commit 593f331
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions LiterateSwift2/RenderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func linkURLs(blocks: [Block]) -> [String?] {
func tableOfContents(blocks: [Block]) -> [Block] {
let headers = deepCollect(blocks) { (b: Block) -> [Block] in
guard case let .Header(text, level) = b else { return [] }
let prepend = String(Array(count: level, repeatedValue: "#")) + " "
return [Block.Paragraph(text: [InlineElement.Text(text: prepend)] + text)]
let prepend = "".join(Array(count: level, repeatedValue: "_")) + " "
return [Block.Paragraph(text: [InlineElement.Code(text: prepend)] + text)]
}
return [Block.Paragraph(text: [InlineElement.Emphasis(children: ["Table of contents"])])] + headers + [Block.HorizontalRule]
}
Expand All @@ -63,7 +63,9 @@ class RenderViewController: NSViewController {
let directory = fileName.stringByDeletingLastPathComponent

let elements = evaluateAndReplacePrintSwift(tableOfContents(elements) + deepApply(elements, { prependLanguage($0).flatMap(replaceSnippet(directory)) }))
webview.mainFrame.loadHTMLString(Node(blocks: elements).html, baseURL: nil)
let prelude = "<body style='font-family: \"Akkurat TT\", \"Helvetica\"'>"
let html = prelude + (Node(blocks: elements).html ?? "") + "</body>"
webview.mainFrame.loadHTMLString(html, baseURL: nil)
}

override func viewDidAppear() {
Expand Down
6 changes: 4 additions & 2 deletions LiterateSwiftFramework/LiterateSwiftFramework/Weave.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ func extractSnippet(filename: String, snippetName: String) -> String? {

func findSnippet(directory: String)(name: String) -> String? {
let files = findNestedFiles(directory) { $0.pathExtension == "swift" }
for swiftFile in files {
return extractSnippet(directory.stringByAppendingPathComponent(swiftFile), snippetName: name)
for swiftFile in files {
if let snippet = extractSnippet(directory.stringByAppendingPathComponent(swiftFile), snippetName: name) {
return snippet
}
}
return nil
}

0 comments on commit 593f331

Please sign in to comment.