Coder Social home page Coder Social logo

htmlfragmenthelper's Introduction

##HtmlFragmentHelper

HtmlFragmentHelper makes handling Microsoft HTML clipboard format easy in your .NET applications. Written in C#, it parses HTML clipboard metadata in the clipboard and separates it from the HTML source, and further parses the precise source that belongs to the selected html fragment in the clipboard. Each property is then easily accessible from a strongly typed view model, rather than losing them in a blob of text.

HtmlFragmentViewModel also includes a number of convenience methods and properties to make dealing with this data easy. For now, the details are in the source.

The engine of HtmlFragmentHelper lives inside a single file, HtmlFragmentViewModel.cs. To create the view model, you send HtmlFragmentViewModel's constructor the contents of a Microsoft formatted HTML Fragment as a raw string.

###Example usage

public string CreateQuote(string htmlFragmentSource) 
{
    string strIntroLink = string.Empty;
    HtmlFragmentViewModel vm = new HtmlFragmentViewModel(htmlFragmentSource);

    if (vm.SourceUrl.Length > 0 && vm.SourceUrlDomainSecondAndTopLevelsOnly.Length > 0)
    {
        strIntroLink = string.Format("From <a href=\"{0}\">{1}</a>:" + Environment.NewLine + Environment.NewLine,
            vm.SourceUrl, vm.SourceUrlDomainSecondAndTopLevelsOnly);
    }

    return strIntroLink + vm.FragmentSourceParsed;
}

To produce the source for htmlFragmentSource, you'd likely use async code similar to the following:

string src = string.Empty;
DataPackageView dataPackageView = Clipboard.GetContent();

if (dataPackageView.Contains(StandardDataFormats.Html))
{
    src = await Clipboard.GetContent().GetHtmlFormatAsync();
}
else if (dataPackageView.Contains(StandardDataFormats.Text))
{
    src = await Clipboard.GetContent().GetTextAsync();
}
// Else it's a clipboard format we're not handling.

string blockquotedHtml = CreateQuote(src);

The resulting blockquotedHtml might look like this:

From <a href="http://daringfireball.net/2016/10/mossberg_siri">daringfireball.net</a>:

<P>Mossberg:</P><BLOCKQUOTE><P>For instance, when I asked Siri on my Mac how long it would take me to get to work, it said it didn't have my work address - even though the "me" contact card contains a work address and the same synced contact card on my iPhone allowed Siri to give me an answer.</P><P>Similarly, on my iPad, when I asked what my next appointment was, it said "Sorry, Walt, something's wrong" - repeatedly, with slightly different wording, in multiple places on multiple days. But, using the same Apple calendar and data, Siri answered correctly on the iPhone.</P></BLOCKQUOTE><P>These sort of glaring inconsistencies are almost as bad as universal failures. The big problem Apple faces with Siri is that when people encounter these problems, <EM>they stop trying</EM>.</P>

###LICENSE

// =========================== LICENSE ===============================
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// ======================== EO LICENSE ===============================

htmlfragmenthelper's People

Contributors

ruffin-- avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.