本文整理汇总了C#中Bloom.Book.HtmlDom类的典型用法代码示例。如果您正苦于以下问题:C# HtmlDom类的具体用法?C# HtmlDom怎么用?C# HtmlDom使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HtmlDom类属于Bloom.Book命名空间,在下文中一共展示了HtmlDom类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:33,代码来源:ImageUpdater.cs
示例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);
}
开发者ID:JohnThomson,项目名称:testBloom,代码行数:7,代码来源:HtmlDomTests.cs
示例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);
}
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:8,代码来源:ToolboxView.cs
示例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);
}
}
开发者ID:JohnThomson,项目名称:testBloom,代码行数:28,代码来源:ImageUpdater.cs
示例5: BaseForRelativePaths_NoHead_NoLongerThrows
public void BaseForRelativePaths_NoHead_NoLongerThrows()
{
var dom = new HtmlDom(
@"<html></html>");
dom.BaseForRelativePaths = "theBase";
Assert.AreEqual("theBase", dom.BaseForRelativePaths);
}
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:7,代码来源:HtmlDomTests.cs
示例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);
}
开发者ID:JohnThomson,项目名称:testBloom,代码行数:28,代码来源:RuntimeInformationInjector.cs
示例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);
}
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:8,代码来源:HtmlDomTests.cs
示例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);
}
开发者ID:JohnThomson,项目名称:testBloom,代码行数:8,代码来源:BookTests.cs
示例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);
}
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:9,代码来源:HtmlDomTests.cs
示例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);
}
开发者ID:JohnThomson,项目名称:testBloom,代码行数:9,代码来源:HtmlDomTests.cs
示例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);
}
开发者ID:JohnThomson,项目名称:testBloom,代码行数:9,代码来源:HtmlDomTests.cs
示例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);
}
开发者ID:jorik041,项目名称:BloomDesktop,代码行数:13,代码来源:BookData.cs
示例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");
}
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:10,代码来源:ToolboxView.cs
示例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", "*"));
}
开发者ID:JohnThomson,项目名称:testBloom,代码行数:11,代码来源:BookDataTests.cs
示例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;
}
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:50,代码来源:RuntimeInformationInjector.cs
示例16: GetMetadata
/// <summary>
/// Create a Clearshare.Metadata object by reading values out of the dom's bloomDataDiv
/// </summary>
/// <param name="brandingNameOrFolderPath"> Normally, the branding is just a name, which we look up in the official branding folder
//but unit tests can instead provide a path to the folder.
/// </param>
public static Metadata GetMetadata(HtmlDom dom, string brandingNameOrFolderPath = "")
{
if (ShouldSetToDefaultCopyrightAndLicense(dom))
{
return GetMetadataWithDefaultCopyrightAndLicense(brandingNameOrFolderPath);
}
var metadata = new Metadata();
var copyright = dom.GetBookSetting("copyright");
if (!copyright.Empty)
{
metadata.CopyrightNotice = WebUtility.HtmlDecode(copyright.GetFirstAlternative());
}
var licenseUrl = dom.GetBookSetting("licenseUrl").GetBestAlternativeString(new[] { "*", "en" });
if (string.IsNullOrWhiteSpace(licenseUrl))
{
//NB: we are mapping "RightsStatement" (which comes from XMP-dc:Rights) to "LicenseNotes" in the html.
//custom licenses live in this field, so if we have notes (and no URL) it is a custom one.
var licenseNotes = dom.GetBookSetting("licenseNotes");
if (!licenseNotes.Empty)
{
metadata.License = new CustomLicense { RightsStatement = WebUtility.HtmlDecode(licenseNotes.GetFirstAlternative()) };
}
else
{
// The only remaining current option is a NullLicense
metadata.License = new NullLicense(); //"contact the copyright owner
}
}
else // there is a licenseUrl, which means it is a CC license
{
try
{
metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl);
}
catch (Exception e)
{
throw new ApplicationException("Bloom had trouble parsing this license url: '" + licenseUrl + "'. (ref BL-4108)", e);
}
//are there notes that go along with that?
var licenseNotes = dom.GetBookSetting("licenseNotes");
if(!licenseNotes.Empty)
{
var s = WebUtility.HtmlDecode(licenseNotes.GetFirstAlternative());
metadata.License.RightsStatement = HtmlDom.ConvertHtmlBreaksToNewLines(s);
}
}
return metadata;
}
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:56,代码来源:BookCopyrightAndLicense.cs
示例17: UpdateAllHtmlDataAttributesForAllImgElements_HasBothImgAndBackgroundImageElements_UpdatesBoth
public void UpdateAllHtmlDataAttributesForAllImgElements_HasBothImgAndBackgroundImageElements_UpdatesBoth()
{
var dom = new HtmlDom("<html><body><img src='test.png'/><div style='color:orange; background-image=url(\"test.png\")'/></body></html>");
using (var folder = new TemporaryFolder("bloom pictures test source"))
{
MakeSamplePngImageWithMetadata(folder.Combine("test.png"));
ImageUpdater.UpdateAllHtmlDataAttributesForAllImgElements(folder.FolderPath, dom, new NullProgress());
}
AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//*[@data-copyright='Copyright 1999 by me']", 2);
AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//*[@data-creator='joe']", 2);
AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//*[@data-license='cc-by-nd']", 2);
}
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:14,代码来源:ImageUpdaterTests.cs
示例18: BringBookUpToDate_CoverImageHasMetaData_HtmlForCoverPageHasMetaDataAttributes
public void BringBookUpToDate_CoverImageHasMetaData_HtmlForCoverPageHasMetaDataAttributes()
{
_bookDom = new HtmlDom(@"
<html>
<body>
<div id='bloomDataDiv'>
<div data-book='coverImage'>test.png</div>
</div>
</body>
</html>");
var book = CreateBook();
var imagePath = book.FolderPath.CombineForPath("test.png");
MakeSamplePngImageWithMetadata(imagePath);
book.BringBookUpToDate(new NullProgress());
AssertThatXmlIn.Dom(book.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div/div/div/img[@data-creator='joe']",1);
}
开发者ID:JohnThomson,项目名称:testBloom,代码行数:18,代码来源:BookTests.cs
示例19: UpdateBook
public static void UpdateBook(HtmlDom dom, string language1Iso639Code)
{
int page = 0;
foreach (XmlElement pageDiv in dom.SafeSelectNodes("/html/body//div[contains(@class,'bloom-page')]"))
{
var term = pageDiv.SelectSingleNode("//div[contains(@data-book,'term')]").InnerText.Trim();
XmlNode weekDataNode = pageDiv.SelectSingleNode("//div[contains(@data-book,'week')]");
if(weekDataNode==null)
continue; // term intro books don't have weeks
var week = weekDataNode.InnerText.Trim();
// TODO: need a better way to identify thumbnails, like a class that is always there, lest we replace some other img that we don't want to replace
foreach (XmlElement thumbnailContainer in pageDiv.SafeSelectNodes(".//img"))
{
++page;
thumbnailContainer.SetAttribute("src", language1Iso639Code + "-t" + term + "-w" + week + "-p" + page + ".png");
}
}
}
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:19,代码来源:SHRP_TeachersGuideExtension.cs
示例20: XMatterHelper
/// <summary>
/// Constructs by finding the file and folder of the xmatter pack, given the its key name e.g. "Factory", "SILIndonesia".
/// The name of the file should be (key)-XMatter.htm. The name and the location of the folder is not our problem...
/// we leave it to the supplied fileLocator to find it.
/// </summary>
/// <param name="nameOfXMatterPack">e.g. "Factory", "SILIndonesia"</param>
/// <param name="fileLocator">The locator needs to be able tell us the path to an xmater html file, given its name</param>
public XMatterHelper(HtmlDom bookDom, string nameOfXMatterPack, IFileLocator fileLocator)
{
_bookDom = bookDom;
_nameOfXMatterPack = nameOfXMatterPack;
string directoryName = nameOfXMatterPack + "-XMatter";
string directoryPath;
try
{
directoryPath = fileLocator.LocateDirectoryWithThrow(directoryName);
}
catch(ApplicationException error)
{
var errorTemplate = LocalizationManager.GetString("Errors.XMatterNotFound",
"This Book called for Front/Back Matter pack named '{0}', but Bloom couldn't find that on this computer. You can either install a Bloom Pack that will give you '{0}', or go to Settings:Book Making and change to another Front/Back Matter Pack.");
var msg = string.Format(errorTemplate, nameOfXMatterPack);
ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(), msg);
//NB: we don't want to put up a dialog for each one; one failure here often means 20 more are coming as the other books are loaded!
throw new ApplicationException(msg);
}
var htmName = nameOfXMatterPack + "-XMatter.html";
PathToXMatterHtml = directoryPath.CombineForPath(htmName);
if(!RobustFile.Exists(PathToXMatterHtml))
{
htmName = nameOfXMatterPack + "-XMatter.htm"; // pre- Bloom 3.7
PathToXMatterHtml = directoryPath.CombineForPath(htmName);
}
if (!RobustFile.Exists(PathToXMatterHtml))
{
ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(), "Could not locate the file {0} in {1} (also checked .html)", htmName, directoryPath);
throw new ApplicationException();
}
PathToStyleSheetForPaperAndOrientation = directoryPath.CombineForPath(GetStyleSheetFileName());
if (!RobustFile.Exists(PathToXMatterHtml))
{
ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(), "Could not locate the file {0} in {1}", GetStyleSheetFileName(), directoryPath);
throw new ApplicationException();
}
XMatterDom = XmlHtmlConverter.GetXmlDomFromHtmlFile(PathToXMatterHtml, false);
}
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:48,代码来源:XMatterHelper.cs
注:本文中的Bloom.Book.HtmlDom类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论