Giter VIP home page Giter VIP logo

yii2-markdown's Introduction

Krajee Logo
yii2-markdown
Donate

Stable Version Unstable VersionLicense License Total Downloads Monthly Downloads Daily Downloads

This module provides Markdown Editing and Conversion utilities for Yii Framework 2.0. It implements markdown conversion using PHP Markdown Extra and PHP Smarty Pants. In addition, you can customize the flavor of Markdown, by including additional custom conversion patterns. The module also includes an enhanced customized Markdown Editor Widget for markdown editing and preview at runtime. This widget is styled using Bootstrap 3.0. View a complete demo.

Markdown

VIEW DEMO
This is a markdown converter class that uses PHP Markdown Extra and PHP SmartyPantsTypographer for processing Markdown conversion to HTML. It also supports configurable custom conversion processing of patterns for styling your own flavour of Markdown to some extent. View examples and details or view a complete demo.

MarkdownEditor

VIEW DEMO
This is an advanced markdown input widget with configurable options. It is styled using Bootstrap 3.0. Key features available with this widget are:

  1. Configurable toolbar and buttons for formatting content
  2. Live preview of Markdown formatted text as HTML
  3. Maximize editor for full screen editing
  4. Implements PHP Markdown Extra and PHP SmartyPantsTypographer functionality as provided by the Markdown.
  5. Uses Bootstrap 3.0 styling wherever possible
  6. Allows saving/exporting of the text-editor contents as Text or HTML
  7. Configurable header, footer, and input options.
  8. Supports localization and customization of messages and content.

View examples and details or view a complete demo.

Demo

You can see a demonstration here on usage of these functions with documentation and examples.

Installation

The preferred way to install this extension is through composer.

Note: Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki on setting the minimum-stability settings for your application's composer.json.

Either run

$ php composer.phar require kartik-v/yii2-markdown "dev-master"

or add

"kartik-v/yii2-markdown": "dev-master"

to the require section of your composer.json file.

Usage

Setup Module

Add markdown to your modules section of your Yii configuration file

'modules' => [
	/* other modules */
	'markdown' => [
		'class' => 'kartik\markdown\Module',
	]
];

You can setup additional configuration options for the markdown module:

'modules' => [
	'markdown' => [
		// the module class
		'class' => 'kartik\markdown\Module',
		
		// the controller action route used for markdown editor preview
		'previewAction' => '/markdown/parse/preview',
		
		// the list of custom conversion patterns for post processing
		'customConversion' => [
			'<table>' => '<table class="table table-bordered table-striped">'
		],
		
		// whether to use PHP SmartyPantsTypographer to process Markdown output
		'smartyPants' => true
	]
	/* other modules */
];

Markdown

use kartik\markdown\Markdown;

// default call
echo Markdown::convert($content);

// with custom post processing
echo Markdown::convert($content, ['custom' => [
	'<h1>' => '<h1 class="custom-h1">',
	'<h2>' => '<h2 class="custom-h2">',
	'<p>' => Html::beginTag('p', $options),
]]);

MarkdownEditor

// add this in your view
use kartik\markdown\MarkdownEditor;

// usage with model
echo MarkdownEditor::widget([
	'model' => $model, 
	'attribute' => 'markdown',
]);

// usage without model
echo MarkdownEditor::widget([
	'name' => 'markdown', 
	'value' => $value,
]);

Smarty Templates

Smarty templates can be enabled globally by setting the module params

'modules' => [
	'markdown' => [
	     'class' => 'kartik\markdown\Module',
	     'smarty' => true,
	     // Smarty class configuration
	     'smartyParams' => [],
	     // provide Yii::$app to the Smarty template as variable
	     'smartyYiiApp' => true,
	     // provide Yii::$app->params to the Smarty template as config variables
	     'smartyYiiParams' => true,
	],
        /* other modules */
];

Then define smarty in the editor

echo MarkdownEditor::widget([
    'model' => $model, 
    'attribute' => 'markdown',
    'smarty' => true,
]);

Note that it may be unwise to enable Smarty templates globally. You can set the module property smarty to a callable function and provide RBAC features.

'modules' => [
	'markdown' => [
		'class' => 'kartik\markdown\Module',
		'smarty' => function($module) {
			if (\Yii::$app->user->can('smarty')) {
			    if(\Yii::$app->user->can('smartyYiiApp'))
			        $module->smartyYiiApp=true;
			    else
			        $module->smartyYiiApp=false;
			    if(\Yii::$app->user->can('smartyYiiParams'))
			        $module->smartyYiiParams=true;
			    else
			        $module->smartyYiiParams=false;
			    return true;
			}
			return false;
		}
	],
        /* other modules */
];

