erdomke / bracketpipe Goto Github PK
View Code? Open in Web Editor NEWBracketPipe is a .NET library for building parsing and processing piplines for web languages like HTML, CSS, Javscript, SVG, and MathML
License: MIT License
BracketPipe is a .NET library for building parsing and processing piplines for web languages like HTML, CSS, Javscript, SVG, and MathML
License: MIT License
Given this HTML:
<div style="font-size:12pt;;"><p style="font-size:10.5pt;margin:0;">Some <strong>initial </strong>text.</p><p style="font-size:10.5pt;margin:0;"><br></p></div>
Calling Html.ToMarkdown
is returning:
Some **initial** text.
\
With an extra non-sensical '\' at the end.
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
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.