Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Tools/MarkDown/MarkDown in HTMLViewer/MarkDown
Function:
Required plugins for this example: MBS Win Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Tools/MarkDown/MarkDown in HTMLViewer/MarkDown
This example is the version from Thu, 4th Jan 2017.
Project "MarkDown.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class TestWindow Inherits Window
Control InputText Inherits TextArea
ControlInstance InputText Inherits TextArea
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control OutputText Inherits TextArea
ControlInstance OutputText Inherits TextArea
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control ConvertButton Inherits PushButton
ControlInstance ConvertButton Inherits PushButton
EventHandler Sub Action() Convert End EventHandler
End Control
Control PreviewHTMLViewer Inherits HTMLViewer
ControlInstance PreviewHTMLViewer Inherits HTMLViewer
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control CHTMLViewer Inherits HTMLViewer
ControlInstance CHTMLViewer Inherits HTMLViewer
End Control
EventHandler Sub Open() Init End EventHandler
Sub Convert() dim i as string = InputText.Text.ConvertEncoding(encodings.UTF8) if TargetWin32 then // needs MBS Win Plugin if CHTMLViewer.Renderer = 0 then // IE if CHTMLViewer.IESetTextAreaMBS("formtest", "input", i) then if CHTMLViewer.IERunJavaScriptMBS("Convert();") then dim o as string = CHTMLViewer.IEGetTextAreaMBS("formtest", "output") if o <> "" then // ok OutputText.Text = o PreviewHTMLViewer.LoadPage o, nil Return end if else MsgBox "Failed to run javascript." end if else MsgBox "Failed to find input field." end if else // WebKit todo Break end if elseif TargetCocoa then // needs MBS Cocoa Plugins #if TargetCocoa then dim m as WebFrameMBS = CHTMLViewer.mainFrameMBS dim d as DOMDocumentMBS = m.DOMDocument dim vi as Variant = d.getElementById("input") dim vo as Variant = d.getElementById("output") dim tai as DOMHTMLTextAreaElementMBS = vi dim tao as DOMHTMLTextAreaElementMBS = vo tai.value = i dim r as string = CHTMLViewer.EvaluateJavaScriptMBS("Convert();") if r = "OK" then dim o as string = tao.value if o <> "" then // ok OutputText.Text = o PreviewHTMLViewer.LoadPage o, nil Return end if else MsgBox "JavaScript failed"+EndOfLine+EndOfLine+r end if #endif else // others todo Break end if // failed OutputText.Text = "" PreviewHTMLViewer.LoadURL "about:blank" End Sub
Function FindFile(name as string) As FolderItem // Look for file in parent folders from executable on dim parent as FolderItem = app.ExecutableFile.Parent while parent<>Nil dim file as FolderItem = parent.Child(name) if file<>Nil and file.Exists then Return file end if parent = parent.Parent wend End Function
Sub Init() // initialize empty PreviewHTMLViewer.LoadURL "about:blank" // load local file dim f as FolderItem = findFile("markdown.html") CHTMLViewer.LoadPage f End Sub
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Tools Plugin.




Links
MBS Xojo Plugins