It may be a better option to leave smarty turned off in the config files and turn it on in the view with the widget settings.

echo MarkdownEditor::widget([
    'model' => $model, 
    'attribute' => 'markdown',
    'smarty' => true,
    'previewAction' => Url::to(['my/preview']),
]);

Then create an action in your controller and implement RBAC there. That way Smarty templates is off by default and you can turn it on and control access to it in the Controller.

class MyController extends Controller
{
    public function actionPreview()
    {
        $module = Yii::$app->getModule('markdown');
        if (\Yii::$app->user->can('smarty')) {
            $module->smarty = true;
            $module->smartyYiiApp = \Yii::$app->user->can('smartyYiiApp') ? true : false;
            $module->smartyYiiParams = Yii::$app->user->can('smartyYiiParams') ? true : false;
        }
        if (isset($_POST['source'])) {
            $output = (strlen($_POST['source']) > 0) ? Markdown::convert($_POST['source'], ['custom' => $module->customConversion]) : $_POST['nullMsg'];
        }
        echo Json::encode(HtmlPurifier::process($output));
    }
}

After saving the value to the database you can render it in your views with Markdown::convert(). For example if you save the Markdown field in the content column of the Post table you can use something like the following.

$content = Post::find(['page_id'=>'myPage'])->one()->content;
echo HtmlPurifier::process(Markdown::convert($content, ['custom' => $module->customConversion]))

License

yii2-markdown is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.

yii2-markdown's People

Contributors

andrew72ru avatar chris68 avatar derekisbusy avatar drenty avatar edofre avatar faryshta avatar gentoofreak avatar janoszab avatar jlnarvaez avatar kartik-v avatar lestat1968 avatar mcserep avatar mx0r avatar richweber avatar vikramkhot111 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-markdown's Issues

Export conflict with ActiveForm

EDIT BY KARTIK: Changed title to Export conflict with ActiveForm.
Original title was Client side validation issue.

Hello Kartik,

Client-side validation doesn't work anymore. Is it just me?

When I replace the widget by a textarea the validation works.

Provide widget for use in activeform/activefield

An activeWidget for the intended usage in an ActiveForm would be extremely helpful!

<?php $form = ActiveForm::begin(); ?>
  <?= $form->field($model, 'description')->widget('\kartik\markdown\MarkdownEditor', 
    [
        'showExport' => false,
    ]) ?>
<?php ActiveForm::end(); ?>

The widget then must fulfill the interface of the routine widget in class ActiveField, i.e. the parameter passing must be harmonized (instead of name and value use the model and attribute)

    /**
     * Renders a widget as the input of the field.
     *
     * Note that the widget must have both `model` and `attribute` properties. They will
     * be initialized with [[model]] and [[attribute]] of this field, respectively.
     *
     * If you want to use a widget that does not have `model` and `attribute` properties,
     * please use [[render()]] instead.
     *
     * @param string $class the widget class name
     * @param array $config name-value pairs that will be used to initialize the widget
     * @return static the field object itself
     */
    public function widget($class, $config = [])
    {
        /** @var \yii\base\Widget $class */
        $config['model'] = $this->model;
        $config['attribute'] = $this->attribute;
        $config['view'] = $this->form->getView();
        $this->parts['{input}'] = $class::widget($config);
        return $this;
    }
?>

Currently one has to use the cumbersome

            <?= $form->field($model, 'description')->widget('\kartik\markdown\MarkdownEditor', 
                [
                    'name' => Html::getInputName($model,'description'), 
                    'value' => $model->description,
                    'showExport' => false,
                ]) ?>

Display preview if input is disabled and/or readonly

If the field is disabled and/or readonly, should it be possible to display the preview and hide buttons and textarea instead of textare in reaonly ?

Another solution is to write a MarkdownViewer only displaying Markdown::convert. By inheriting InputWidget, it could be possible to manage model, attribute, input template, etc.

Javascript injection feasible

If I enter

Check javascript

<script>
alert("Hi!");
</script>

in the editor and press the preview button I get a 'Hi' box. Not really desirable...

Github handles that correctly (as you can easily test with this bug report)

Full screen, preview, and export buttons don't work

These three buttons don't seem to work, but everything else does (bold italics etc).

No javascript errors in console.

