Skip to content

Commit

Permalink
Use Mermaid 8.0.0 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames authored Feb 17, 2019
1 parent d39455c commit 5accc50
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 125 deletions.
12 changes: 6 additions & 6 deletions Mermaid.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static function initExtension( $credits = [] ) {
'remoteExtPath' => 'Mermaid',
'position' => 'top',
'styles' => [
'res/mermaid/7.0.5/mermaid.min.css'
'res/mermaid/8.0.0/mermaid.min.css'
],
'messages' => [],
'targets' => [
Expand All @@ -83,7 +83,7 @@ public static function initExtension( $credits = [] ) {
'remoteExtPath' => 'Mermaid',
'position' => 'top',
'styles' => [
'res/mermaid/7.0.5/mermaid.forest.min.css'
'res/mermaid/8.0.0/mermaid.forest.min.css'
],
'messages' => [],
'targets' => [
Expand All @@ -97,7 +97,7 @@ public static function initExtension( $credits = [] ) {
'remoteExtPath' => 'Mermaid',
'position' => 'top',
'styles' => [
'res/mermaid/7.0.5/mermaid.dark.min.css'
'res/mermaid/8.0.0/mermaid.dark.min.css'
],
'messages' => [],
'targets' => [
Expand All @@ -111,7 +111,7 @@ public static function initExtension( $credits = [] ) {
'remoteExtPath' => 'Mermaid',
'position' => 'top',
'styles' => [
'res/mermaid/7.0.5/mermaid.neutral.min.css'
'res/mermaid/8.0.0/mermaid.neutral.min.css'
],
'messages' => [],
'targets' => [
Expand Down Expand Up @@ -140,7 +140,7 @@ public static function initExtension( $credits = [] ) {
'remoteExtPath' => 'Mermaid',
'position' => 'top',
'scripts' => [
'res/mermaid/7.0.5/mermaid.min.js'
'res/mermaid/8.0.0/mermaid.min.js'
],
'dependencies' => [
'ext.mermaid.d3'
Expand All @@ -157,7 +157,7 @@ public static function initExtension( $credits = [] ) {
'remoteExtPath' => 'Mermaid',
'position' => 'top',
'scripts' => [
'res/mermaid/7.0.5/mermaidAPI.min.js'
'res/mermaid/8.0.0/mermaidAPI.min.js'
],
'dependencies' => [
'ext.mermaid.d3'
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"process-timeout": 0
},
"scripts":{
"phpunit": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist"
"phpunit": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist",
"phpdbg": "phpdbg -qrr ../../tests/phpunit/phpunit.php -c phpunit.xml.dist",
"test": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist"
}
}
10 changes: 8 additions & 2 deletions res/d3/d3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion res/ext.mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

var that = $( this );

var id = that.attr( 'id' ) + '-diagram';
var id = 'ext-mermaid-' + ( new Date().getTime() );
var data = that.data( 'mermaid' );

that.find( '.mermaid-dots' ).hide();
Expand Down
1 change: 1 addition & 0 deletions res/mermaid/8.0.0/mermaid.dark.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions res/mermaid/8.0.0/mermaid.forest.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions res/mermaid/8.0.0/mermaid.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions res/mermaid/8.0.0/mermaid.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions res/mermaid/8.0.0/mermaid.neutral.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions res/mermaid/8.0.0/mermaidAPI.min.js

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions src/HookRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ private function registerCallbackHandlers( $configuration ) {
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserFirstCallInit
*/
$this->handlers['ParserFirstCallInit'] = function ( &$parser ) {
$defaultTheme = $GLOBALS['mermaidgDefaultTheme'];

$parserFunctionFactory = new ParserFunctionFactory();

list( $name, $definition, $flag ) = $parserFunctionFactory->newMermaidParserFunctionDefinition();

$parser->setFunctionHook( $name, $definition, $flag );
$parser->setFunctionHook(
'mermaid',
MermaidParserFunction::newCallback( $defaultTheme ),
0
);

return true;
};
Expand Down
47 changes: 36 additions & 11 deletions src/MermaidParserFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ class MermaidParserFunction {
*/
private $defaultTheme = '';

/**
* @since 1.1
*
* @param string $defaultTheme
*
* @return callable
*/
public static function newCallback( $defaultTheme ) {

return function( $parser ) use ( $defaultTheme ) {
$mermaidParserFunction = new self(
$parser
);

$mermaidParserFunction->setDefaultTheme(
$defaultTheme
);

return $mermaidParserFunction->parse( func_get_args() );
};
}

/**
* @since 1.0
*
Expand Down Expand Up @@ -51,49 +73,52 @@ public function setDefaultTheme( $defaultTheme ) {
public function parse( array $params ) {

$class = 'ext-mermaid';

// #12 Improve entropy by adding a random number
$id = uniqid( 'ext-mermaid-' . rand( 1, 10000 ) );

$parserOutput = $this->parser->getOutput();

if( isset( $params[0] ) && $params[0] instanceof \Parser ) {
array_shift( $params );
}

// Signal the OutputPageParserOutput hook
$this->parser->getOutput()->setExtensionData(
$parserOutput->setExtensionData(
'ext-mermaid',
true
);

$this->parser->getOutput()->addModuleStyles(
$parserOutput->addModuleStyles(
'ext.mermaid.styles'
);

$this->parser->getOutput()->addModules(
$parserOutput->addModules(
'ext.mermaid'
);

$config = [
'theme' => $this->defaultTheme
];

foreach ( $params as $param ) {
foreach ( $params as $key => $param ) {

if ( strpos( $param, '=' ) !== false ) {
list( $k, $v ) = explode( '=', $param, 2 );

if ( $k === 'theme' ) {
if ( $k === 'config.theme' ) {
$config['theme'] = $v;
unset( $params[$key] );
}

if ( $k === 'config.flowchart.curve' ) {
$config['flowchart'] = [ 'curve' => $v ];
unset( $params[$key] );
}
}
}

$content = isset( $params[0] ) ? $params[0] : '';
$content = implode( "|", $params );

return Html::rawElement(
'div',
[
'id' => $id,
'class' => $class,
'data-mermaid' => json_encode(
[
Expand Down
36 changes: 0 additions & 36 deletions src/ParserFunctionFactory.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

if ( PHP_SAPI !== 'cli' ) {
if ( PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' ) {
die( 'Not an entry point' );
}

Expand Down
Loading

0 comments on commit 5accc50

Please sign in to comment.