Skip to content

Commit

Permalink
Fixed bug: Yahoo: Code blocks would just show a bunch of span tags. (…
Browse files Browse the repository at this point in the history
…Introduced in 2.3.0.)
  • Loading branch information
adam-p committed Jun 20, 2012
1 parent 0d7241a commit a9a5806
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change Log
==========

2012-06-20: v2.3.1
------------------

* Fixed bug: Yahoo: Code blocks would just show a bunch of span tags. (Introduced in 2.3.0.)

2012-06-20: v2.3.0
------------------

Expand Down
24 changes: 21 additions & 3 deletions src/common/markdown-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,21 @@
text = text.replace(/<(img[^>]*)>/ig, '&lt;$1&gt;');

// Leave rendered links intact.
keepTags = ['a', 'b', 'i', 'u', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'font', 'span', 'ul', 'ol'];
keepTags = ['a', 'b', 'i', 'u', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'font', 'ul', 'ol'];
for (i = 0; i < keepTags.length; i++) {
text = excludeTagBlocks(keepTags[i], text, false);
}

// Span tags are used by email editors for formatting (especially for
// background colour -- "highlighting"), but Yahoo also uses them around
// almost everything. If we escape them all, we'll mess up code blocks
// (you'll just see a lot of span tag crap). So we'll only escape span
// tags that have styles.
keepTags = ['span'];
for (i = 0; i < keepTags.length; i++) {
text = excludeTagBlocks(keepTags[i], text, false, 'style');
}

// Experimentation has shown some tags that need to be tweaked a little.
text =
text
Expand All @@ -63,11 +73,19 @@
// special "exclude" class to them.
// If `wrapInPara` is true, `<p>` tags will be added before and after each
// tag block found.
function excludeTagBlocks(tagName, text, wrapInPara) {
// If `ifHasAttribute` is non-null, tags will only be matched if they have
// that attribute.
function excludeTagBlocks(tagName, text, wrapInPara, ifHasAttribute) {
var depth, startIndex, openIndex, closeIndex, currentOpenIndex,
openTagRegex, closeTagRegex, remainderText, closeTagLength;

openTagRegex = new RegExp('<'+tagName+'\\b', 'i');
if (ifHasAttribute) {
openTagRegex = new RegExp('<'+tagName+'\\b[^>]*\\b'+ifHasAttribute+'\\b', 'i');
}
else {
openTagRegex = new RegExp('<'+tagName+'\\b', 'i');
}

closeTagRegex = new RegExp('</'+tagName+'\\b', 'i');

depth = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description about="urn:mozilla:install-manifest">
<em:type>2</em:type> <!-- 2 : Extension -->
<em:id>[email protected]</em:id>
<em:version>2.3.0</em:version>
<em:version>2.3.1</em:version>

<!-- Any suitably modern toolkit application -->
<em:targetApplication>
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Markdown Here",
"version": "2.3.0",
"version": "2.3.1",
"description": "Write your email in Markdown, then make it pretty.",
"homepage_url": "https://chrome.google.com/webstore/detail/elifhakcjgalahccnjkneoccemfahfoa",
"minimum_chrome_version": "6",
Expand Down

0 comments on commit a9a5806

Please sign in to comment.