 	func contentsEdited(range: NSRange, delta: Int) -> Bool
 }
 
-class LivePreviewDisplayController: AbstractSessionViewController, OutputController, LivePreviewOutputController {
+class LivePreviewDisplayController: AbstractSessionViewController, OutputController, LivePreviewOutputController, WKUIDelegate, WKNavigationDelegate
+{
 	var contextualMenuDelegate: ContextualMenuDelegate?
 	var sessionController: SessionController?
 	private var context: MutableProperty<EditorContext?> = MutableProperty<EditorContext?>(nil) { didSet { contextChanged() }}
 	private let contextDisposables = CompositeDisposable()
 	private var contentsDisposable: Disposable?
+	private var lineContiuationRegex: NSRegularExpression!
+	private var openDoubleDollarRegex: NSRegularExpression!
+	private var closeDoubleDollarRegex: NSRegularExpression!
+	private var documentRoot: URL?
+	private var initialDocumentLoaded = false
+	private var needToLoadDocumentOnLoad = false
+	private var resourcesExtracted = false
+	private var readyForContent: Bool { return resourcesExtracted && needToLoadDocumentOnLoad }
+	private var parseInProgress = false
 	
 	var editorContext: EditorContext? {
 		get { return context.value }


import Cocoa
import WebKit
import ClientCore
import SyntaxParsing
import ReactiveSwift
import Down

protocol LivePreviewOutputController {
	/// might not need to be accessible

	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()
