本文整理汇总了C#中Bloom.Book.HtmlDom类的典型用法代码示例。如果您正苦于以下问题:C# HtmlDom类的具体用法?C# HtmlDom怎么用?C# HtmlDom使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HtmlDom类属于Bloom.Book命名空间,在下文中一共展示了HtmlDom类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyImageMetadataToWholeBook
public static void CopyImageMetadataToWholeBook(string folderPath, HtmlDom dom, Metadata metadata, IProgress progress)
{
progress.WriteStatus("Starting...");
//First update the images themselves
int completed = 0;
var imgElements = GetImagePaths(folderPath);
foreach (string path in imgElements)
{
progress.ProgressIndicator.PercentCompleted = (int)(100.0 * (float)completed / imgElements.Count());
progress.WriteStatus("Copying to " + Path.GetFileName(path));
try
{
metadata.WriteIntellectualPropertyOnly(path);
}
catch (TagLib.CorruptFileException e)
{
NonFatalProblem.Report(ModalIf.Beta, PassiveIf.All,"Image metadata problem", "Bloom had a problem accessing the metadata portion of this image " + path+ " ref(BL-3214)", e);
}
++completed;
}
//Now update the html attributes which echo some of it, and is used by javascript to overlay displays related to
//whether the info is there or missing or whatever.
foreach (XmlElement img in dom.SafeSelectNodes("//img"))
{
UpdateImgMetdataAttributesToMatchImage(folderPath, img, progress, metadata);
}
}
示例2: SetBaseForRelativePaths_NoExistingBase_Adds
public void SetBaseForRelativePaths_NoExistingBase_Adds()
{
var dom = new HtmlDom(
@"<html><head/></html>");
dom.SetBaseForRelativePaths("theBase");
AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("html/head/base[@href='theBase']", 1);
}
示例3: AppendToolboxPanel
/// <summary>Loads the requested panel into the toolbox</summary>
public static void AppendToolboxPanel(HtmlDom domForToolbox, string fileName)
{
var toolbox = domForToolbox.Body.SelectSingleNode("//div[@id='toolbox']");
var toolDom = new HtmlDom(XmlHtmlConverter.GetXmlDomFromHtmlFile(fileName));
AddToolDependencies(toolDom);
AppendAllChildren(toolDom.Body, toolbox);
}
示例4: CopyImageMetadataToWholeBook
public static void CopyImageMetadataToWholeBook(string folderPath, HtmlDom dom, Metadata metadata, IProgress progress)
{
progress.WriteStatus("Starting...");
//First update the images themselves
int completed = 0;
var imgElements = GetImagePaths(folderPath);
foreach (string path in imgElements)
{
progress.ProgressIndicator.PercentCompleted = (int)(100.0 * (float)completed / imgElements.Count());
progress.WriteStatus("Copying to " + Path.GetFileName(path));
using (var image = PalasoImage.FromFile(path))
{
image.Metadata = metadata;
image.SaveUpdatedMetadataIfItMakesSense();
}
++completed;
}
//Now update the html attributes which echo some of it, and is used by javascript to overlay displays related to
//whether the info is there or missing or whatever.
foreach (XmlElement img in dom.SafeSelectNodes("//img"))
{
UpdateImgMetdataAttributesToMatchImage(folderPath, img, progress, metadata);
}
}
示例5: BaseForRelativePaths_NoHead_NoLongerThrows
public void BaseForRelativePaths_NoHead_NoLongerThrows()
{
var dom = new HtmlDom(
@"<html></html>");
dom.BaseForRelativePaths = "theBase";
Assert.AreEqual("theBase", dom.BaseForRelativePaths);
}
示例6: AddUIDictionaryToDom
public static void AddUIDictionaryToDom(HtmlDom pageDom, CollectionSettings collectionSettings)
{
XmlElement dictionaryScriptElement = pageDom.RawDom.SelectSingleNode("//script[@id='ui-dictionary']") as XmlElement;
if (dictionaryScriptElement != null)
dictionaryScriptElement.ParentNode.RemoveChild(dictionaryScriptElement);
dictionaryScriptElement = pageDom.RawDom.CreateElement("script");
dictionaryScriptElement.SetAttribute("type", "text/javascript");
dictionaryScriptElement.SetAttribute("id", "ui-dictionary");
var d = new Dictionary<string, string>();
d.Add(collectionSettings.Language1Iso639Code, collectionSettings.Language1Name);
if (!String.IsNullOrEmpty(collectionSettings.Language2Iso639Code) && !d.ContainsKey(collectionSettings.Language2Iso639Code))
d.Add(collectionSettings.Language2Iso639Code, collectionSettings.GetLanguage2Name(collectionSettings.Language2Iso639Code));
if (!String.IsNullOrEmpty(collectionSettings.Language3Iso639Code) && !d.ContainsKey(collectionSettings.Language3Iso639Code))
d.Add(collectionSettings.Language3Iso639Code, collectionSettings.GetLanguage3Name(collectionSettings.Language3Iso639Code));
d.Add("vernacularLang", collectionSettings.Language1Iso639Code);//use for making the vernacular the first tab
d.Add("{V}", collectionSettings.Language1Name);
d.Add("{N1}", collectionSettings.GetLanguage2Name(collectionSettings.Language2Iso639Code));
d.Add("{N2}", collectionSettings.GetLanguage3Name(collectionSettings.Language3Iso639Code));
AddLocalizedHintContentsToDictionary(pageDom, d, collectionSettings);
dictionaryScriptElement.InnerText = String.Format("function GetDictionary() {{ return {0};}}", JsonConvert.SerializeObject(d));
pageDom.Head.InsertAfter(dictionaryScriptElement, pageDom.Head.LastChild);
}
示例7: BaseForRelativePaths_NullPath_SetsToEmpty
public void BaseForRelativePaths_NullPath_SetsToEmpty()
{
var dom = new HtmlDom(
@"<html><head><base href='original'/></head></html>");
dom.BaseForRelativePaths = null;
AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("html/head/base", 0);
Assert.AreEqual(string.Empty, dom.BaseForRelativePaths);
}
示例8: BringBookUpToDate_DomHas2ContentLanguages_PulledIntoBookProperties
public void BringBookUpToDate_DomHas2ContentLanguages_PulledIntoBookProperties()
{
_bookDom = new HtmlDom(@"<html><head><div id='bloomDataDiv'><div data-book='contentLanguage2'>okm</div><div data-book='contentLanguage3'>kbt</div></div></head><body></body></html>");
var book = CreateBook();
book.BringBookUpToDate(new NullProgress());
Assert.AreEqual("okm", book.MultilingualContentLanguage2);
Assert.AreEqual("kbt", book.MultilingualContentLanguage3);
}
示例9: BaseForRelativePaths_HasExistingBase_Removes
public void BaseForRelativePaths_HasExistingBase_Removes()
{
var dom = new HtmlDom(
@"<html><head><base href='original'/></head></html>");
AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("html/head/base[@href='original']", 1);
dom.BaseForRelativePaths = "new";
AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("html/head/base", 0);
Assert.AreEqual("new", dom.BaseForRelativePaths);
}
示例10: SetBaseForRelativePaths_HasExistingBase_Replaces
public void SetBaseForRelativePaths_HasExistingBase_Replaces()
{
var dom = new HtmlDom(
@"<html><head><base href='original'/></head></html>");
AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("html/head/base[@href='original']", 1);
dom.SetBaseForRelativePaths("new");
AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("html/head/base[@href='original']", 0);
AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("html/head/base[@href='new']", 1);
}
示例11: RemoveMetaValue_IsThere_RemovesIt
public void RemoveMetaValue_IsThere_RemovesIt()
{
var dom = new HtmlDom(
@"<html><head>
<meta name='one' content='1'/>
</head></html>");
dom.RemoveMetaElement("one");
AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//meta[@name='one']", 0);
}
示例12: BookData
/// <param name="dom">Set this parameter to, say, a page that the user just edited, to limit reading to it, so its values don't get overriden by previous pages.
/// Supply the whole dom if nothing has priority (which will mean the data-div will win, because it is first)</param>
/// <param name="collectionSettings"> </param>
/// <param name="updateImgNodeCallback">This is a callback so as not to introduce dependencies on ImageUpdater & the current folder path</param>
public BookData(HtmlDom dom, CollectionSettings collectionSettings, Action<XmlElement> updateImgNodeCallback)
{
_dom = dom;
_updateImgNode = updateImgNodeCallback;
_collectionSettings = collectionSettings;
GetOrCreateDataDiv();
_dataset = GatherDataItemsFromCollectionSettings(_collectionSettings);
GatherDataItemsFromXElement(_dataset,_dom.RawDom);
}
示例13: LoadPanelIntoToolbox
public static void LoadPanelIntoToolbox(HtmlDom domForToolbox, ToolboxTool tool, List<string> checkedBoxes, string toolboxFolder)
{
// For all the toolbox tools, the tool name is used as the name of both the folder where the
// assets for that tool are kept, and the name of the main htm file that represents the tool.
var fileName = tool.ToolId + "ToolboxPanel.html";
var path = BloomFileLocator.sTheMostRecentBloomFileLocator.LocateFile(fileName);
Debug.Assert(!string.IsNullOrEmpty(path));
AppendToolboxPanel(domForToolbox, path);
checkedBoxes.Add(tool.ToolId + "Check");
}
示例14: Constructor_CollectionSettingsHasCountrProvinceDistrict_LanguageLocationFilledIn
public void Constructor_CollectionSettingsHasCountrProvinceDistrict_LanguageLocationFilledIn()
{
// var dom = new HtmlDom(@"<html><head><div id='bloomDataDiv'>
// <div data-book='country'>the country</div>
// <div data-book='province'>the province</div>
// <div data-book='district'>the district</div>
// </div></head><body></body></html>");
var dom = new HtmlDom();
var data = new BookData(dom, new CollectionSettings(){Country="the country", Province = "the province", District= "the district"}, null);
Assert.AreEqual("the district, the province<br/>the country", data.GetVariableOrNull("languageLocation", "*"));
}
示例15: AddUIDictionaryToDom
public static void AddUIDictionaryToDom(HtmlDom pageDom, CollectionSettings collectionSettings)
{
CheckDynamicStrings();
// add dictionary script to the page
XmlElement dictionaryScriptElement = pageDom.RawDom.SelectSingleNode("//script[@id='ui-dictionary']") as XmlElement;
if (dictionaryScriptElement != null)
dictionaryScriptElement.ParentNode.RemoveChild(dictionaryScriptElement);
dictionaryScriptElement = pageDom.RawDom.CreateElement("script");
dictionaryScriptElement.SetAttribute("type", "text/javascript");
dictionaryScriptElement.SetAttribute("id", "ui-dictionary");
var d = new Dictionary<string, string>();
d.Add(collectionSettings.Language1Iso639Code, collectionSettings.Language1Name);
if (!String.IsNullOrEmpty(collectionSettings.Language2Iso639Code))
SafelyAddLanguage(d, collectionSettings.Language2Iso639Code,
collectionSettings.GetLanguage2Name(collectionSettings.Language2Iso639Code));
if (!String.IsNullOrEmpty(collectionSettings.Language3Iso639Code))
SafelyAddLanguage(d, collectionSettings.Language3Iso639Code,
collectionSettings.GetLanguage3Name(collectionSettings.Language3Iso639Code));
SafelyAddLanguage(d, "vernacularLang", collectionSettings.Language1Iso639Code);//use for making the vernacular the first tab
SafelyAddLanguage(d, "{V}", collectionSettings.Language1Name);
SafelyAddLanguage(d, "{N1}", collectionSettings.GetLanguage2Name(collectionSettings.Language2Iso639Code));
SafelyAddLanguage(d, "{N2}", collectionSettings.GetLanguage3Name(collectionSettings.Language3Iso639Code));
// TODO: Eventually we need to look through all .bloom-translationGroup elements on the current page to determine
// whether there is text in a language not yet added to the dictionary.
// For now, we just add a few we know we need
AddSomeCommonNationalLanguages(d);
MakePageLabelLocalizable(pageDom, d);
// Hard-coded localizations for 2.0
AddHtmlUiStrings(d);
// Do this last, on the off-chance that the page contains a localizable string that matches
// a language code.
AddLanguagesUsedInPage(pageDom.RawDom, d);
dictionaryScriptElement.InnerText = String.Format("function GetInlineDictionary() {{ return {0};}}", JsonConvert.SerializeObject(d));
// add i18n initialization script to the page
//AddLocalizationTriggerToDom(pageDom);
pageDom.Head.InsertAfter(dictionaryScriptElement, pageDom.Head.LastChild);
_collectDynamicStrings = false;
}