Skip to content

Commit

Permalink
Clean up markdown processing
Browse files Browse the repository at this point in the history
- Process input via Markdownparser and return the result, no further
  text processing.
- During parsing, catch all <code> blocks and replace them with a hash
  value.
- After the markup is returned from Parsedown, apply mentions and links
- Restore the untouched <code> Blocks back in place.

Fixes #34040, PR #1976
Also fixes #22315, #22320, #24241, #24628, #24810, #22231, #23738

Signed-off-by: Damien Regad <dregad@mantisbt.org>
  • Loading branch information
grummbeer authored and dregad committed Apr 2, 2024
1 parent 6ddc26b commit 3aec6e6
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 160 deletions.
38 changes: 16 additions & 22 deletions plugins/MantisCoreFormatting/MantisCoreFormatting.php
Expand Up @@ -89,10 +89,10 @@ function config() {
*
* @return string valid formatted text
*/
private function processText( $p_string, $p_multiline = true ){

private function processText( $p_string, $p_multiline = true ) {
$t_string = string_strip_hrefs( $p_string );
$t_string = string_html_specialchars( $t_string );

return string_restore_valid_html_tags( $t_string, $p_multiline );
}

Expand All @@ -102,9 +102,9 @@ private function processText( $p_string, $p_multiline = true ){
*
* @return string Formatted text
*/
private function processBugAndNoteLinks( $p_string ){

private function processBugAndNoteLinks( $p_string ) {
$t_string = string_process_bug_link( $p_string );

return string_process_bugnote_link( $t_string );
}

Expand Down Expand Up @@ -158,10 +158,6 @@ function formatted( $p_event, $p_string, $p_multiline = true ) {

$t_string = $p_string;

if( null === $s_text ) {
$s_text = plugin_config_get( 'process_text' );
}

if( null === $s_urls ) {
$s_urls = plugin_config_get( 'process_urls' );
$s_buglinks = plugin_config_get( 'process_buglinks' );
Expand All @@ -171,35 +167,33 @@ function formatted( $p_event, $p_string, $p_multiline = true ) {
$s_markdown = plugin_config_get( 'process_markdown' );
}

# Parse input and return finished HTML markup, no further processing.
if( ON == $s_markdown ) {
return MantisMarkdown::getInstance( $s_urls, $s_buglinks )->convert( $t_string, $p_multiline );
}

if( null === $s_text ) {
$s_text = plugin_config_get( 'process_text' );
}

if( ON == $s_text ) {
$t_string = $this->processText( $t_string );

if( $p_multiline && OFF == $s_markdown ) {
if( $p_multiline ) {
$t_string = string_preserve_spaces_at_bol( $t_string );
$t_string = string_nl2br( $t_string );
}
}

# Process Markdown
if( ON == $s_markdown ) {
if( $p_multiline ) {
$t_string = MantisMarkdown::convert_text( $t_string );
} else {
$t_string = MantisMarkdown::convert_line( $t_string );
}
}

if( ON == $s_urls && OFF == $s_markdown ) {
if( ON == $s_urls ) {
$t_string = string_insert_hrefs( $t_string );
}

if ( ON == $s_buglinks ) {
$t_string = $this->processBugAndNoteLinks( $t_string );
}

$t_string = mention_format_text( $t_string, /* html */ true );

return $t_string;
return mention_format_text( $t_string, /* html */ true );
}

/**
Expand Down

0 comments on commit 3aec6e6

Please sign in to comment.