Skip to content

Commit

Permalink
Markdown plugin
Browse files Browse the repository at this point in the history
Added initial stand-alone plugin for markdown, moved all dependencies
to the plugin folder.

- revert CoreFormatting back to its original state, as well as other,
  unneeded previous changes
- disable all processing in MantisCoreFormatting if enabled
- turn MantisCoreFormatting back on if Markdown is uninstalled
- hook EVENT_CORE_HEADERS to enable images referenced from the internet
  • Loading branch information
jllano authored and vboctor committed Jan 11, 2017
1 parent dfd1256 commit 45f3582
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -26,6 +26,7 @@ plugins/*
!plugins/MantisGraph
!plugins/XmlImportExport
!plugins/Gravatar
!plugins/MantisMarkdown

# IDE/Editor temporary files
*~
Expand Down
10 changes: 0 additions & 10 deletions config_defaults_inc.php
Expand Up @@ -1208,16 +1208,6 @@
*/
$g_private_news_threshold = DEVELOPER;

############
# Markdown #
############

/**
* Enables markdown support - once enabled all issue titles, text, and notes are formatted based on
* markdown syntax. Default to OFF since it is experimental feature for now.
*/
$g_markdown_enabled = OFF;

################################
# MantisBT Default Preferences #
################################
Expand Down
7 changes: 1 addition & 6 deletions core.php
Expand Up @@ -274,11 +274,6 @@ function __autoload( $p_class ) {

# Set HTTP response headers
require_api( 'http_api.php' );

if( MantisMarkdown::enabled() ) { # if markdown enabled, then images can be referenced from internet.
http_csp_add( 'img-src', "*" );
}

event_signal( 'EVENT_CORE_HEADERS' );
http_all_headers();

Expand All @@ -292,4 +287,4 @@ function __autoload( $p_class ) {
if( !defined( 'PLUGINS_DISABLED' ) && !defined( 'MANTIS_MAINTENANCE_MODE' ) ) {
require_api( 'event_api.php' );
event_signal( 'EVENT_CORE_READY' );
}
}
9 changes: 0 additions & 9 deletions docbook/Admin_Guide/en-US/config/display.xml
Expand Up @@ -194,14 +194,5 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_markdown_enabled</term>
<listitem>
<para>
Enables markdown support - once enabled all issue titles, text, and notes are formatted based on
markdown syntax. Default to OFF since it is experimental feature for now.
</para>
</listitem>
</varlistentry>
</variablelist>
</section>
38 changes: 13 additions & 25 deletions plugins/MantisCoreFormatting/MantisCoreFormatting.php
Expand Up @@ -78,21 +78,13 @@ function text( $p_event, $p_string, $p_multiline = true ) {
}

if( ON == $s_text ) {
if ( MantisMarkdown::enabled() ) {
if ( $p_multiline ) {
$t_string = MantisMarkdown::convert_text( $t_string );
} else {
$t_string = MantisMarkdown::convert_line( $t_string );
}
} else {
$t_string = string_strip_hrefs( $t_string );
$t_string = string_html_specialchars( $t_string );
$t_string = string_restore_valid_html_tags( $t_string, $p_multiline );

if( $p_multiline ) {
$t_string = string_preserve_spaces_at_bol( $t_string );
$t_string = string_nl2br( $t_string );
}
$t_string = string_strip_hrefs( $t_string );
$t_string = string_html_specialchars( $t_string );
$t_string = string_restore_valid_html_tags( $t_string, $p_multiline );

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

Expand Down Expand Up @@ -123,7 +115,7 @@ function formatted( $p_event, $p_string, $p_multiline = true ) {
$s_buglinks = plugin_config_get( 'process_buglinks' );
}

if( ON == $s_urls && !MantisMarkdown::enabled() ) {
if( ON == $s_urls ) {
$t_string = string_insert_hrefs( $t_string );
}

Expand Down Expand Up @@ -155,14 +147,10 @@ function rss( $p_event, $p_string ) {
}

if( ON == $s_text ) {
if ( MantisMarkdown::enabled() ) {
$t_string = MantisMarkdown::convert_text( $t_string );
} else {
$t_string = string_strip_hrefs( $t_string );
$t_string = string_html_specialchars( $t_string );
$t_string = string_restore_valid_html_tags( $t_string );
$t_string = string_nl2br( $t_string );
}
$t_string = string_strip_hrefs( $t_string );
$t_string = string_html_specialchars( $t_string );
$t_string = string_restore_valid_html_tags( $t_string );
$t_string = string_nl2br( $t_string );
}

if( ON == $s_urls ) {
Expand Down Expand Up @@ -208,4 +196,4 @@ function email( $p_event, $p_string ) {

return $t_string;
}
}
}
128 changes: 128 additions & 0 deletions plugins/MantisMarkdown/MantisMarkdown.php
@@ -0,0 +1,128 @@
<?php
/**
* MantisBT - A PHP based bugtracking system
*
* MantisBT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MantisBT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net
*/

require_api( 'mention_api.php' );
require_once( 'core/MantisMarkdown.php' );

/**
* Mantis Markdown Plugin
*/
class MantisMarkdownPlugin extends MantisPlugin {

/**
* Initialized any needed methods, api's, etc...
*
* Make sure to turn Text Processing off, causing markdown to not render properly
* @return void
*/
function init() {

if ( ON == config_get( 'plugin_MantisCoreFormatting_process_text' ) ) {
config_set( 'plugin_MantisCoreFormatting_process_text', OFF );
}

if ( ON == config_get( 'plugin_MantisCoreFormatting_process_urls' ) ) {
config_set( 'plugin_MantisCoreFormatting_process_urls', OFF );
}

if ( ON == config_get( 'plugin_MantisCoreFormatting_process_buglinks' ) ) {
config_set( 'plugin_MantisCoreFormatting_process_buglinks', OFF );
}

}

/**
* Make sure to turn Text Processing back on uninstall
* reset it back to MantisCoreFormatting position
*/
function uninstall() {
config_set( 'plugin_MantisCoreFormatting_process_text', ON );
config_set( 'plugin_MantisCoreFormatting_process_urls', ON );
config_set( 'plugin_MantisCoreFormatting_process_buglinks', ON );
}

/**
* A method that populates the plugin information and minimum requirements.
* @return void
*/
function register() {
$this->name = lang_get( 'plugin_markdown_title' );
$this->description = lang_get( 'plugin_markdown_description' );

$this->version = MANTIS_VERSION;
$this->requires = array(
'MantisCore' => '2.0.0',
);

$this->author = 'MantisBT Team';
$this->contact = 'mantisbt-dev@lists.sourceforge.net';
$this->url = 'http://www.mantisbt.org';
}

/**
* Event hook declaration.
* @return array
*/
function hooks() {
return array(
'EVENT_DISPLAY_FORMATTED' => 'markdown', # Formatted String Display
'EVENT_CORE_HEADERS' => 'csp_headers'
);
}

/**
* Add img-src directives to enable to referenced images from internet.
* @return void
*/
function csp_headers() {
http_csp_add( 'img-src', "*" );
}

/**
* Markdown processing.
*
* Performs markdown and bug links processing
*
* @param string $p_event Event name.
* @param string $p_string Raw text to process.
* @param boolean $p_multiline True for multiline text (default), false for single-line.
*
* @return string The html text
*/
function markdown( $p_event, $p_string, $p_multiline = true ) {

$t_string = $p_string;

# Process bug links
$t_string = string_process_bug_link( $t_string );
$t_string = string_process_bugnote_link( $t_string );

$t_string = mention_format_text( $t_string, true );

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

return $t_string;
}
}
Expand Up @@ -29,14 +29,14 @@
* To meet and match the MantisBT styles and logic requirements, we have to override and control with it
* For example: #2 is treated as header markdown
* So, to make sure #2 treated as bug link (not a header), then we have to change the logic in blockHeader and blockSetextHeader method
*
*
* @package MantisBT
* @subpackage parsedown
*
* @uses Parsedown Library
*/

require_once( dirname( dirname( __FILE__ ) ) . '../../library/parsedown/Parsedown.php' );
require_once( dirname( dirname( __FILE__ ) ) . '/library/Parsedown.php' );

/**
* A class that overrides default Markdown parsing for Mantis specific scenarios.
Expand Down Expand Up @@ -69,15 +69,6 @@ public function __construct() {
$this->inline_style = 'border-color:#847d7d';
}

/**
* Check if markdown is enabled.
*
* @return bool true for enabled, false otherwise.
*/
public static function enabled() {
return config_get( 'markdown_enabled' ) != OFF;
}

/**
* Convert a field that supports multiple lines form markdown to html.
* @param string $p_text The text to convert.
Expand Down Expand Up @@ -151,7 +142,7 @@ protected function blockSetextHeader( $line, array $block = null ) {

/**
* Add a class attribute on a table markdown elements
*
*
* @param string $line The Markdown syntax to parse
* @param array $block A block-level element
* @param string $fn the function name to call (blockTable or blockTableContinue)
Expand Down Expand Up @@ -192,7 +183,7 @@ protected function blockTableContinue( $line, array $block ) {

/**
* Add an inline style on a blockquote markdown elements
*
*
* @param string $line The Markdown syntax to parse
* @param array $block A block-level element
* @param string $fn the function name to call (blockQuote or blockQuoteContinue)
Expand Down Expand Up @@ -241,4 +232,4 @@ private static function init() {
}
return static::$mantis_markdown;
}
}
}
45 changes: 45 additions & 0 deletions plugins/MantisMarkdown/lang/strings_english.txt
@@ -0,0 +1,45 @@
<?php
# MantisBT - A PHP based bugtracking system

# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.

/**
* Language File - English (English)
*
* **********************************************************************
* ** This file is generated from translations stored in translatewiki **
* ** Information on Copyright/License for translatewiki translations **
* ** is available at http://translatewiki.net/wiki/Project:About **
* **********************************************************************
* ** **
* ** DO NOT UPDATE MANUALLY **
* ** **
* ** To improve a translation please visit http://translatewiki.net **
* ** Detailed instructions on how to create or update translations at **
* ** http://www.mantisbt.org/wiki/doku.php/mantisbt:translationshowto **
* **********************************************************************
*
* See the qqq 'language' for message documentation incl. usage of parameters
*
* @ingroup Language
* @file
* @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*
*/

$s_plugin_markdown_title = 'MantisBT Markdown';
$s_plugin_markdown_description = 'Official Markdown plugin.';


File renamed without changes.
File renamed without changes.
Expand Up @@ -24,7 +24,8 @@
*/

# Includes
require_once dirname( dirname( __FILE__ ) ) . '/TestConfig.php';
require_once( dirname( dirname( __FILE__ ) ) . '../../../tests/TestConfig.php' );
require_once( dirname( dirname( __FILE__ ) ) . '/core/MantisMarkdown.php' );

# MantisBT Core API
require_mantis_core();
Expand Down
2 changes: 0 additions & 2 deletions tests/Mantis/AllTests.php
Expand Up @@ -33,7 +33,6 @@
require_once 'MentionParsingTest.php';
require_once 'StringTest.php';
require_once 'ConfigParserTest.php';
require_once 'MarkdownTest.php';

/**
* All Test Cases
Expand All @@ -53,7 +52,6 @@ public static function suite() {
$t_suite->addTestSuite( 'MantisStringTest' );
$t_suite->addTestSuite( 'MentionParsingTest' );
$t_suite->addTestSuite( 'MantisConfigParserTest' );
$t_suite->addTestSuite( 'MantisMarkdownTest' );

return $t_suite;
}
Expand Down

0 comments on commit 45f3582

Please sign in to comment.