summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes1
-rw-r--r--HISTORY2
-rw-r--r--demos/quickstart/protected/comments/CommentList.tpl20
-rw-r--r--framework/Web/UI/WebControls/TMarkdown.php90
-rw-r--r--framework/Web/UI/WebControls/TTextHighlighter.php61
-rw-r--r--framework/Web/UI/WebControls/TTextProcessor.php87
6 files changed, 148 insertions, 113 deletions
diff --git a/.gitattributes b/.gitattributes
index faaafecf..444a4e1f 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -968,6 +968,7 @@ framework/Web/UI/WebControls/TTableRow.php -text
framework/Web/UI/WebControls/TTemplateColumn.php -text
framework/Web/UI/WebControls/TTextBox.php -text
framework/Web/UI/WebControls/TTextHighlighter.php -text
+framework/Web/UI/WebControls/TTextProcessor.php -text
framework/Web/UI/WebControls/TValidationSummary.php -text
framework/Web/UI/WebControls/TWebControl.php -text
framework/Web/UI/WebControls/TWebControlAdapter.php -text
diff --git a/HISTORY b/HISTORY
index 43f11657..030aaac3 100644
--- a/HISTORY
+++ b/HISTORY
@@ -27,6 +27,8 @@ CHG: Ticket#151 - URL format is modified to handle empty GET values (Qiang)
CHG: Ticket#153 - TAssetManager now ignores .svn directories (Qiang)
NEW: TTableHeaderRow, TTableFooterRow and table section support (Qiang)
NEW: TCompositeControl (Qiang)
+NEW: TTextProcessor (Qiang)
+NEW: TMarkdown (Wei)
NEW: Blog demo (Qiang)
Version 3.0.0 May 1, 2006
diff --git a/demos/quickstart/protected/comments/CommentList.tpl b/demos/quickstart/protected/comments/CommentList.tpl
index 0aeb2c81..ef74316a 100644
--- a/demos/quickstart/protected/comments/CommentList.tpl
+++ b/demos/quickstart/protected/comments/CommentList.tpl
@@ -2,7 +2,7 @@
<com:TRepeater ID="comments">
<prop:HeaderTemplate>
- <h2 class="comment_header">Comments
+ <h2 class="comment_header">Comments
<span style="font-size:0.8em">( <a href="#add_comments">Add your comments</a> )</span></h2>
</prop:HeaderTemplate>
<prop:ItemTemplate>
@@ -16,7 +16,7 @@
</span>
<div class="comment">
<com:TSafeHtml>
- <com:TMarkdown TextHighlighter.CssClass="source">
+ <com:TMarkdown CssClass="source">
<%# $this->DataItem['comment'] %>
</com:TMarkdown>
</com:TSafeHtml>
@@ -29,13 +29,13 @@
<com:TView ID="view1">
<div id="add_comments" class="add_comments">
<h3>Post a comment</h3>
- <p><strong>Note:</strong>
+ <p><strong>Note:</strong>
Please only use the comments in relation to this page for
- <ul>
+ <ul>
<li>questions/critcisms/suggestions on the documentation,</li>
<li>small notes that can solve or clarify a particular problem or task.</li>
</ul>
- If you experience errors please <a href="http://trac.pradosoft.com/newticket">file a ticket</a>
+ If you experience errors please <a href="http://trac.pradosoft.com/newticket">file a ticket</a>
or <a href="http://www.pradosoft.com/forum/">ask at the forum</a>.
Please use the <a href="http://pradosoft.com/wiki/index.php/Main_Page">Prado wiki</a> for longer pieces and detailed solutions</a>.
</p>
@@ -49,8 +49,8 @@
ControlToValidate="email"
Display="Dynamic"
ErrorMessage="An email address is required." />
- <com:TEmailAddressValidator
- ControlToValidate="email"
+ <com:TEmailAddressValidator
+ ControlToValidate="email"
CheckMXRecord="false"
Display="Dynamic"
ErrorMessage="Please provide your email address."/>
@@ -70,13 +70,13 @@
<h3 style="margin:0">Preview comment</h3>
<div class="comment">
<com:TSafeHtml>
- <com:TMarkdown TextHighlighter.CssClass="source">
+ <com:TMarkdown CssClass="source">
<%= $this->content->Text %>
</com:TMarkdown>
</com:TSafeHtml>
</div>
</div>
- </com:TPlaceHolder>
+ </com:TPlaceHolder>
<div class="add_comment">
<com:TButton ID="previewComment" Text="Preview Comment" />
<com:TButton ID="addComment" Text="Add Comment" OnClick="addComment_Clicked"/>
@@ -90,7 +90,7 @@
<h3 style="margin:0">Preview comment</h3>
<div class="comment">
<com:TSafeHtml>
- <com:TMarkdown TextHighlighter.CssClass="source">
+ <com:TMarkdown CssClass="source">
<%= $this->content->Text %>
</com:TMarkdown>
</com:TSafeHtml>
diff --git a/framework/Web/UI/WebControls/TMarkdown.php b/framework/Web/UI/WebControls/TMarkdown.php
index 49660b4e..740653a5 100644
--- a/framework/Web/UI/WebControls/TMarkdown.php
+++ b/framework/Web/UI/WebControls/TMarkdown.php
@@ -11,12 +11,18 @@
*/
/**
+ * Using TTextHighlighter and MarkdownParser classes
+ */
+Prado::using('System.Web.UI.WebControls.TTextHighlighter');
+Prado::using('System.3rdParty.Markdown.MarkdownParser');
+
+/**
* TMarkdown class
*
* TMarkdown is a control that produces HTML from code with markdown syntax.
*
- * Markdown is a text-to-HTML conversion tool for web writers. Markdown allows
- * you to write using an easy-to-read, easy-to-write plain text format, then
+ * Markdown is a text-to-HTML conversion tool for web writers. Markdown allows
+ * you to write using an easy-to-read, easy-to-write plain text format, then
* convert it to structurally valid XHTML (or HTML).
* Further documentation regarding Markdown can be found at
* http://daringfireball.net/projects/markdown/
@@ -27,86 +33,48 @@
* See http://www.pradosoft.com/demos/quickstart/?page=Markdown for
* details on the Markdown syntax usage.
*
+ * TMarkdown also performs syntax highlighting for code blocks whose language
+ * is recognized by {@link TTextHighlighter}.
+ * The language of a code block must be specified in the first line of the block
+ * and enclosed within a pair of square brackets (e.g. [php]).
+ *
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
- * @since 3.0
+ * @since 3.0.1
*/
-class TMarkdown extends TControl
+class TMarkdown extends TTextHighlighter
{
/**
- * @var TTextHighlighter
+ * Processes a text string.
+ * This method is required by the parent class.
+ * @param string text string to be processed
+ * @return string the processed text result
*/
- private $_highlighter;
-
- /**
- * Renders body content.
- * This method overrides parent implementation by removing
- * malicious javascript code from the body content
- * @param THtmlWriter writer
- */
- public function render($writer)
+ public function processText($text)
{
- $textWriter=new TTextWriter;
- parent::render(new THtmlWriter($textWriter));
- $writer->write($this->renderMarkdown($textWriter->flush()));
- }
-
- /**
- * Use MarkdownParser to render the HTML content.
- * @param string markdown content
- * @return string HTML content
- */
- protected function renderMarkdown($text)
- {
- $renderer = Prado::createComponent('System.3rdParty.Markdown.MarkdownParser');
+ $renderer = new MarkdownParser;
$result = $renderer->parse($text);
return preg_replace_callback(
- '/<pre><code>\[\s*(\w+)\s*\]\n+((.|\n)*?)\s*<\\/code><\\/pre>/im',
+ '/<pre><code>\[\s*(\w+)\s*\]\n+((.|\n)*?)\s*<\\/code><\\/pre>/im',
array($this, 'highlightCode'), $result);
}
/**
- * @return TTextHighlighter source code highlighter
- */
- public function getTextHighlighter()
- {
- if(is_null($this->_highlighter))
- $this->_highlighter = new TTextHighlighter;
- return $this->_highlighter;
- }
-
-
- /**
* Highlights source code using TTextHighlighter
* @param array matches of code blocks
* @return string highlighted code.
*/
protected function highlightCode($matches)
{
- $text = new TTextWriter;
- $writer = new THtmlWriter($text);
- $hi = $this->getTextHighlighter();
- if($hi->getControls()->getCount() > 0)
- $hi->getControls()->removeAt(0);
- $hi->addParsedObject(html_entity_decode($matches[2]));
- $hi->setLanguage($matches[1]);
- $hi->render($writer);
- return $text->flush();
- }
+ $geshi=new GeSHi(html_entity_decode($matches[2],ENT_QUOTES,'UTF-8'), $matches[1]);
+ if($this->getShowLineNumbers())
+ $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
+ $geshi->enable_classes();
+ if($this->getEnableCopyCode())
+ $geshi->set_header_content($this->getHeaderTemplate());
- /**
- * Registers css style for the highlighted result.
- * This method overrides parent implementation.
- * @param THtmlWriter writer
- */
- public function onPreRender($writer)
- {
- parent::onPreRender($writer);
- $hi = $this->getTextHighlighter();
- $this->getControls()->insertAt(0,$hi);
- $hi->onPreRender($writer);
- $this->getControls()->removeAt(0);
+ return $geshi->parse_code();
}
}
diff --git a/framework/Web/UI/WebControls/TTextHighlighter.php b/framework/Web/UI/WebControls/TTextHighlighter.php
index f5c3eca9..a9ccf5bb 100644
--- a/framework/Web/UI/WebControls/TTextHighlighter.php
+++ b/framework/Web/UI/WebControls/TTextHighlighter.php
@@ -11,9 +11,10 @@
*/
/**
- * Using GeSHi and TTextWriter classes
+ * Using GeSHi and TTextProcessor classes
*/
Prado::using('System.3rdParty.geshi.geshi');
+Prado::using('System.Web.UI.WebControls.TTextProcessor');
/**
* TTextHighlighter class.
@@ -31,7 +32,7 @@ Prado::using('System.3rdParty.geshi.geshi');
* @package System.Web.UI.WebControls
* @since 3.0
*/
-class TTextHighlighter extends TWebControl
+class TTextHighlighter extends TTextProcessor
{
/**
* @return string tag name of the panel
@@ -77,39 +78,30 @@ class TTextHighlighter extends TWebControl
}
/**
- * Registers css style for the highlighted result.
- * This method overrides parent implementation.
- * @param THtmlWriter writer
+ * @return boolean true will show "Copy Code" link. Defaults to false.
*/
- public function onPreRender($writer)
+ public function getEnableCopyCode()
{
- parent::onPreRender($writer);
- $this->registerHighlightScripts();
+ return $this->getViewState('CopyCode', false);
}
/**
- * HTML-decodes static text.
- * This method overrides parent implementation.
- * @param mixed object to be added as body content
+ * @param boolean true to show the "Copy Code" link.
*/
- public function addParsedObject($object)
+ public function setEnableCopyCode($value)
{
- if(is_string($object))
- $object=html_entity_decode($object);
- parent::addParsedObject($object);
+ $this->setViewState('CopyCode', TPropertyValue::ensureBoolean($value), false);
}
/**
- * Renders body content.
- * This method overrides parent implementation by replacing
- * the body content with syntax highlighted result.
+ * Registers css style for the highlighted result.
+ * This method overrides parent implementation.
* @param THtmlWriter writer
*/
- public function renderContents($writer)
+ public function onPreRender($writer)
{
- $textWriter=new TTextWriter;
- parent::renderContents(new THtmlWriter($textWriter));
- $writer->write($this->highlightText($textWriter->flush()));
+ parent::onPreRender($writer);
+ $this->registerHighlightScripts();
}
/**
@@ -131,27 +123,12 @@ class TTextHighlighter extends TWebControl
}
/**
- * @return boolean true will show "Copy Code" link. Defaults to false.
- */
- public function getEnableCopyCode()
- {
- return $this->getViewState('CopyCode', false);
- }
-
- /**
- * @param boolean true to show the "Copy Code" link.
- */
- public function setEnableCopyCode($value)
- {
- $this->setViewState('CopyCode', TPropertyValue::ensureBoolean($value), false);
- }
-
- /**
- * Returns the highlighted text.
- * @param string text to highlight.
- * @return string highlighted text.
+ * Processes a text string.
+ * This method is required by the parent class.
+ * @param string text string to be processed
+ * @return string the processed text result
*/
- protected function highlightText($text)
+ public function processText($text)
{
$geshi = new GeSHi(trim($text), $this->getLanguage());
if($this->getShowLineNumbers())
diff --git a/framework/Web/UI/WebControls/TTextProcessor.php b/framework/Web/UI/WebControls/TTextProcessor.php
new file mode 100644
index 00000000..4c4c68f2
--- /dev/null
+++ b/framework/Web/UI/WebControls/TTextProcessor.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * TTextProcessor class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 Wei Zhuo
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TTextProcessor class.
+ *
+ * TTextProcessor is the base class for classes that process or transform
+ * text content into different forms. The text content to be processed
+ * is specified by {@link setText Text} property. If it is not set, the body
+ * content enclosed within the processor control will be processed and rendered.
+ * The body content includes static text strings and the rendering result
+ * of child controls.
+ *
+ * Note, all child classes must implement {@link processText} method.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI
+ * @since 3.0.1
+ */
+abstract class TTextProcessor extends TWebControl
+{
+ /**
+ * Processes a text string.
+ * This method must be implemented by child classes.
+ * @param string text string to be processed
+ * @return string the processed text result
+ */
+ abstract public function processText($text);
+
+ /**
+ * HTML-decodes static text.
+ * This method overrides parent implementation.
+ * @param mixed object to be added as body content
+ */
+ public function addParsedObject($object)
+ {
+ if(is_string($object))
+ $object=html_entity_decode($object,ENT_QUOTES,'UTF-8');
+ parent::addParsedObject($object);
+ }
+
+ /**
+ * @return string text to be processed
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * @param string text to be processed
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value);
+ }
+
+ /**
+ * Renders body content.
+ * This method overrides the parent implementation by replacing
+ * the body content with the processed text content.
+ * @param THtmlWriter writer
+ */
+ public function renderContents($writer)
+ {
+ if(($text=$this->getText())==='' && $this->getHasControls())
+ {
+ $textWriter=new TTextWriter;
+ parent::renderContents(new THtmlWriter($textWriter));
+ $text=$textWriter->flush();
+ }
+ if($text!=='')
+ $writer->write($this->processText($text));
+ }
+
+}
+?> \ No newline at end of file