Skip to content

Commit

Permalink
Changed Yahoo-specific HTML-to-text rule that does special <p> handli…
Browse files Browse the repository at this point in the history
…ng to instead detect if there are more <p> elements than <br> elements and do the special sauce if there are. This also makes Blogger and maybe Wordpress behave somewhat better.
  • Loading branch information
adam-p committed Oct 1, 2013
1 parent b034324 commit be739db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/common/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
}

/* To add site specific rules, you can use the `data-md-url` attribute that we
add to the wrapper element. */
add to the wrapper element. Note that rules like this are used depending
on the URL you're *sending* from, not the URL where the recipient views it.
*/
/*
.markdown-here-wrapper[data-md-url*="mail.yahoo."] ul {
color: red;
Expand Down
11 changes: 9 additions & 2 deletions src/common/mdh-html-to-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,15 @@ MdhHtmlToText.prototype._preprocess = function() {

// Yahoo seems to often/always/sometimes (only in Chrome?) use <p> instead
// of <div>. We'll replace the former with the latter so that our other rules work.
// TODO: Figure out if it's more than Yahoo that's a problem.
if (this.url && this.url.match(/\.yahoo\./i)) {
// This also seems to be the case in Blogger.
// Instead of adding URL matches, we're going to count the number of <p> and
// <br> elements and do some replacement if there are more of the former than
// the latter.
var brMatches = this.preprocessInfo.html.match(/<br\b/g);
brMatches = (brMatches ? brMatches.length : 0);
var pMatches = this.preprocessInfo.html.match(/<p\b/g);
pMatches = (pMatches ? pMatches.length : 0);
if (pMatches > brMatches) {
this.preprocessInfo.html =
this.preprocessInfo.html
.replace(/<p\b[^>]*>/ig, '<div>')
Expand Down
7 changes: 1 addition & 6 deletions src/common/options-iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,10 @@
| col 2 is | centered | $12 |<br>
| zebra stripes | are neat | $1 |<br>
<br>
Horizontal rule<br>
Here's a horizontal rule:<br>
<br>
---<br>
<br>
&lt;dl><br>
&lt;dt>Definition list&lt;/dt><br>
&lt;dd>Is something people use sometimes.&lt;/dd><br>
&lt;/dl><br>
<br>
```<br>
code block<br>
with no highlighting<br>
Expand Down

0 comments on commit be739db

Please sign in to comment.