|
Cookbook /
MarkupToUnstyledSummary: Converts PmWiki markup into unstyled text
Version: 2009-03-01
Prerequisites: PmWiki2 (developed and tested with 2.2.0-stable)
Status: working
Maintainer: Tontyna
Categories: Markup
File: markuptounstyled.phpΔ
Questions answered by this recipeHow can I extract just the pure unstyled text from a given string containing PmWiki markup? Like MarkupToHTML does only without HTML tags. DescriptionDeveloping SlimTableOfContents and extending SectionEdit I was in need for a recipe that gives the - properly unformatted - text of the headings. I ended up with
SlimTableOfContents uses the text-only result as link text in the TOC and SectionEdit creates the edit link html title from it. Activation
Cookbooks SlimTableOfContents and SectionEdit (since v 2.2.1-2009-02-26) include this scrpt automatically.
include_once("$FarmD/cookbook/markuptounstyled.php");
UsageWhenever you need unstyled text-only call $unstyledtext = MarkupToUnstyled($pagename, $markuptext); The How it works
CustomizationThe array By default it holds the replace pattern for
SDV($MarkupToUnstyledIgnorePattern, array(
"(?>\\[\\[([^|\\]]+))\\|\\s*#\\s*\\]\\]", // [[target |#]] reference links
"(?>\\[\\[#([A-Za-z][-.:\\w]*))\\]\\]" // [[#anchor]]
));
Depending on the cookbooks / markups your Wiki uses you should extend the $MarkupToUnstyledIgnorePattern array - after including the script. E.g. if you have cookbook Footnotes installed you should add the following to your config.php: $MarkupToUnstyledIgnorePattern[] = '\\[\\^(.*?)\\^\\]'; Cookbook SectionEdit already adds the following pattern: $MarkupToUnstyledIgnorePattern[] = '\\(:sectionedit.*:\\)'; NotesThe default The recipe is required by cookbooks
Release Notes
See AlsoContributorsCommentsPatch to add a space character between joined linesSteP January 15, 2010, at 02:48 PM: Function MarkupToUnstyled leaves no space between lines when it joins them together. If you prefer adding a space character here is a patch that will do it. Tested on PmWiki 2.2.8.
// evaluate markup
$text = MarkupToHTML($pagename, $text);
//begin=add{
// replace <br /> and runs of newlines with a space
$text = preg_replace(':<br />|\\n+:s', ' ', $text);
//end-add}
//delete // remove newlines
//delete $text = preg_replace('/\\n/s', '', $text);
// remove html tags
$text = preg_replace('/<.*?>/s', '', $text);
Patch to suppress attached images and neuter intermapsSteP January 15, 2010, at 02:48 PM: By default function MarkupToUnstyledLinkSuppress replaces all links with their text, which basically leaves intermaps, such as
function MarkupToUnstyledLinkSuppress($pagename,$imap,$path,$title,$txt,$fmt=NULL)
{ return ($imap=='Attach:') ?'' :preg_replace("/^$imap/","",$txt); } //Step# delete Attach links and prevent intermap link expansion
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |