From 79f21919628c77e5458b4cce039c4c8ed23df38a Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Sun, 8 Apr 2018 17:41:08 -0400 Subject: [PATCH] Make xml version declaration optional regex - Fixes an issue where the doctype declaration is not stripped when the xml version declaration is missing from the exported `.enex` file. When the `DOCTYPE` declaration is left in, we get `REXML::ParseException: Declarations can only occur in the doctype declaration.` raised exception. --- lib/ever2boost/enex_converter.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ever2boost/enex_converter.rb b/lib/ever2boost/enex_converter.rb index cc92c25..8f0825f 100644 --- a/lib/ever2boost/enex_converter.rb +++ b/lib/ever2boost/enex_converter.rb @@ -29,12 +29,18 @@ def parse_plural_notes(enex, output_dir) xml_document = REXML::Document.new(el.to_s).elements Note.new({ title: xml_document['note/title'].text, - content: "
#{xml_document['note/content/text()'].to_s.sub(/<\?xml(.*?)\?>(.*?)<\!DOCTYPE(.*?)>/m, '')}
", + content: "
#{strip_doctype(xml_document)}
", output_dir: output_dir }) end end.compact.flatten end + + private + + def strip_doctype(xml_document) + xml_document['note/content/text()'].to_s.sub(/(<\?xml(.*?)\?>(.*?))?<\!DOCTYPE(.*?)>/m, '') + end end end end