Skip to content

Commit

Permalink
Merge pull request #90 from neurospeech/master
Browse files Browse the repository at this point in the history
Access to underlying Document made public
  • Loading branch information
martinnormark committed Feb 23, 2016
2 parents 960ca99 + 09fae39 commit f513963
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
23 changes: 21 additions & 2 deletions PreMailer.Net/PreMailer.Net/PreMailer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace PreMailer.Net
{
public class PreMailer
public class PreMailer : IDisposable
{
private readonly IHtmlDocument _document;
private bool _removeStyleElements;
Expand Down Expand Up @@ -389,5 +389,24 @@ private void StripElementAttributes(params string[] attributeNames)
}
}
}
}


/// <summary>
/// Access underlying IHTMLDocument
/// </summary>
public IHtmlDocument Document {
get {
return _document;
}
}


/// <summary>
/// Dispose underlying document
/// </summary>
public void Dispose()
{
_document.Dispose();
}
}
}
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ Both absolute and relative URLs are suppored. If the URL is relative, you must s
If you want to [apply mobile styles to your e-mail](http://help.campaignmonitor.com/topic.aspx?t=164), you should put your
mobile specific styles in its own `style` block that targets the appropriate devices using media queries.

But since you cannot know by the time of sending an e-mail wether or not it will be viewed on a mobile device, the `style`
But since you cannot know by the time of sending an e-mail wether or not it will be viewed on a mobile device, the `style`
block that targets mobile devices should not be inlined!

To ignore a `style` block, you need to specify an ignore selector when calling the `MoveCssInline` method, like this:

```csharp
var result = PreMailer.MoveCssInline(input, false, ignoreElements: "#ignore");
```

And your mobile specific `style` block should have an ID of `ignore`:

```html
<style type="text/css" id="ignore">.target { width: 1337px; }</style>
```
Expand All @@ -70,7 +70,7 @@ For example

```css
table {
-premailer-cellspacing: 5;
-premailer-cellspacing: 5;
-premailer-width: 500;
}
```
Expand All @@ -81,6 +81,19 @@ will make a `table` element render as
<table cellspacing="5" width="500">
```

### Custom Dom Processing
```csharp
using(var pm = new PreMailer(html)){

var document = pm.Document;

// use AngleSharp to process document before moving css inline ...
var result = pm.MoveCssInline();
}
```


### Notes

- Pseudo classes/elements are not supported by [CsQuery](https://github.com/jamietre/CsQuery) (which PreMailer.Net uses internally). Any that are encountered in your HTML will be ignored and logged to the `InlineResult.Warnings` collection.
Expand Down

0 comments on commit f513963

Please sign in to comment.