Skip to content

Commit

Permalink
MDL-32114 form: markdown must be preserved on saving post
Browse files Browse the repository at this point in the history
- Markdown is saved to the DB, no conversion to HTML to keep
  ability to reedit the content without beaking it.
- Blockquote element is styled that it's distingishable from
  normal text.
  • Loading branch information
srobotta committed Jan 5, 2023
1 parent b8b905c commit 4a31dd6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
5 changes: 2 additions & 3 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1337,9 +1337,8 @@ function format_text($text, $format = FORMAT_MOODLE, $options = null, $courseidd

case FORMAT_MARKDOWN:
$text = markdown_to_html($text);
if (!$options['noclean']) {
$text = clean_text($text, FORMAT_HTML, $options);
}
// The markdown parser does not strip dangerous html so we need to clean it, even if noclean is set to true.
$text = clean_text($text, FORMAT_HTML, $options);
$text = $filtermanager->filter_text($text, $context, $filteroptions);
break;

Expand Down
12 changes: 8 additions & 4 deletions mod/forum/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,10 @@
$canreplyprivately = forum_user_can_reply_privately($modcontext, $parent);
}

$post = trusttext_pre_edit($post, 'message', $modcontext);
// If markdown is used, the parser does the job already, otherwise clean text from arbitrary code that might be dangerous.
if ($post->messageformat != FORMAT_MARKDOWN) {
$post = trusttext_pre_edit($post, 'message', $modcontext);
}

// Unsetting this will allow the correct return URL to be calculated later.
unset($SESSION->fromdiscussion);
Expand Down Expand Up @@ -796,9 +799,10 @@
// WARNING: the $fromform->message array has been overwritten, do not use it anymore!
$fromform->messagetrust = trusttext_trusted($modcontext);

// Clean message text.
$fromform = trusttext_pre_edit($fromform, 'message', $modcontext);

// Clean message text, unless markdown which should be saved as it is, otherwise editing messes things up.
if ($fromform->messageformat != FORMAT_MARKDOWN) {
$fromform = trusttext_pre_edit($fromform, 'message', $modcontext);
}
if ($fromform->edit) {
// Updating a post.
unset($fromform->groupid);
Expand Down
7 changes: 7 additions & 0 deletions theme/boost/scss/moodle/core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3023,3 +3023,10 @@ body.dragging {
}
}
}

blockquote {
margin: 0 0.5rem 1rem;
padding-left: 1rem;
color: $gray-700;
border-left: 5px solid $gray-400;
}
6 changes: 6 additions & 0 deletions theme/boost/style/moodle.css
Original file line number Diff line number Diff line change
Expand Up @@ -12321,6 +12321,12 @@ body.dragging .dragging {
border-top-right-radius: 0.2rem;
border-bottom-right-radius: 0.2rem; }

blockquote {
margin: 0 0.5rem 1rem;
padding-left: 1rem;
color: #495057;
border-left: 5px solid #ced4da; }

.icon {
font-size: 16px;
width: 16px;
Expand Down
6 changes: 6 additions & 0 deletions theme/classic/style/moodle.css
Original file line number Diff line number Diff line change
Expand Up @@ -12321,6 +12321,12 @@ body.dragging .dragging {
border-top-right-radius: 0.2rem;
border-bottom-right-radius: 0.2rem; }

blockquote {
margin: 0 0.5rem 1rem;
padding-left: 1rem;
color: #495057;
border-left: 5px solid #ced4da; }

.icon {
font-size: 16px;
width: 16px;
Expand Down

0 comments on commit 4a31dd6

Please sign in to comment.