-
Notifications
You must be signed in to change notification settings - Fork 477
Adding support for <link> css inclusion #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 7 commits
48db17f
b09100c
3bb451b
62d3cc1
d313e10
6757960
63d31a9
9c3a092
45287a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Net; | ||
using System.Text; | ||
|
||
namespace Svg | ||
{ | ||
[NonSvgElementAttribute("link")] | ||
public class SvgLink : NonSvgElement | ||
{ | ||
public SvgLink() | ||
: base("link") | ||
{ | ||
|
||
} | ||
public enum RelativeValue | ||
{ | ||
Unknown, | ||
Alternate, | ||
Author, | ||
Help, | ||
Icon, | ||
License, | ||
Next, | ||
Pingback, | ||
Preconnect, | ||
Prefetch, | ||
Preload, | ||
Prerender, | ||
Prev, | ||
Search, | ||
Stylesheet | ||
} | ||
|
||
public override SvgElement DeepCopy() | ||
{ | ||
return DeepCopy<SvgLink>(); | ||
} | ||
|
||
FabioFerrettiMoodys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[SvgAttribute("href")] | ||
public string Href | ||
{ | ||
get { return GetAttribute<string>("href", false, string.Empty); } | ||
set { Attributes["href"] = value; } | ||
} | ||
|
||
[SvgAttribute("rel")] | ||
public RelativeValue Rel | ||
{ | ||
get { return GetAttribute<RelativeValue>("rel", false, RelativeValue.Unknown); } | ||
set { Attributes["rel"] = value; } | ||
} | ||
|
||
FabioFerrettiMoodys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
public string GetLinkContentAsText(RelativeValue rel) | ||
{ | ||
var stream = GetLinkContentAsStream(rel); | ||
FabioFerrettiMoodys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (stream == null) | ||
return null; | ||
|
||
string content = null; | ||
using (StreamReader sr = new StreamReader(stream)) | ||
FabioFerrettiMoodys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
content = sr.ReadToEnd(); | ||
} | ||
stream.Dispose(); | ||
return content; | ||
} | ||
|
||
|
||
public Stream GetLinkContentAsStream(RelativeValue rel = RelativeValue.Unknown) | ||
{ | ||
if (Rel != rel && rel != RelativeValue.Unknown) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're doing a comparison with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is to avoid as much as possible the use of the content with a incorrect rel type. if you call GetLinkContentAsStream(stylesheet) on a link with rel="icon" for exemple, you will not get the content and cannot use it as a stylesheet by mistake (and make the code crash). assuming you are absolutely sure of what you do and what you have, you can just call GetLinkContentAsStream(), you will get the content independently of the rel these technique avoid to check everywhere if the Rel is correct every where you use the link content, here it is done in only one place. I can remove if if you prefer. |
||
return null; | ||
// Uri MaxLength is 65519 (https://msdn.microsoft.com/en-us/library/z6c2z492.aspx) | ||
// if using data URI scheme, very long URI may happen. | ||
var safeUriString = Href.Length > 65519 ? Href.Substring(0, 65519) : Href; | ||
|
||
try | ||
{ | ||
var uri = new Uri(safeUriString, UriKind.RelativeOrAbsolute); | ||
|
||
if (!uri.IsAbsoluteUri) | ||
uri = new Uri(OwnerDocument.BaseUri, uri); | ||
|
||
// should work with http: and file: protocol urls | ||
var httpRequest = WebRequest.Create(uri); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should check that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kimsey0 Can you fix it by editing the PR source? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's been too long since I worked on this project, so I can't really remember the details, nor how tests etc. are structured. I can see that #873 split There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kimsey0 Thanks for the update. Just do not know the best way to handle these staled PR.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Never done, can you outline the procedure and give me some hints? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are asking about the git workflow, something like:
Is this what you are asking? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think so, thanks - will look into it this weekend. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depending on the policies of this project (the contribution guide doesn't say), you can also just avoid squashing the commits, leaving the original author for each one and making it clear who's done what. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Something to be added... The current (undocumented) convention is that commits are usually squashed and only rebased if the individual commits are independent changes to be preserved, and have sensible commit comments (which is not the case here). Though it is possible to rebase the PR respectively before the merge, if a rebase is wanted. |
||
|
||
var webResponse = httpRequest.GetResponse(); | ||
var stream = webResponse.GetResponseStream(); | ||
FabioFerrettiMoodys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (stream.CanSeek) | ||
stream.Position = 0; | ||
return stream; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Trace.TraceError("Error loading Link content: '{0}', error: {1} ", Href, ex.Message); | ||
return null; | ||
} | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Svg | ||
{ | ||
/// <summary> | ||
/// Specifies the SVG name of an <see cref="SvgElement"/>. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public sealed class NonSvgElementAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Gets the name of the SVG element. | ||
/// </summary> | ||
public string ElementName { get; private set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="NonSvgElementAttribute"/> class with the specified element name; | ||
/// </summary> | ||
/// <param name="elementName">The name of the non SVG element.</param> | ||
public NonSvgElementAttribute(string elementName) | ||
{ | ||
this.ElementName = elementName; | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.