9 hours ago9 hr We have a few functions in the MBS FileMaker Plugin to convert things to HTML. That is useful to visualize HTML or JSON. You may convert text, styled text or MarkDown to HTML.JSONWe often have to debug our code for web services and display JSON for debugging. There our JSON.ToHTML function helps a lot. We can pass the JSON and receive some HTML, which we display into a web viewer.e.g.MBS("JSON.ToHTML"; "{\"FirstName\": \"John\", \"id\": 123}")Returns:<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> </head> <body> <div class="JSONObject"> <table border=0 cellpadding=1> <tr class="odd"><td>FirstName</td> <td>John</td></tr> <tr class="even"><td>id</td> <td>123</td></tr> </table></div> </body> </html> Here is a little script to take some html, convert it to HTML and load it into a web viewer:# now make html Set Variable [ $html ; Value: MBS( "JSON.ToHTML"; $json) ] # and show in web viewer Set Web Viewer [ Object Name: "web" ; URL: "data:text/html;charset=utf-8," & $html ]Which looks like this:FirstNameJohnid123XMLSimilar to JSON above, you may want to display XML. Our XML.ToHTML functon builds a HTML with tables to show the various layers in an XML document. All the keys and values show up with indention to show the level. You may use a CSS for odd and even rows to colorize the cell backgrounds.e.g.MBS("XML.ToHTML"; "1234John"; 0; "")Returns:<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> </head> <body> <h3>test</h3><div class="Elements"> <table border=0 cellpadding=1> <tr class="odd"><td>id</td> <td><p>1234</p></td></tr> <tr class="even"><td>name</td> <td><p>John</p></td></tr> </table></div> </body> </html> Which looks like this:testid1234nameJohnStyled TextYou may want to have users type some styled text in a field. Later you convert the styled text to HTML with our Text.TextToHTML function or GetAsCSS(). Our function does have a few options for the HTML generation.e.g.MBS( "Text.TextToHTML"; "Hello World¶¶Just a test¶¶😀"; 32 + 1 )Returns: <p>Hello World</p> <p> Just a test</p> <p> 😀</p> Which looks like this:Hello WorldJust a test😀TextWhen you have text and you like to include it in a HTML piece, you need to encode the various special characters. Our Text.EncodeToHTML function looks for various special characters and does proper escaping. This way you guarantee that all the accents, asian characters or even smileys survive when embedding some text in HTML, e.g. for an email.e.g.MBS( "Text.EncodeToHTML"; "Hast Du Äpfel? 🍎" )Returns: Hast Du Äpfel? 🍎Which looks like this:Hast Du Äpfel? 🍎MarkDownFor MarkDown text, you can use our Markdown functions to convert to html and show in a web viewer. For this you combine the MarkDown.Create function with either the MarkDown.HTML function for just the html snippet, or you use the MarkDown.HTMLDocument function to get a full document.e.g.Set Variable [ $r ; Value: MBS("MarkDown.Create"; "Text attributes *italic*, **bold**, `monospace`, ~~strikethrough~~ .") ] Set Variable [ $html ; Value: MBS("MarkDown.HTMLDocument"; $r) ] Set Variable [ $r ; Value: MBS("MarkDown.Release"; $r) ] From HTMLSometimes you need the other way around. Parse the HTML into something useful. Our Text.HTMLtoJSON parses the HTML using the tidy library and outputs the nodes as JSON. This way you can use JSON functions to work on the HTML and read values. Especially JSON.Query and JSON.Search may help here to find values in the parsed HTML.When you like to convert the html to styled text, we have the Text.HTMLtoStyledText function. It parses the HTML and converts the styles FileMaker supports from HTML tags to something FileMaker can understand. Various CSS rules will not work, but in general it works often fine for HTML from emails with inline styles.
Create an account or sign in to comment