<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Automatic HTML Summary / Teaser</title>
	<atom:link href="http://blog.stevenlevithan.com/archives/get-html-summary/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.stevenlevithan.com/archives/get-html-summary</link>
	<description>A JavaScript and regular expression centric blog</description>
	<lastBuildDate>Thu, 02 Feb 2012 02:09:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: vince</title>
		<link>http://blog.stevenlevithan.com/archives/get-html-summary/comment-page-1#comment-100824</link>
		<dc:creator>vince</dc:creator>
		<pubDate>Mon, 09 May 2011 21:09:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/archives/get-html-summary#comment-100824</guid>
		<description>this Cold Fusion version is working great. thanks.</description>
		<content:encoded><![CDATA[<p>this Cold Fusion version is working great. thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TYPO3 HTML save cropping - nerdcenter</title>
		<link>http://blog.stevenlevithan.com/archives/get-html-summary/comment-page-1#comment-49236</link>
		<dc:creator>TYPO3 HTML save cropping - nerdcenter</dc:creator>
		<pubDate>Tue, 16 Mar 2010 16:11:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/archives/get-html-summary#comment-49236</guid>
		<description>[...] Abhilfe schafft die folgende crop-Methode, die eine Portierung der Javascript-Version von Steven Levithan [...]</description>
		<content:encoded><![CDATA[<p>[...] Abhilfe schafft die folgende crop-Methode, die eine Portierung der Javascript-Version von Steven Levithan [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Max Paperno</title>
		<link>http://blog.stevenlevithan.com/archives/get-html-summary/comment-page-1#comment-46590</link>
		<dc:creator>Max Paperno</dc:creator>
		<pubDate>Wed, 27 Jan 2010 05:06:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/archives/get-html-summary#comment-46590</guid>
		<description>Here&#039;s a ColdFusion version of this function. Thanks Steve! Love the regex solution. 

Tested and working, but YMMV. Posted to CFLib.org but not up there yet.

&lt;pre class=&quot;code fixedHeight&quot;&gt;function getLeadingHtml(input, maxChars) {
	// token matches a word, tag, or special character
	var	token = &quot;[[:word:]]+&#124;[^[:word:]&lt;]&#124;(?:]*(\/)?&gt;)&#124;&lt;&quot;;
	var	selfClosingTag = &quot;^(?:[hb]r&#124;img)$&quot;;
	var	output = &quot;&quot;;
	var	charCount = 0;
	var	openTags = &quot;&quot;; var strPos = 0; var tag = &quot;&quot;;
	var i = 1;

	var	match = REFind(token, input, i, &quot;true&quot;);

	while ( (charCount LT maxChars) AND match.pos[1] ) {
		// If this is an HTML tag
		if (match.pos[3]) {
			output = output &amp; Mid(input, match.pos[1], match.len[1]);
			tag = Mid(input, match.pos[3], match.len[3]);
			// If this is not a self-closing tag
			if ( NOT ( match.pos[4] OR REFindNoCase(selfClosingTag, tag) ) ) {
				// If this is a closing tag
				if ( match.pos[2] AND ListFindNoCase(openTags, tag) ) {
					openTags = ListDeleteAt(openTags, ListFindNoCase(openTags, tag)); 
				} else {
					openTags = ListAppend(openTags, tag);
				}
			}
		} else {
			charCount = charCount +  match.len[1];
			if (charCount LTE maxChars) output = output &amp; Mid(input, match.pos[1], match.len[1]);
		}
		
		i = i + match.len[1];
		match = REFind(token, input, i, &quot;true&quot;);
	}

	// Close any tags which were left open
	while ( ListLen(openTags) ) {
		output = output &amp; &quot;&quot;;
		openTags = ListDeleteAt(openTags, ListLen(openTags));
	}

	if ( Len(input) GT Len(output) )
		output = output &amp; &quot;â€¦&quot;;
	
	return output;
}&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a ColdFusion version of this function. Thanks Steve! Love the regex solution. </p>
<p>Tested and working, but YMMV. Posted to CFLib.org but not up there yet.</p>
<pre class="code fixedHeight">function getLeadingHtml(input, maxChars) {
	// token matches a word, tag, or special character
	var	token = "[[:word:]]+|[^[:word:]< ]|(?:]*(\/)?>)|< ";
	var	selfClosingTag = "^(?:[hb]r|img)$";
	var	output = "";
	var	charCount = 0;
	var	openTags = ""; var strPos = 0; var tag = "";
	var i = 1;

	var	match = REFind(token, input, i, "true");

	while ( (charCount LT maxChars) AND match.pos[1] ) {
		// If this is an HTML tag
		if (match.pos[3]) {
			output = output &#038; Mid(input, match.pos[1], match.len[1]);
			tag = Mid(input, match.pos[3], match.len[3]);
			// If this is not a self-closing tag
			if ( NOT ( match.pos[4] OR REFindNoCase(selfClosingTag, tag) ) ) {
				// If this is a closing tag
				if ( match.pos[2] AND ListFindNoCase(openTags, tag) ) {
					openTags = ListDeleteAt(openTags, ListFindNoCase(openTags, tag));
				} else {
					openTags = ListAppend(openTags, tag);
				}
			}
		} else {
			charCount = charCount +  match.len[1];
			if (charCount LTE maxChars) output = output &#038; Mid(input, match.pos[1], match.len[1]);
		}

		i = i + match.len[1];
		match = REFind(token, input, i, "true");
	}

	// Close any tags which were left open
	while ( ListLen(openTags) ) {
		output = output &#038; "";
		openTags = ListDeleteAt(openTags, ListLen(openTags));
	}

	if ( Len(input) GT Len(output) )
		output = output &#038; "â€¦";

	return output;
}</pre>
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maxime</title>
		<link>http://blog.stevenlevithan.com/archives/get-html-summary/comment-page-1#comment-43931</link>
		<dc:creator>Maxime</dc:creator>
		<pubDate>Mon, 23 Nov 2009 17:05:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/archives/get-html-summary#comment-43931</guid>
		<description>silent, I had the same problem. The solution is simple : just add this line 

token.lastIndex = 0;

before the while statement.</description>
		<content:encoded><![CDATA[<p>silent, I had the same problem. The solution is simple : just add this line </p>
<p>token.lastIndex = 0;</p>
<p>before the while statement.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: silent</title>
		<link>http://blog.stevenlevithan.com/archives/get-html-summary/comment-page-1#comment-41790</link>
		<dc:creator>silent</dc:creator>
		<pubDate>Tue, 13 Oct 2009 21:26:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/archives/get-html-summary#comment-41790</guid>
		<description>It doesnt work in firefox... When i call function for the first time - is OK, but for second time - &quot;match[&#039;index&#039;]&quot; doesnt resets, just continue from index number from last function call. 
Any help?</description>
		<content:encoded><![CDATA[<p>It doesnt work in firefox&#8230; When i call function for the first time &#8211; is OK, but for second time &#8211; &#8220;match['index']&#8221; doesnt resets, just continue from index number from last function call.<br />
Any help?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

