 	
 	override func viewDidLoad() {
 		super.viewDidLoad()
-		do {
-			guard let headerUrl = Bundle.main.url(forResource: "customRmdHeader", withExtension: "html"),
-				let footerUrl = Bundle.main.url(forResource: "customRmdFooter", withExtension: "html")
-			else {
-				fatalError("failed to load live preview template file")
-			}
-			let header = try String(contentsOf: headerUrl)
-			let footer = try String(contentsOf: footerUrl)
-			outputView?.loadHTMLString("\(header) Body <span id\"foobar\">Goes</span> Here \(footer)", baseURL: nil)
-		} catch {
-			fatalError("failed to load live preview template file: \(error.localizedDescription)")
-		}
+		guard let regex = try? NSRegularExpression(pattern: "\\s+\\\\$", options: [.anchorsMatchLines]),
+			let openRegex = try? NSRegularExpression(pattern: "^\\$\\$", options: []),
+			let closeRegex = try? NSRegularExpression(pattern: "\\$\\$(\\s*)$", options: [])
+			else { fatalError("regex failed to compile")}
+
+		lineContiuationRegex = regex
+		openDoubleDollarRegex = openRegex
+		closeDoubleDollarRegex = closeRegex
+		documentRoot = Bundle.main.url(forResource: "preview_support", withExtension: nil)
+//		do {
+//			documentRoot = try AppInfo.subdirectory(type: .applicationSupportDirectory, named: "preview_support")
+//			documentRoot = URL(fileURLWithPath: documentRoot!.path.removingPercentEncoding!)
+//			loadInitialPage()
+//		} catch {
+//			fatalError("failed to load live preview template file: \(error.localizedDescription)")
+//		}
+		ensureResourcesLoaded()
+		outputView?.uiDelegate = self
+		outputView?.navigationDelegate = self
 	}
 	
 	/// called by the editor when the user has made an edit, resulting in a change of what is displayed

		// string = string.replacingOccurrences(of: "\f", with: "\\f")
		return string
	}
}

	func contentsEdited(range: NSRange, delta: Int) -> Bool {
		/// FIXME: implement
		// need to update the changed chunk if possible. If not, then reparse document
		parseContent()
		return true
	}
	
	private func loadInitialPage() {
		guard resourcesExtracted, needToLoadDocumentOnLoad,
			let headerUrl = Bundle.main.url(forResource: "customRmdHeader", withExtension: "html"),
			let footerUrl = Bundle.main.url(forResource: "customRmdFooter", withExtension: "html")
			else { return }
		do {
			let header = try String(contentsOf: headerUrl)
			let footer = try String(contentsOf: footerUrl)
			outputView?.loadHTMLString("\(header) \(footer)", baseURL: documentRoot)
		} catch {
			fatalError("failed to load initial preview content: \(error)")
		}
	}

	/// called when the context property has been set
	private func contextChanged() {
		contextDisposables.dispose()
		contentsDisposable?.dispose()
