ornj / markdown-bundle
Form fields for inputting and previewing markdown in Symfony2
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 6 026
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 10
Open Issues: 0
Language:JavaScript
Type:symfony-bundle
Requires
- php: >=5.3.0
- symfony/symfony: >=2.2
Suggests
- knplabs/knp-markdown-bundle: 1.2.*@dev
This package is not auto-updated.
Last update: 2022-07-20 00:48:25 UTC
README
This bundle create a markdown
form field allowing for the realtime previewing of markdown markup. It is intended
to be used in a user interface built using Twitter Bootstrap. This bundle pairs nicely with
SonataAdminBundle or MopaBootstrapBundle.
You should use KnpMarkdownBundle to render the markdown on your front end.
Markdown fields are rendered with controls and a preview using:
Installation
Install this bundle in your Symfony2 project by adding it to your composer.json
.
{ "require": { "ornj/markdown-bundle": "dev-master" } }
After running updating composer, register the bundle in app/AppKernel.php
.
$bundles = array( // ... new Ornj\Bundle\MarkdownBundle\OrnjMarkdownBundle(), );
Usage
Enable Twig Template
This bundle provides a Twig template for rendering the markdown field. To use it there are two options.
Enable globally by adding the template to config.yml
twig: form: resources: - 'OrnjMarkdownBundle:Form:fields.html.twig'
or
Add the template in your form's twig template.
{% form_theme form 'OrnjMarkdownBundle:Form:fields.html.twig' %}
Add Styles and Javascript
Extend or modify your base admin template and add the following styles. Either SCSS or CSS can be used.
SCSS
{% stylesheets filter="cssrewrite, compass" '@OrnjMarkdownBundle/Resources/public/scss/*' %} <link rel="stylesheet" href="{{ asset_url }}" type="text/css" media="all" /> {% endstylesheets %}
CSS
{% stylesheets filter="cssrewrite, compass" '@OrnjMarkdownBundle/Resources/public/css/*' %} <link rel="stylesheet" href="{{ asset_url }}" type="text/css" media="all" /> {% endstylesheets %}
Javascript
Extend or modify your base admin template and add the following Javascript.
{% javascripts '@OrnjMarkdownBundle/Resources/public/js/markdown.js' '@OrnjMarkdownBundle/Resources/public/js/to-markdown.js' '@OrnjMarkdownBundle/Resources/public/js/bootbox.js' '@OrnjMarkdownBundle/Resources/public/js/bootstrap-markdown.js' %} <script type="text/javascript" src="{{ asset_url }}"></script> {% endjavascripts %}
The Form Field
The markdown field is an extension of textarea
. It can be used to render an input for any field expecting a string.
$builder->add('body', 'markdown');
Rendering in front end
You will need a parser in order to render the markdown as HTML. KnpMarkdownBundle adds a handy Twig extension for rendering the result.
To Do
- Allow inclusion of
textarea
options. - Investigate removing physical copies of dependencies in bundle.
- Allow customization of ui options through config.