Git Product home page Git Product logo

bracketpipe's People

Contributors

erdomke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bracketpipe's Issues

Replace HtmlText with Links

I've used HtmlSanitizer as the basis for injecting links to keywords in content. Basically, when a TextToken comes up, it looks for keywords in the value and wraps a link around the keyword.

Unfortunately I don't think this is the right approach, as it seems to mess up the parent nodes somehow.

<ul><liTitle Here ><br><spanThis is a test result <a href="/search?q=foo">foo</a> <a href="/search?q=bar">bar</a> is also here....></span></li></ul>

This is the code I'm using to test inject links:

static HashSet<string> keywords = new HashSet<string>(new string[]  
{
    "foo",
    "bar"
});

private static HtmlText InjectLink(HtmlNode node, HtmlSanitizeSettings settings)
{
    var words = node.Value.Split(new char[] { ' ' });
    for (int i = 0; i < words.Length; i++)
    {
        var word = words[i];
        if (keywords.Contains(word))
        {
            var link = $"<a href=\"/search?q={word}\">{word}</a>";
            words[i] = link;
        }
    }
    var value = string.Join(" ", words);
    var text = new HtmlText(node.Position, value)
    {
        Encode = false
    };
    return text;
}

Which I call from a modification of the Sanitize() function:

switch (token.Type)
{
    case HtmlTokenType.Text:
        if (removeDepth < 0)
        {
            if (inStyle)
                yield return new HtmlText(token.Position, SanitizeCss(token.Value, settings, true));
            else
                // yield return token;
                yield return InjectLink(token, settings);
                
        }
        break;
//...

Test Html:

<ul><li>Title Here <br><span>This is a test result foo bar is also here....</span></li></ul>

Expected Result:

<ul><li>Title Here <br><span>This is a test result <a href=""/search/q?=foo"">foo</a> <a href=""/search/q?=bar"">bar</a> is also here....</span></li></ul>

Actual Result:

<ul><liTitle Here ><br><spanThis is a test result <a href="/search?q=foo">foo</a> <a href="/search?q=bar">bar</a> is also here....></span></li></ul>

Example Project:
CleanAndLink.zip

iso-2022-cn is not a supported encoding name

I call this method:

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

Then when I try to convert certain text, I get this error:

System.ArgumentException: ''iso-2022-cn' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. (Parameter 'name')'

Why is that?

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.