Is it possible to convert HTML into XHTML with Jsoup 1.8.1?
See Document.OutputSettings.Syntax.xml
:
private String toXHTML( String html ) {
final Document document = Jsoup.parse(html);
document.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
return document.html();
}
How to convert HTML to valid XHTML?
Don't use a Regular expression, but dedicated parsers. In JavaScript, create a document using the DOMParser
, then serialize it using the XMLSerializer
:
var doc = new DOMParser().parseFromString('<img src="foo">', 'text/html');
var result = new XMLSerializer().serializeToString(doc);
// result:
// <html xmlns="http://www.w3.org/1999/xhtml"><head></head><body> (no line break)
// <img src="foo" /></body></html>
You have to use xmldom if you required to use this with nodejs backend. npm i xmldom
.
How to convert HTML to XHTML?
Convert from HTML to XML with HTML Tidy
Downloadable Binaries
JRoppert, For your need, i guess you might want to look at the Sources
c:\temp>tidy -help
tidy [option...] [file...] [option...] [file...]
Utility to clean up and pretty print HTML/XHTML/XML
see http://tidy.sourceforge.net/
Options for HTML Tidy for Windows released on 14 February 2006:
File manipulation
-----------------
-output <file>, -o write output to the specified <file>
<file>
-config <file> set configuration options from the specified <file>
-file <file>, -f write errors to the specified <file>
<file>
-modify, -m modify the original input files
Processing directives
---------------------
-indent, -i indent element content
-wrap <column>, -w wrap text at the specified <column>. 0 is assumed if
<column> <column> is missing. When this option is omitted, the
default of the configuration option "wrap" applies.
-upper, -u force tags to upper case
-clean, -c replace FONT, NOBR and CENTER tags by CSS
-bare, -b strip out smart quotes and em dashes, etc.
-numeric, -n output numeric rather than named entities
-errors, -e only show errors
-quiet, -q suppress nonessential output
-omit omit optional end tags
-xml specify the input is well formed XML
-asxml, -asxhtml convert HTML to well formed XHTML
-ashtml force XHTML to well formed HTML
-access <level> do additional accessibility checks (<level> = 0, 1, 2, 3).
0 is assumed if <level> is missing.
Character encodings
-------------------
-raw output values above 127 without conversion to entities
-ascii use ISO-8859-1 for input, US-ASCII for output
-latin0 use ISO-8859-15 for input, US-ASCII for output
-latin1 use ISO-8859-1 for both input and output
-iso2022 use ISO-2022 for both input and output
-utf8 use UTF-8 for both input and output
-mac use MacRoman for input, US-ASCII for output
-win1252 use Windows-1252 for input, US-ASCII for output
-ibm858 use IBM-858 (CP850+Euro) for input, US-ASCII for output
-utf16le use UTF-16LE for both input and output
-utf16be use UTF-16BE for both input and output
-utf16 use UTF-16 for both input and output
-big5 use Big5 for both input and output
-shiftjis use Shift_JIS for both input and output
-language <lang> set the two-letter language code <lang> (for future use)
Miscellaneous
-------------
-version, -v show the version of Tidy
-help, -h, -? list the command line options
-xml-help list the command line options in XML format
-help-config list all configuration options
-xml-config list all configuration options in XML format
-show-config list the current configuration settings
Use --blah blarg for any configuration option "blah" with argument "blarg"
Input/Output default to stdin/stdout respectively
Single letter options apart from -f may be combined
as in: tidy -f errs.txt -imu foo.html
For further info on HTML see http://www.w3.org/MarkUp
How do I convert HTML to XHTML using JavaScript?
You'll have to use a capture group:
strInput = strInput.replace(/(<img[^>]+)>/gm, "$1 />");
Here's the fiddle: http://jsfiddle.net/ChNnU/
convert HTML to XHTML
Replace the &
in the href attribute with &
. You need to use character references in XHTML.
How to convert HTML into XHTML
$filename = 'template.php'; // filepath to file
// All options : http://tidy.sourceforge.net/docs/quickref.html
$options = array('output-xhtml' => true, 'clean' => true, 'wrap-php' => true);
$tidy = new tidy(); // create new instance of Tidy
$tidy->parseFile($filename, $options); // open file
$tidy->cleanRepair(); // process with specified options
copy($filename, $filename . '.bak'); // backup current file
file_put_contents($filename, $tidy); // overwrite current file with XHTML version
I don't have a Smarty template file to test this on, but give it a try and see if it works correctly in converting one. Backup your files as always when running something of this nature. Test out on sample files first.
Related Topics
How to Determine If a Decimal/Double Is an Integer
How to Add Js and CSS Files in ASP.NET Core
What Is a Dynamic Language, and Why Doesn't C# Qualify
Why C# Implements Methods as Non-Virtual by Default
Add "Everyone" Privilege to Folder Using C#.Net
Data Binding in Wpf User Controls
C# - Winforms - Global Variables
How to Get the Z-Order in Windows
How to Exit a Wpf Application Programmatically
Redirecting Unauthorized Controller in ASP.NET MVC
ASP.NET Core 2.0-2.2 Kestrel Not Serving Static Content
In Ruby, What Is the Equivalent to an Interface in C#
Does Java Have Something Like C#'s Ref and Out Keywords
How to Set Up a Web API Controller for Multipart/Form-Data