Skip to content

Markdown conversion in PHP for user input (comments, etc).

License

Notifications You must be signed in to change notification settings

starekrow/safedown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Safedown

This converts text to HTML using a restricted subset of Markdown. No inline HTML is allowed at all. Links are supported but disabled by default. Safedown is designed to be safe to use with unrestricted user input.

Using Safedown

Instantiate and call text():

$sd = new Safedown();
echo $sd->text( "Safedown is *awesome*." );

Result:

<p>Safedown is <em>awesome</em>.</p>

Links

There is special handling for links found in the text. By default, both automatic and explicit links are mangled to prevent clicking on them (also to prevent crawlers from linking to every darn thing your users put in their text).

If you wish, you can allow some or all links to be rendered as anchor tags. Supply a filterLinks property in the options when you construct your Safedown instance, like so:

$sd = new Safedown( [
	"filterLinks" => function($l) { return true; }
] );

The function will receive an array with the following values:

  • url - URL to link to
  • text - text to draw for link (before conversion)
  • title - title to use for link (may be missing or null)
  • click - javascript to run when anchor is clicked (onclick text)

The function should return a modified array, OR false to perform the default action (mangle/deactivate the link) or true to allow the link to be used with no changes.

Differences from Markdown

The "trailing space" syntax for creating breaks in Markdown is not supported, nor is line continuation with a trailing \. These are both fine features for web developers, but they're terrible for users.

For extra line breaks, Safedown allows extra vertical space to be specified just by adding extra blank lines between paragraphs or blocks. There is currently no support for line continuation.

About

Markdown conversion in PHP for user input (comments, etc).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages