Улучшено распознавание xml-формата
This commit is contained in:
@@ -103,6 +103,11 @@ class ConvertBase {
|
||||
return he.escape(he.decode(text.replace(/ /g, ' ')));
|
||||
}
|
||||
|
||||
isDataXml(data) {
|
||||
const str = data.toString().trim();
|
||||
return (str.indexOf('<?xml version="1.0"') == 0 || str.indexOf('<?xml version=\'1.0\'') == 0 );
|
||||
}
|
||||
|
||||
formatFb2(fb2) {
|
||||
const out = xmlParser.formatXml({
|
||||
FictionBook: {
|
||||
|
||||
@@ -6,7 +6,10 @@ class ConvertFb2 extends ConvertBase {
|
||||
check(data, opts) {
|
||||
const {dataType} = opts;
|
||||
|
||||
return (dataType && dataType.ext == 'xml' && data.toString().indexOf('<FictionBook') >= 0);
|
||||
return (
|
||||
( (dataType && dataType.ext == 'xml') || this.isDataXml(data) ) &&
|
||||
data.toString().indexOf('<FictionBook') >= 0
|
||||
);
|
||||
}
|
||||
|
||||
async run(data, opts) {
|
||||
|
||||
@@ -7,7 +7,7 @@ class ConvertHtml extends ConvertBase {
|
||||
const {dataType} = opts;
|
||||
|
||||
//html?
|
||||
if (dataType && (dataType.ext == 'html' || dataType.ext == 'xml'))
|
||||
if ( ( (dataType && (dataType.ext == 'html' || dataType.ext == 'xml')) ) || this.isDataXml(data) )
|
||||
return {isText: false};
|
||||
|
||||
//может это чистый текст?
|
||||
|
||||
Reference in New Issue
Block a user