Added support for Markdown - thanks to David Scotson!

This commit is contained in:
moodler 2004-07-30 04:02:58 +00:00
parent b035834fc5
commit e7cdcd1892
3 changed files with 1259 additions and 14 deletions

View File

@ -421,13 +421,14 @@ $string['forceno'] = 'Do not force';
$string['forgotten'] = 'Forgotten your username or password?';
$string['format'] = 'Format';
$string['formathtml'] = 'HTML format';
$string['formatmarkdown'] = 'Markdown format';
$string['formatplain'] = 'Plain text format';
$string['formatsocial'] = 'Social format';
$string['formattext'] = 'Moodle auto-format';
$string['formattexttype'] = 'Formatting';
$string['formattopics'] = 'Topics format';
$string['formatweeks'] = 'Weekly format';
$string['formatwiki'] = 'Wiki format';
$string['formatwiki'] = 'Wiki-like format';
$string['from'] = 'From';
$string['frontpagecategorynames'] = 'Show a list of categories';
$string['frontpagecourselist'] = 'Show a list of courses';
@ -496,7 +497,7 @@ $string['helpreading'] = 'Read carefully';
$string['helprichtext'] = 'About the HTML editor';
$string['helpsummaries'] = 'About these summaries';
$string['helptext'] = 'How to write text';
$string['helpwiki'] = 'How to write Wiki text';
$string['helpwiki'] = 'How to write Wiki-like text';
$string['helpwriting'] = 'Write carefully';
$string['hide'] = 'Hide';
$string['hiddensections'] = 'Hidden sections';
@ -719,7 +720,7 @@ $string['notifyloginfailuresmessagewithuser'] = ' with username ';
$string['notifyloginfailuresmessageend'] = 'You can view these logs at $a/course/log.php?id=1&chooselog=1&modid=site_errors.';
$string['numattempts'] = '$a failed login attempt(s) ';
$string['nothingnew'] = 'Nothing new since your last login';
$string['noticenewerbackup'] = 'This backup file has been created with Moodle $a->backuprelease ($a->backupversion) and it\'s newer than your currently installed Moodle $a->serverrelease ($a->serverversion). This could cause some inconsistencies because backwards compatibility of backup files cannot be guarantied.';
$string['noticenewerbackup'] = 'This backup file has been created with Moodle $a->backuprelease ($a->backupversion) and it\'s newer than your currently installed Moodle $a->serverrelease ($a->serverversion). This could cause some inconsistencies because backwards compatibility of backup files cannot be guaranteed.';
$string['notincluded'] = 'Not included';
$string['notingroup'] = 'Sorry, but you need to be part of a group to see this activity.';
$string['nousersmatching'] = 'No users matching \'$a\' were found';

1219
lib/markdown.php Executable file

File diff suppressed because it is too large Load Diff

View File

