From 6076225c714bb0cde5a4862cccfdef52c68e67d4 Mon Sep 17 00:00:00 2001 From: mohrt Date: Mon, 16 Sep 2002 15:19:41 +0000 Subject: [PATCH] add textformat block function --- NEWS | 2 + docs/designers.sgml | 232 ++++++++++++++++++++++++++++++ libs/plugins/block.textformat.php | 71 +++++++++ plugins/block.textformat.php | 71 +++++++++ 4 files changed, 376 insertions(+) create mode 100644 libs/plugins/block.textformat.php create mode 100644 plugins/block.textformat.php diff --git a/NEWS b/NEWS index e65bfc74..a170af3f 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ + - added textformat block function (Monte) + Version 2.3.0 ------------- diff --git a/docs/designers.sgml b/docs/designers.sgml index fb304428..64a2b9e3 100644 --- a/docs/designers.sgml +++ b/docs/designers.sgml @@ -4295,6 +4295,238 @@ text="<UL><LI>links<LI>pages<LI>images</UL>" snapx OUTPUT: (See the Smarty official web site for working examples.) + + + + textformat + + + + + + + + + + Attribute Name + Type + Required + Default + Description + + + + + style + string + No + n/a + preset style + + + indent + number + No + 0 + The number of chars to indent every line + + + indent_first + number + No + 0 + The number of chars to indent the first line + + + indent_char + string + No + (single space) + The character (or string of chars) to indent with + + + wrap + number + No + 80 + How many characters to wrap each line to + + + wrap_char + string + No + \n + The character (or string of chars) to break each + line with + + + wrap_cut + boolean + No + false + If true, wrap will break the line at the exact + character instead of at a word boundary + + + assign + string + No + n/a + the template variable the output will be assigned + to + + + + + + textformat is a block function used to format text. It basically + cleans up spaces and special characters, and formats paragraphs by + wrapping at a boundary and indenting lines. + + + You can set the parameters explicitly, or use a preset style. + Currently "email" is the only available style. + + +textformat + +{textformat wrap=40} + +This is foo. +This is foo. +This is foo. +This is foo. +This is foo. +This is foo. + +This is bar. + +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. + +{/textformat} + +OUTPUT: + +This is foo. This is foo. This is foo. +This is foo. This is foo. This is foo. + +This is bar. + +bar foo bar foo foo. bar foo bar foo +foo. bar foo bar foo foo. bar foo bar +foo foo. bar foo bar foo foo. bar foo +bar foo foo. bar foo bar foo foo. + + +{textformat wrap=40 indent=4} + +This is foo. +This is foo. +This is foo. +This is foo. +This is foo. +This is foo. + +This is bar. + +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. + +{/textformat} + +OUTPUT: + + This is foo. This is foo. This is + foo. This is foo. This is foo. This + is foo. + + This is bar. + + bar foo bar foo foo. bar foo bar foo + foo. bar foo bar foo foo. bar foo + bar foo foo. bar foo bar foo foo. + bar foo bar foo foo. bar foo bar + foo foo. + +{textformat wrap=40 indent=4 indent_first=4} + +This is foo. +This is foo. +This is foo. +This is foo. +This is foo. +This is foo. + +This is bar. + +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. + +{/textformat} + +OUTPUT: + + This is foo. This is foo. This + is foo. This is foo. This is foo. + This is foo. + + This is bar. + + bar foo bar foo foo. bar foo bar + foo foo. bar foo bar foo foo. bar + foo bar foo foo. bar foo bar foo + foo. bar foo bar foo foo. bar foo + bar foo foo. + +{textformat style="email"} + +This is foo. +This is foo. +This is foo. +This is foo. +This is foo. +This is foo. + +This is bar. + +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. +bar foo bar foo foo. + +{/textformat} + +OUTPUT: + +This is foo. This is foo. This is foo. This is foo. This is foo. This is +foo. + +This is bar. + +bar foo bar foo foo. bar foo bar foo foo. bar foo bar foo foo. bar foo +bar foo foo. bar foo bar foo foo. bar foo bar foo foo. bar foo bar foo +foo. + + diff --git a/libs/plugins/block.textformat.php b/libs/plugins/block.textformat.php new file mode 100644 index 00000000..eab2b7d9 --- /dev/null +++ b/libs/plugins/block.textformat.php @@ -0,0 +1,71 @@ + 0) { + $paragraph = str_repeat($indent_char,$indent_first) . $paragraph; + } + // wordwrap sentences + $paragraph = wordwrap($paragraph, $wrap - $indent, $wrap_char, $wrap_cut); + // indent lines + if($indent > 0) { + $paragraph = preg_replace('!^!m',str_repeat($indent_char,$indent),$paragraph); + } + $output .= $paragraph . $wrap_char . $wrap_char; + } + + if($assign != null) { + $this->assign($assign,$output); + } else { + echo $output; + } + //echo $content; +} + +/* vim: set expandtab: */ + +?> diff --git a/plugins/block.textformat.php b/plugins/block.textformat.php new file mode 100644 index 00000000..eab2b7d9 --- /dev/null +++ b/plugins/block.textformat.php @@ -0,0 +1,71 @@ + 0) { + $paragraph = str_repeat($indent_char,$indent_first) . $paragraph; + } + // wordwrap sentences + $paragraph = wordwrap($paragraph, $wrap - $indent, $wrap_char, $wrap_cut); + // indent lines + if($indent > 0) { + $paragraph = preg_replace('!^!m',str_repeat($indent_char,$indent),$paragraph); + } + $output .= $paragraph . $wrap_char . $wrap_char; + } + + if($assign != null) { + $this->assign($assign,$output); + } else { + echo $output; + } + //echo $content; +} + +/* vim: set expandtab: */ + +?>