public void MapCssToLang_UsesGetValidCssClassName() { var helper = new XhtmlHelper(); helper.MapCssToLang("#MyClass", "dummy"); List<string> output; Assert.That(helper.TryGetLangsFromCss("#MyClass", out output), Is.True, "unmodified class name should retrieve successfully"); Assert.That(helper.TryGetLangsFromCss("NUMBER_SIGNMyClass", out output), Is.True, "corrected class name should also work"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Run the export /// </summary> /// ------------------------------------------------------------------------------------ public void Run() { // Check whether we're about to overwrite an existing file. if (File.Exists(m_fileName)) { string sFmt = DlgResources.ResourceString("kstidAlreadyExists"); string sMsg = String.Format(sFmt, m_fileName); string sCaption = DlgResources.ResourceString("kstidExportXHTML"); if (MessageBox.Show(sMsg, sCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } } try { try { m_writer = new StreamWriter(m_fileName, false, Encoding.UTF8); m_strm = new TextWriterStream(m_writer); m_xhtml = new XhtmlHelper(m_writer, m_cache); } catch (Exception e) { MessageBox.Show(e.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } ExportTE(); } catch (Exception e) { Exception inner = e.InnerException != null ? e.InnerException : e; if (inner is IOException) { MessageBox.Show(inner.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else throw inner; } finally { if (m_writer != null) { try { m_writer.Close(); } catch { // ignore errors on close } } m_writer = null; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize the object with some useful information, and write the initial /// element start tag to the output. /// </summary> /// ------------------------------------------------------------------------------------ public void Initialize(FdoCache cache, Mediator mediator, TextWriter w, string sDataType, string sFormat, string sOutPath, string sBodyClass) { m_writer = w; m_strm = new TextWriterStream(w); m_cache = cache; m_mediator = mediator; m_stylesheet = Widgets.FontHeightAdjuster.StyleSheetFromMediator(m_mediator); m_mdc = cache.MetaDataCacheAccessor; m_sFormat = sFormat.ToLowerInvariant(); if (m_sFormat == "xhtml") { m_xhtml = new XhtmlHelper(w, cache); m_xhtml.WriteXhtmlHeading(sOutPath, null, sBodyClass); } else { w.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); w.WriteLine("<{0}>", sDataType); } m_cssType = (sBodyClass == "notebookBody") ? XhtmlHelper.CssType.Notebook : XhtmlHelper.CssType.Dictionary; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize the object with some useful information, and write the initial /// element start tag to the output. /// </summary> /// <param name="cache">The cache.</param> /// <param name="w">The w.</param> /// <param name="sDataType">Type of the s data.</param> /// <param name="sFormat">The s format.</param> /// <param name="sOutPath">The s out path.</param> /// ------------------------------------------------------------------------------------ public void Initialize(FdoCache cache, TextWriter w, string sDataType, string sFormat, string sOutPath) { m_writer = w; m_strm = new TextWriterStream(w); m_cache = cache; m_sFormat = sFormat.ToLowerInvariant(); m_fUseRFC4646 = m_sFormat == "xhtml" || m_sFormat == "lift"; m_xhtml = new XhtmlHelper(w, cache); if (m_sFormat == "xhtml") { m_xhtml.WriteXhtmlHeading(sOutPath, null, "dicBody"); } else { w.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); w.WriteLine("<{0}>", sDataType); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Run the export /// </summary> /// ------------------------------------------------------------------------------------ public void Run(Form dialogOwner) { // Check whether we're about to overwrite an existing file. if (FileUtils.IsFileReadable(m_fileName)) { string sFmt = DlgResources.ResourceString("kstidAlreadyExists"); string sMsg = String.Format(sFmt, m_fileName); string sCaption = DlgResources.ResourceString("kstidExportXHTML"); if (MessageBoxUtils.Show(dialogOwner, sMsg, sCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } } try { try { m_writer = FileUtils.OpenFileForWrite(m_fileName, Encoding.UTF8); m_xhtml = new XhtmlHelper(m_writer, m_cache); } catch (Exception e) { MessageBoxUtils.Show(dialogOwner, e.Message, m_app.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } ExportTE(dialogOwner); } catch (Exception e) { Exception inner = e.InnerException ?? e; if (inner is IOException) { MessageBoxUtils.Show(dialogOwner, inner.Message, m_app.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else throw inner; } finally { if (m_writer != null) { try { m_writer.Close(); } catch { // ignore errors on close } } m_writer = null; } }