@ -32,10 +32,11 @@
/// Constants
/// Define text formatting types ... eventually we can add Wiki, BBcode etc
define("FORMAT_MOODLE", "0"); // Does all sorts of transformations and filtering
define("FORMAT_HTML", "1"); // Plain HTML (with some tags stripped)
define("FORMAT_PLAIN", "2"); // Plain text (even tags are printed in full)
define("FORMAT_WIKI", "3"); // Wiki-formatted text
define("FORMAT_MOODLE", "0"); // Does all sorts of transformations and filtering
define("FORMAT_HTML", "1"); // Plain HTML (with some tags stripped)
define("FORMAT_PLAIN", "2"); // Plain text (even tags are printed in full)
define("FORMAT_WIKI", "3"); // Wiki-formatted text
define("FORMAT_MARKDOWN", "4"); // Markdown-formatted text http://daringfireball.net/projects/markdown/
$ALLOWED_TAGS =
"<p><br><b><i><u><font><table><tbody><span><div><tr><td><th><ol><ul><dl><li><dt><dd><h1><h2><h3><h4><h5><h6><hr><img><a><strong><emphasis><em><sup><sub><address><cite><blockquote><pre><strike><embed><object><param><acronym><nolink><style><lang><tex><algebra><math><mi><mn><mo><mtext><mspace><ms><mrow><mfrac><msqrt><mroot><mstyle><merror><mpadded><mphantom><mfenced><msub><msup><msubsup><munder><mover><munderover><mmultiscripts><mtable><mtr><mtd><maligngroup><malignmark><maction><cn><ci><apply><reln><fn><interval><inverse><sep><condition><declare><lambda><compose><ident><quotient><exp><factorial><divide><max><min><minus><plus><power><rem><times><root><gcd><and><or><xor><not><implies><forall><exists><abs><conjugate><eq><neq><gt><lt><geq><leq><ln><log><int><diff><partialdiff><lowlimit><uplimit><bvar><degree><set><list><union><intersect><in><notin><subset><prsubset><notsubset><notprsubset><setdiff><sum><product><limit><tendsto><mean><sdev><variance><median><mode><moment><vector><matrix><matrixrow><determinant><transpose><selector><annotation><semantics><annotation-xml>";
@ -569,7 +570,8 @@ function format_text_menu() {
return array (FORMAT_MOODLE => get_string("formattext"),
FORMAT_HTML => get_string("formathtml"),
FORMAT_PLAIN => get_string("formatplain"),
FORMAT_WIKI => get_string("formatwiki"));
FORMAT_WIKI => get_string("formatwiki"),
FORMAT_MARKDOWN => get_string("formatmarkdown"));
}
function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL ) {
@ -616,6 +618,11 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL
$text = filter_text($text, $courseid);
break;
case FORMAT_MARKDOWN:
$text = markdown_to_html($text);
$text = filter_text($text, $courseid);
break;
default: // FORMAT_MOODLE or anything else
if (!isset($options->smiley)) {
$options->smiley=true;
@ -666,7 +673,9 @@ function format_text_email($text, $format) {
return html_to_text($text);
break;
default: // FORMAT_MOODLE or anything else
case FORMAT_MOODLE:
case FORMAT_MARKDOWN:
default:
$text = eregi_replace('(<a [^<]*href=["|\']?([^ "\']*)["|\']?[^>]*>([^<]*)</a>)','\\3 [\\2]', $text);
return strtr(strip_tags($text), array_flip(get_html_translation_table(HTML_ENTITIES)));
break;
@ -705,23 +714,30 @@ function clean_text($text, $format=FORMAT_MOODLE) {
global $ALLOWED_TAGS;
switch ($format) {
case FORMAT_MOODLE:
case FORMAT_HTML:
case FORMAT_WIKI:
case FORMAT_PLAIN:
return $text;
default:
/// Remove tags that are not allowed
$text = strip_tags($text, $ALLOWED_TAGS);
/// Munge javascript: label
$text = str_ireplace("javascript:", "Xjavascript:", $text);
$text = str_ireplace("vbscript:", "Xvbscript:", $text);
/// Remove script events
$text = eregi_replace("([^a-z])language([[:space:]]*)=", "\\1Xlanguage=", $text);
$text = eregi_replace("([^a-z])on([a-z]+)([[:space:]]*)=", "\\1Xon\\2=", $text);
return $text;
case FORMAT_PLAIN:
/// Remove Javascript entities
$text = eregi_replace("&{([^};]*)};", "\\1", $text);
return $text;
}
}
function replace_smilies(&$text) {
/// Replaces all known smileys in the text with image equivalents
global $CFG;
@ -834,6 +850,15 @@ function wiki_to_html($text) {
return $wiki->format($text);
}
function markdown_to_html($text) {
/// Given Markdown formatted text, make it into XHTML using external function
global $CFG;
require_once("$CFG->libdir/markdown.php");
return Markdown($text);
}
function html_to_text($html) {
/// Given HTML text, make it into plain text using external function
global $CFG;