Fresh installation:

  1. composer.json "kartik-v/yii2-markdown": "dev-master"
  2. add module 'markdown' => [ 'class' => 'kartik\markdown\Module' ]
  3. add to view
    <?=  MarkdownEditor::widget([
        'model' => $model,
        'attribute' => 'text',
    ]) ?>

Editor does not work in ActiveForm

The markdown editor does not really work inside an ActiveForm; whenever I press the save or preview button, the whole form submits.

Config

    'modules' => [
        'markdown' => [
            // the module class
            'class' => 'kartik\markdown\Module',
            // whether to use PHP SmartyPants to process Markdown output
            'smartyPants' => true

        ],

View

<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\markdown\MarkdownEditor;

/**
 * @var yii\web\View $this
 * @var yii\widgets\ActiveForm $form
 */
?>

<?php
// Works
$value1 = 'TestOutsideForm';
echo MarkdownEditor::widget([
    'name' => 'markdown1', 
    'value' => $value1,
]);
?>
<?php $form = ActiveForm::begin(); ?>
// Does not work
$value2 = 'TestInsideForm';
echo MarkdownEditor::widget([
    'name' => 'markdown2', 
    'value' => $value2,
]);
 ?>
<?= Html::submitButton('Submit') ?>

<?php ActiveForm::end(); ?>

Make Save Button optional

The save button is likely to be misinterpreted if you use the editor in a form (people think they will update/submit the form).

It would be helpful, to make it optional (via a parameter to the widget),

Yii2-markdown version

  • My project is in a stage to go to production. I have used your extension all across the place and my markdown version is look at your dev-master. I don't want my version to be looking at dev-master, so set it to latest version availabel from your Change.md file. But it throws up an error "Setting unknown property: kartik\markdown\MarkdownEditor::smarty".

  • I don't want my code to break when you have released a newer version which might have few modified components in them. So what is the stable version at the moment? Should it not be released for Yii2 version < 2.0.11 ? What is the fix for this?

Broken composer dependences

I'm try to install extension via composer and have an error:

php ./composer.phar require kartik-v/yii2-markdown "dev-master"
  Problem 1
    - Installation request for kartik-v/yii2-markdown dev-master -> satisfiable by kartik-v/yii2-markdown[dev-master].
    - kartik-v/yii2-markdown dev-master requires michelf/php-smartypants * -> no matching package found.

Widget Not Rendering Properly

It seems some form fields for the export feature that needs to be hidden are showing for some reason. This was all fine until I made a recent update to the plugin. Now I see three extra input fields below the main textarea that needs not to be there. See screenshot

image

This is how I'm rendering the form.

<?= $form->field($model, 'description')->widget(MarkdownEditor::classname(),
    [ 'height' => 200, 'showExport' => false]) ?>

No support for checkboxes / tasklist

I am trying to get a simple todo list for the project I am on. Just to keep orderly, and for the client to see. Once in production, it would be removed..

I am looking for GitHub based markdown. ie: anything we can do on GitHub, we should be able to do with a markdown extension that "supports" GitHub.

- [x] checked
- [ ] unchecked

These seem to be unsupported by your extension.

Install error!

Hello, i install package and receive error!
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for kartik-v/yii2-markdown dev-master -> satisfiable
by kartik-v/yii2-markdown[dev-master].
- kartik-v/yii2-markdown dev-master requires michelf/php-smartypants * -> no
matching package found.

Potential causes:

Read http://getcomposer.org/doc/articles/troubleshooting.md for further common
problems.

initEditor is overriding globally scoped name

From kv-markdown.js:

function initEditor(params) {
    var input = params.source,
        editor = params.editor,
        preview = params.preview,
        target = params.target,
        maximize = params.maximize,
        container = params.container,
        modal = editor.slice(1) + '-modal',
        export1 = params.export1,
        export2 = params.export2,
        defHeight = params.height,
        $iframe = $('#' + params.iframeId),
        $form = $iframe.contents().find('form'),
        fullscreen = input.slice(1) + '-fullscreen';
    filename = params.filename;  //// <--------

    $(input).focus(function () {
        $(editor).addClass('active');
    });

filename is not defined inside your file, and the area where it is used is in the global space. So by setting this variable here you are potentially overwriting someone else' variable. It is difficult to say what the effect is. It could be nothing or everything!

I think you want:

        $form = $iframe.contents().find('form'),
        fullscreen = input.slice(1) + '-fullscreen',  /// <---
        filename = params.filename;  //// <--------

    $(input).focus(function () {
        $(editor).addClass('active');
    });

Conflict jquery ???

Hi,
As i have used markdown in ActiveForm as following:
echo $form->field($modelCommentProduct, 'comment')->widget(
MarkdownEditor::classname(),
['height' => 300, 'encodeLabels' => false]
);
and in browser console display an error:
Uncaught TypeError: undefined is not a function
initEditor
(anonymous function)
jQuery.event.dispatch
elemData.handle

I can not click up any place on markdown editor.
Could you please explain me this?Thanks.

possible javascript bug with markdown widget in detail view

Putting the markdown editor into your detailview widget causes preview amongst other things to fail - no console error. This only happens when the export button is enabled and seems to be somehow related to the id for the iframe - altering the id prohibits jquery from selecting the iframe when it is intended hence the conflict doesn't occur - no doubt something else won't work though - probably export am guessing but haven't tried. If I place the widget outside the detail view it works, or if I place 1 outside the detail view and 1 inside, then both work.

Handling PHP SmartyPants not consistent

Even if I say

        'markdown' => [
            // the module class
            'class' => 'kartik\markdown\Module',
            // whether to use PHP SmartyPants to process Markdown output
            'smartyPants' => false

it says

 You may use PHP Markdown Extra and PHP SmartyPants syntax.

Height and Full screen button not working in modal

I must load update section inside modal via renderAjax , But height and Full screen button not working in markdown editor

_form :
<a href="<?= \yii\helpers\Url::to(['quote/update','id' => $model->id])?>" data-toggle="modal" data-target="#myModal<?=$model->id?>">edit</a>

<div class="modal fade " id="myModal<?=$model->id?>" tabindex="-1" role="dialog" aria-labelledby="myModal<?=$model->id?>"> <div class="modal-dialog " role="document"> <div class="modal-content"> </div> </div> </div>

Quate controller :

public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->renderAjax('update', [
'model' => $model,
]);
}
}

Quate _from :

<div class="modal-header">
    <h4 class="modal-title" id="myModalLabel<?=$model->id?>"><?=($model->isNewRecord ? 'اضافه کردن نقل قول' : 'ویرایش نقل قول')?></h4>
</div>
<div class="modal-body">
<?= $form->field($model, 'context')->widget(MarkdownEditor::className(),[
    'height' => 300,
    'footerMessage' => '',
    'showExport' => FALSE,
    'showPreview' => FALSE
]); ?>           

</div>
<div class="modal-footer">
    
    <div class="form-group">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>
</div>

400 Bad Request

when i press the preview button ,it comes loading preview the error show 400 Bad Request
send @ jquery.js:8623
jQuery.extend.ajax @ jquery.js:8152
togglePreview @ kv-markdown.js:86
(anonymous function) @ kv-markdown.js:357
jQuery.event.dispatch @ jquery.js:4409
elemData.handle @ jquery.js:4095

Preview and download Button not working

hiii kartik,

Thank you for this greate module..

I have some issuse related them.
Preview and Export Button is not working i have configured in module section of config file is here ...

'markdown' => [
'class' => 'kartik\markdown\Module',
'previewAction' => '/markdown/parse/preview',
'smartyPants' => true
],
i have seen one error in console..
"NetworkError: 403 Forbidden - http://localhost/admin/frontend/web/index.php/markdown/parse/download"
Please help..

Thank you..

Issue with installation

Hi i keep encountering the following when i try to install package:

Problem 1
- Installation request for kartik-v/yii2-markdown dev-master -> satisfiable by kartik-v/yii2-markdown[dev-master].
- kartik-v/yii2-markdown dev-master requires michelf/php-smartypants * -> no matching package found.

Potential causes:

Read http://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

Can you assist please?

I18N support

It would be extremely helpful if the module would provide the base for I18N (i.e. use yii::t()).

I would be more than happy to provide the German translations then.

using as sub-module: preview caused "property of non-object' caused by $module->customConversion

Hi,

When I use the editor as sub-modue inside a module/extension with own configuration and executing the preview I reicve:

PHP Notice 'yii\base\ErrorException' with message 'Trying to get property of non-object' 
in D:\basic_project\vendor\kartik-v\yii2-markdown\controllers\ParseController.php:31

All other functions (for example the downloads) are working like expected.
When I use the configuration in app/config/web.php instead of the extension config - the preview works without any problems.

My extension / module is configured like described in the yii2 guide:
http://www.yiiframework.com/doc-2.0/guide-structure-modules.html

My Module.php looks like this:

namespace app\modules\test;

class Module extends \yii\base\Module
{
    public function init()
    {
        parent::init();

        $this->modules = [
            'markdown' => [
                'class' => 'kartik\markdown\Module',
                'previewAction' => 'markdown/parse/preview',
                'downloadAction' => 'markdown/parse/download',
            ],
        ];
    }
}

Is this a bug or did I something wrong with the configuration as sub-module?

Thank you and best regards

How to config markdown

I want to config markdown to hide 'Export' button, and want to add some button on the toolbar.
Are there any docs or example?

PHP Fatal Error – yii\base\ErrorException Class 'kartik\widgets\AssetBundle' not found

Web.php

'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module',
],
],

