OpenersPrimaryExamplesSection(Spacer1)Examples  (6)

OpenersExampleSection0(Spacer1)Basic Examples  (6)

Translate an expression to an HTML fragment:

ExportString[Graphics[Disk[]], "HTMLFragment"]

Specify a "URLHandler" for the export process:

ExportString[Graphics[Disk[]], "HTMLFragment","URLHandler" -> Automatic]

Deploy the temporary data with a custom function:

staticHandler[expr_, format_] := Export[IntegerString @ Hash[expr]<>"."<>format, expr, format]

ExportString[RandomImage[1,{10,10}], "HTMLFragment", "URLHandler" -> staticHandler]

Export the temporary data to a directory and map with a URL:

ExportString[
	BarChart[{1}], 
	"HTMLFragment", 
	"URIHandler" -> "Export", 
	"FilesDirectory" -> "/Users/usr/Downloads", 
	"FilesPrefix" -> "http://localhost/media/temp"
]

Generate an HTML fragment with a "Bootstrap" class:

ExportString[InputField[], "HTMLFragment", "RenderFormat" -> "Bootstrap"]

Generate an HTML fragment for a string containing any characters:

ExportString["vedrà","HTMLFragment"]

Generate a full HTML document:

ExportString[InputField[], "HTMLFragment", "FullDocument" -> True]//Short

Apply a custom function:

ExportString[InputField[], "HTMLFragment", "TemplateFunction" -> Function @ StringJoin["pre----", #1, "--- post"]]

Apply a custom template:

template = XMLTemplate["
<html>
	<body>
		<wolfram:slot/>
	<body>
</html>"];

ExportString[InputField[], "HTMLFragment", "TemplateFunction" -> template]

Create a formatted HTML page using "TemplateEnvironment":

SystemOpen @ Export[
	FileNameJoin[{$TemporaryDirectory, "cellaut.html"}],
	ArrayPlot[CellularAutomaton[30,{{1},0},50], Frame->False], 
	"HTMLFragment", 
	"TemplateEnvironment" -> <|
		"Theme" -> "Cerulean",
		"Brand" -> "MyCompany",
		"PageTitle" -> "Array plot",
		"PageDescription" -> "This is the array plot description",
		"Footer" -> "Nice footer"
	|>
]

Create an HTML form that submits to an external web page using "TemplateEnvironment":

SystemOpen @ Export[
	FileNameJoin[{$TemporaryDirectory, "input.html"}],
FormObject["i" -> <|"Interpreter" -> "String", "Label" -> "Insert something"|>], 
	"HTMLFragment", 
	"TemplateEnvironment" -> <|
		"Theme" -> "Cerulean",
		"Brand" -> "Smart Fields",
		"PageTitle" -> "Computation form",
		"FormAction" -> "http://www.wolframalpha.com/input/",
		"FormMethod" -> "GET"
	|>
]

Specify an "XMLTransformationFunction" to apply:

transformTree[tree_] := ReplaceAll[tree, XMLElement["a", tags_, body_] :> XMLElement["a", {"class" -> "fancy-link"}, body]]

ExportString[Hyperlink["http://google.com"], "HTMLFragment", "XMLTransformationFunction" -> transformTree]

Specify how to format graphics:

ExportString[BarChart[{1, 2, 3}], "HTMLFragment","GraphicsOutput" -> "PNG"]//Short

Specify how to format audio:

ExportString[ExampleData[{"Sound","AltoFlute"}], "HTMLFragment",  "AudioOutput" -> "WAV"]//Short

Output math expressions as (StringTypeLink["MathML", paclet:ref/format/MathML]):

ExportString[Integrate[1/(x^3+1),x], "HTMLFragment", "MathOutput" -> "MathML"]//Short

Customize how dates are transformed:

ExportString[DateObject[], "HTMLFragment", "DateFormat" -> {"Year", "/",  "Month"}]

formatDates[date_DateObject] := DateString[date, "Year"]

formatDates[date_TimeObject] := DateString[date, "Time"]

ExportString[DateObject[], "HTMLFragment", "DateFormat" -> formatDates]

ExportString[TimeObject[], "HTMLFragment", "DateFormat" -> formatDates]

Specify how to format numbers with a list of rules:

ExportString[1000.15,"HTMLFragment","NumericFormat"->{NumberPoint->",",NumberSeparator->{".",""},DigitBlock->3}]

Provide a Wolfram Language function to format numbers:

ExportString[1000.15,"HTMLFragment","NumericFormat"->AccountingForm]

Use a custom function to format numbers:

ExportString[1000.15,"HTMLFragment","NumericFormat"->Function[ToString[#1]<>" USD"]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {Related Formats:  (RefLink[HTML, paclet:ref/format/HTML])  ▪  (RefLink[EPS, paclet:ref/format/EPS])  ▪  (RefLink[GIF, paclet:ref/format/GIF])  ▪  (RefLink[LaTeX, paclet:ref/format/LaTeX])  ▪  (RefLink[MathML, paclet:ref/format/MathML])  ▪  (RefLink[NB, paclet:ref/format/NB])  ▪  (RefLink[PDF, paclet:ref/format/PDF])  ▪  (RefLink[RTF, paclet:ref/format/RTF])  ▪  (RefLink[SVG, paclet:ref/format/SVG])  ▪  (RefLink[SWF, paclet:ref/format/SWF])  ▪  (RefLink[TeX, paclet:ref/format/TeX])  ▪  (RefLink[XHTML, paclet:ref/format/XHTML])  ▪  (RefLink[XHTMLMathML, paclet:ref/format/XHTMLMathML])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Wolfram System Internet Connectivity, paclet:tutorial/InternetConnectivity])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Creating Web Pages, paclet:guide/CreatingWebPages])}, {▪(RefLinkPlain[Document Formats, paclet:guide/DocumentFormats])}, {▪(RefLinkPlain[Graphics Importing & Exporting, paclet:guide/GraphicsImportingAndExporting])}, {▪(RefLinkPlain[Importing & Exporting, paclet:guide/ImportingAndExporting])}, {▪(RefLinkPlain[Importing & Exporting in Notebooks, paclet:guide/ImportingAndExportingInNotebooks])}, {▪(RefLinkPlain[Listing of All Formats, paclet:guide/ListingOfAllFormats])}, {▪(RefLinkPlain[New in 6.0: Notebooks & Documents, paclet:guide/NewIn60NotebooksAndDocuments])}, {▪(RefLinkPlain[Numerical Data, paclet:guide/NumericalData])}, {▪(RefLinkPlain[Processing Textual Data, paclet:guide/ProcessingTextualData])}, {▪(RefLinkPlain[Web Formats, paclet:guide/WebFormats])}, {▪(RefLinkPlain[Web Operations, paclet:guide/WebOperations])}})}})