mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 19:57:27 -08:00
Output HTML DOCTYPE correctly from HtmlAssetTranslator
This commit is contained in:
parent
0de9db4b0f
commit
a63638a91c
|
@ -30,6 +30,7 @@ import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.DirectoryStream;
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -37,6 +38,7 @@ import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
@ -200,7 +202,10 @@ public final class HtmlAssetTranslator {
|
||||||
|
|
||||||
DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
|
DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
|
||||||
LSSerializer writer = impl.createLSSerializer();
|
LSSerializer writer = impl.createLSSerializer();
|
||||||
writer.writeToURI(document, destFile.toUri().toString());
|
String fileAsString = writer.writeToString(document);
|
||||||
|
// Replace default XML header with HTML DOCTYPE
|
||||||
|
fileAsString = fileAsString.replaceAll("<\\?xml[^>]+>", "<!DOCTYPE HTML>");
|
||||||
|
Files.write(destFile, Collections.singleton(fileAsString), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean shouldTranslate(Node node) {
|
private static boolean shouldTranslate(Node node) {
|
||||||
|
|
Loading…
Reference in a new issue