view/index.php

$array = array(
0=>array(
"Conference"=>4647,
"CallerIDNum"=>0046856202564,
"CallerIDName"=>0046856202564,
)
);

      $dataproviderTest = new ArrayDataProvider([
                    'allModels' => $array,
                    'sort'=>[
                    'attributes'=>['Conference','CallerIDNum','CallerIDName',]],
                    //'Event','ActionID','UserNumber','Channel','Admin','MarkedUser',,'Talking'
                    'pagination'=>[
                    'pageSize'=>10,
               ],
            ]);

      $gridColumns = [
            ['class' => 'yii\grid\SerialColumn'],
                'Conference',
                [
                    'attribute' => 'CallerIDNum',
                    'label' => 'Caller Number',
                ],
                [
                    'attribute' => 'CallerIDName',
                    'label' => 'Caller Name',
                ],

        ];

        // Renders a export dropdown menu
        echo ExportMenu::widget([
            'dataProvider' => $dataproviderTest,
            'columns' => $gridColumns
        ]);

        // You can choose to render your own GridView separately
        echo \kartik\grid\GridView::widget([
            'dataProvider' => $dataproviderTest,
           // 'filterModel' => $searchModel,
            'columns' => $gridColumns
        ]);

I have installed the widget and also tried different ways to fix this like reinstal steps given in some forums.

But still having the following error.

PHP Fatal Error – yii\base\ErrorException

Class 'kartik\widgets\AssetBundle' not found

  1. in /var/www/html/pbx/pbx/asterisk/vendor/kartik-v/yii2-export/ExportMenuAsset.php at line 20
    11121314151617181920212223242526272829use kartik\widgets\AssetBundle;

/**

  • Asset bundle for ExportMenu Widget (for export menu data)
    *
  • @author Kartik Visweswaran [email protected]
  • @SInCE 1.0
    /
    class ExportMenuAsset extends AssetBundle
    {
    /
    *
    • @inheritdoc
      */
      public function init()
      {
      $this->setSourcePath(DIR . '/assets');
      $this->setupAssets('js', ['js/kv-export-data']);
      $this->setupAssets('css', ['css/kv-export-data']);
      parent::init()

I have tried different widget from kartik but no luck to use them fully.

custom button

if you can please add an option for creating custom button in markdown editor;

Emoji

Hello. Is there a way or a plugin to use all known emojis in your editor? It would be excellent

Error when using <?php tag inside the processing text

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of yii2-markdown.
  • This is not a usage question. I confirm having gone through and read the documentation and demos.
  • This is not a general programming/coding question. (Those should be directed to the webtips Q & A forum).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional).

Steps to reproduce the issue

1.Install the extension
2.crate a readme.md file and add the following containing the <?php tag


<?php echo "some text"

  1. Convert the text using
echo Markdown::process($this->render('README.md'));

Expected behavior and actual behavior

When I follow those steps, I see...

PHP Parse Error – yii\base\ErrorException
syntax error, unexpected '`'

I was expecting...
The formatted output

If you remove the <?php tag from the text to be processed then it works ok

BUT

If you use it in the following way it even works along the <?php tag

<?php $html = <<< HTML
        <?php echo "some text";
HTML;
?>
<?=\kartik\markdown\Markdown::process($html) ?>

Environment

Yii 2.0.15.1

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version:
  • yii2-markdown version:

Isolating the problem

  • This bug happens on the demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-markdown without other plugins.

Class 'kartik\widgets\AssetBundle' not found

create_article.php

use kartik\markdown\MarkdownEditor;
// usage without model
echo MarkdownEditor::widget([
'name' => 'markdown',
'value' => 'test',
]);

  1. in /home/xxx/vendor/kartik-v/yii2-markdown/markdown/MarkdownEditorAsset.php at line 18
    9101112131415161718192021222324252627

namespace kartik\markdown;

/**

  • Asset bundle for MarkdownEditor Widget
    *

  • @author Kartik Visweswaran [email protected]

  • @SInCE 1.0
    */
    class MarkdownEditorAsset extends \kartik\widgets\AssetBundle
    {

    public function init()
    {
    $this->setSourcePath(DIR . '/../assets');
    $this->setupAssets('css', ['css/kv-markdown']);
    $this->setupAssets('js', ['js/rangyinputs-jquery-1.1.2', 'js/kv-markdown']);
    parent::init();
    }

beforeProcess and afterProcess callables?

Markdown has a custom option which is great, but it would be better if you could pass callables as options to change the markup either before of after calling process().

That would provide more flexibility.

I can open a PR if you're interested.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

The preview function is not working

1: The controller can receive the preview request, but the "PHP Fatal Error" shows like below.

image

2: In fact, the method "_SmartyPantsTypographer_TmpImpl" can be found.

MarkdownEditor does not work when load via Boostrap modal

I use a Boostrap Modal to load the comment view remote which provided by another controller, but the toolbar does not work. A java script error message show each time a toolbar button is clicked.

Uncaught TypeError: Cannot read property 'length' of undefined VM728:152
    markUp VM728:152
    onclick

The error line:

function markUp(btn, source) {
    var el = $(source)
    el.focus();
    var txt = el.extractSelectedText(),
        len = txt.length, //!!! throw the exception above
        str = txt

    // Bold
    if (btn == 1) {
        str = (txt.length > 0) ? getBlockMarkUp(txt, '**', '**') : '**(bold text here)**';
    }
...

Views
The Modal in the caller controller:

Modal::begin([
    'id' => 'delete-modal',
    'clientOptions' => [
        'modal' => true,
        'autoOpen' => false,
        'remote' => 'the remote content that has the MarkdownEditor widget'
    ],
]);
Modal::end();

And, the MarkdownEditor in the remote controller:

<?= MarkdownEditor::widget([
    'name' => 'task-comment',
    'height' => 80,
    'encodeLabels' => true,
    'toolbar' => [
        //...
    ],
    'footerMessage' => '',
    'showExport' => false,
]) ?>

Install OK, can't resolve class

Added the yii2-markdown to my composer.json file, it installed the following-

  • Installing michelf/php-markdown (1.5.0)
  • Installing michelf/php-smartypants (1.6.0-beta1)
  • Installing kartik-v/yii2-markdown (dev-master f6c7817)

When I add the simplest of code to a page -

But might be a problem with class naming or path names???

...
use kartik\markdown\Markdown;
...
'value' => Markdown::convert($model->factoid),
...
Yii2 tosses this exception -
PHP Fatal Error – yii\base\ErrorException Class 'michelf\_SmartyPantsTypographer_TmpImpl' not found

Multiple editors in a view breaks Js.

When using multiple markdown editors in a single view file, only the last rendered editor works properly with the toggle preview and toggle fullscreen functions.

I haven't tested other buttons, but these seem to fail.

Composer Error

Problem 1
- Installation request for kartik-v/yii2-markdown dev-master -> satisfiable by kartik-v/yii2-markdown[dev-master].
- kartik-v/yii2-markdown dev-master requires michelf/php-smartypants * -> no matching package found.

MarkdownEditor unreliable with Firefox

I have created a form on my site that uses the MarkdownEditor widget. Under Chrome the page always loads properly and all the buttons work as expected.

screen shot 2018-06-08 at 02 21 55

When I view the same page in Firefox, it seems to work once then breaks. When it is broken it looks like:

screen shot 2018-06-08 at 02 23 01

The height is not honoured. The Preview button doesn't work, there is no call out to the preview endpoint when the button is clicked and no messages in the console log. The full screen button doesn't work either (also nothing in console log). The other buttons in the tool group (e.g. bold, italic) work as expected.

I include my configuration for completeness, but I don't think the problem is here. It feels like a javascript loading issue.

common/config/main.php

'modules' => [
	'markdown' => [
		'class' => 'kartik\markdown\Module',
		// the controller action route used for markdown editor preview
		'previewAction' => '/markdown/parse/preview',
		// the list of custom conversion patterns for post processing
		'customConversion' => [
			// default
			// '<table>' => '<table class="table table-bordered table-striped">'
			'<table>' => '<table class="table table-bordered">'
		],
		'smartyPants' => true
	]
]

myview.php

	<?php
	echo $form->field($model, 'description')->widget(MarkdownEditor::classname(), [
		'height' => 300,
		'encodeLabels' => false,
		'showExport' => false,
	]);
	?>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.