Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add markdown element #239

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ This plugin adds a rich editor on the fields you want. Now you can manage your c

## Installation


### Require the plugin

If you want to use our recipes, you can configure your composer.json by running:

```bash
Expand All @@ -31,6 +34,10 @@ composer config --no-plugins --json extra.symfony.endpoint '["https://api.github
composer require monsieurbiz/sylius-rich-editor-plugin
```

<details>
<summary>For the installation without flex, follow these additional steps</summary>
<p>

Change your `config/bundles.php` file to add the line for the plugin :

```php
Expand All @@ -56,8 +63,37 @@ monsieurbiz_richeditor_admin:
resource: "@MonsieurBizSyliusRichEditorPlugin/Resources/config/routing/admin.yaml"
prefix: /%sylius_admin.path_name%
```
</p>
</details>

### Correct `Twig\Extra\Intl\IntlExtension` conflict

Update the file `config/packages/twig.yaml` to remove the `IntlExtension` service :

```yaml
twig:
paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'

services:
# Removed by Rich Editor because it is loaded by the quire of twig/extra-bundle
#
# _defaults:
# public: false
# autowire: true
# autoconfigure: true
#
# Twig\Extra\Intl\IntlExtension: ~

when@test_cached:
twig:
strict_variables: true

```

### Install the assets

And install the assets
```yaml
bin/console asset:install
```
Expand Down Expand Up @@ -198,6 +234,13 @@ You can distinguish the `Row` element and the `Column` element by their dotted b

![The HTML element](docs/images/screenshots/html.png)

### Markdown Element

![The Markdown element](docs/images/screenshots/markdown.png)

Use can use `MONSIEURBIZ_SYLIUS_RICH_EDITOR_ENABLED_HIGHLIGHT_JS_SHOP` to enable code highlighting in the shop.
maximehuran marked this conversation as resolved.
Show resolved Hide resolved
Also you can change the theme with `MONSIEURBIZ_SYLIUS_RICH_EDITOR_ENABLED_HIGHLIGHT_JS_THEME`.

### Text element

![The text element](docs/images/screenshots/text.png)
Expand Down
8 changes: 8 additions & 0 deletions assets/js/highlight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import hljs from 'highlight.js';
import 'highlight.js/styles/default.css';

document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('pre code').forEach((block) => {
maximehuran marked this conversation as resolved.
Show resolved Hide resolved
hljs.highlightElement(block);
});
});
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"license": "MIT",
"require": {
"php": "^8.0",
"sylius/sylius": ">=1.11 <1.14"
"sylius/sylius": ">=1.11 <1.14",
"twig/markdown-extra": "^2.16|^3.12",
"twig/extra-bundle": "^2.16|^3.12",
"league/commonmark": "^2.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.16",
Expand Down
2 changes: 2 additions & 0 deletions dist/.env.local
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
SYLIUS_FIXTURES_HOSTNAME=${SYMFONY_DEFAULT_ROUTE_HOST:-localhost}
MONSIEURBIZ_SYLIUS_RICH_EDITOR_ENABLED_HIGHLIGHT_JS_SHOP=true
MONSIEURBIZ_SYLIUS_RICH_EDITOR_ENABLED_HIGHLIGHT_JS_THEME=atom-one-dark

This file was deleted.

18 changes: 18 additions & 0 deletions dist/config/packages/twig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
twig:
paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'

services:
# Removed by Rich Editor because it is loaded by the quire of twig/extra-bundle
#
# _defaults:
# public: false
# autowire: true
# autoconfigure: true
#
# Twig\Extra\Intl\IntlExtension: ~

when@test_cached:
twig:
strict_variables: true
3 changes: 0 additions & 3 deletions dist/config/routes/monsieurbiz_sylius_rich_editor_plugin.yaml

This file was deleted.

Binary file added docs/images/screenshots/markdown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"a11y-dialog-component": "^5.5.1",
"codemirror": "5",
"gulp": "^4.0.2",
"highlight.js": "^11.10.0",
"mustache": "^4.0.1",
"suneditor": "^2.45.1"
}
Expand Down
42 changes: 42 additions & 0 deletions src/Form/Type/UiElement/MarkdownType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of Monsieur Biz' Rich Editor plugin for Sylius.
*
* (c) Monsieur Biz <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusRichEditorPlugin\Form\Type\UiElement;

use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\AlignmentType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;

class MarkdownType extends AbstractType
{
/**
* @inheritdoc
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('content', TextareaType::class, [
'required' => true,
'label' => 'monsieurbiz_richeditor_plugin.ui_element.monsieurbiz.markdown.field.content',
'constraints' => [
new Assert\NotBlank([]),
],
])
->add('align', AlignmentType::class, [
'show_justify' => true,
])
;
}
}
11 changes: 11 additions & 0 deletions src/Resources/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ knp_gaufrette:
parameters:
env(MONSIEURBIZ_SYLIUS_RICH_EDITOR_UPLOAD_DIR): /media/rich-editor
env(MONSIEURBIZ_SYLIUS_RICH_EDITOR_IMAGE_UPLOAD_DIR): /media/image
env(MONSIEURBIZ_SYLIUS_RICH_EDITOR_ENABLED_HIGHLIGHT_JS_SHOP): 'false'
env(MONSIEURBIZ_SYLIUS_RICH_EDITOR_ENABLED_HIGHLIGHT_JS_THEME): 'default'

twig:
globals:
monsieurbiz_sylius_rich_editor: {
highlight_js: {
shop_enabled: '%env(MONSIEURBIZ_SYLIUS_RICH_EDITOR_ENABLED_HIGHLIGHT_JS_SHOP)%',
theme: '%env(MONSIEURBIZ_SYLIUS_RICH_EDITOR_ENABLED_HIGHLIGHT_JS_THEME)%',
}
}

liip_imagine:
loaders:
Expand Down
12 changes: 12 additions & 0 deletions src/Resources/config/richeditor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,15 @@ monsieurbiz_sylius_richeditor:
templates:
admin_render: '@MonsieurBizSyliusRichEditorPlugin/Admin/UiElement/row.html.twig'
front_render: '@MonsieurBizSyliusRichEditorPlugin/Shop/UiElement/row.html.twig'
monsieurbiz.markdown:
alias: markdown
title: 'monsieurbiz_richeditor_plugin.ui_element.monsieurbiz.markdown.title'
description: 'monsieurbiz_richeditor_plugin.ui_element.monsieurbiz.markdown.description'
icon: file code
wireframe: markdown
tags: [ default ]
classes:
form: MonsieurBiz\SyliusRichEditorPlugin\Form\Type\UiElement\MarkdownType
templates:
admin_render: '@MonsieurBizSyliusRichEditorPlugin/Admin/UiElement/markdown.html.twig'
front_render: '@MonsieurBizSyliusRichEditorPlugin/Shop/UiElement/markdown.html.twig'
5 changes: 5 additions & 0 deletions src/Resources/config/sylius/ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ sylius_ui:
blocks:
monsieurbiz_richeditor_init_app:
template: '@MonsieurBizSyliusRichEditorPlugin/Admin/app.html.twig'

sylius.shop.layout.javascripts:
blocks:
monsieurbiz_richeditor_init_shop:
template: '@MonsieurBizSyliusRichEditorPlugin/Shop/app.html.twig'
9 changes: 9 additions & 0 deletions src/Resources/public/css/rich-editor-highlight.css

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

2 changes: 1 addition & 1 deletion src/Resources/public/css/rich-editor.css

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/Resources/public/entrypoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
"js": [
"/public/js/rich-editor.js"
]
},
"rich-editor-highlight": {
"css": [
"/public/css/rich-editor-highlight.css"
],
"js": [
"/public/js/rich-editor-highlight.js"
]
}
}
}
1 change: 1 addition & 0 deletions src/Resources/public/js/rich-editor-highlight.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Resources/public/js/rich-editor.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/Resources/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"public/rich-editor.css": "/public/css/rich-editor.css",
"public/rich-editor.js": "/public/js/rich-editor.js"
"public/rich-editor.js": "/public/js/rich-editor.js",
"public/rich-editor-highlight.css": "/public/css/rich-editor-highlight.css",
"public/rich-editor-highlight.js": "/public/js/rich-editor-highlight.js"
}
5 changes: 5 additions & 0 deletions src/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ monsieurbiz_richeditor_plugin:
description: 'An element with multiple images. A link can be added on each image.'
field:
images: 'Images list'
monsieurbiz.markdown:
title: 'Markdown Element'
description: 'An element with markdown content'
field:
content: 'Content'
file:
change: 'Change file'
form:
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/translations/messages.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ monsieurbiz_richeditor_plugin:
description: 'Un elemento con varias imágenes. Se puede agregar un enlace a cada imagen.'
field:
images: 'Lista de imágenes'
monsieurbiz.markdown:
title: 'Elemento de markdown'
description: 'Un elemento con contenido en markdown'
field:
content: 'Contenido'
file:
change: 'Cambiar archivo'
form:
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/translations/messages.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ monsieurbiz_richeditor_plugin:
description: 'Une lame contenant une liste d''images.'
field:
images: 'Liste d''images'
monsieurbiz.markdown:
title: 'Lame Markdown'
description: 'Une lame affichant un contenu rédigé en Markdown'
field:
content: 'Contenu'
file:
change: 'Changer de fichier'
form:
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/translations/messages.hr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ monsieurbiz_richeditor_plugin:
description: 'Element s više slika. Svaka slika može biti link.'
field:
images: 'Slike'
monsieurbiz.markdown:
title: 'Markdown'
description: 'Element koji sadrži Markdown.'
field:
content: 'Sadržaj'
file:
change: 'Zamijeni datoteku'
form:
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/translations/messages.nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ monsieurbiz_richeditor_plugin:
description: 'Een element met meerdere afbeeldingen. Aan elke afbeelding kan een link worden toegevoegd.'
field:
images: 'Lijst van afbeeldingen'
monsieurbiz.markdown:
title: 'Markdown'
description: 'Een element met inhoud in markdown'
field:
content: 'Inhoud'
file:
change: 'Bestand aanpassen'
form:
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/translations/messages.pl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ monsieurbiz_richeditor_plugin:
description: 'Element z wieloma obrazami. Można dodać link do każdego obrazu.'
field:
images: 'Lista obrazów'
monsieurbiz.markdown:
title: 'Element Markdown'
description: 'Element z treścią Markdown'
field:
content: 'Treść'
file:
change: 'Zmień plik'
form:
Expand Down
13 changes: 13 additions & 0 deletions src/Resources/views/Admin/UiElement/markdown.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{#
UI Element template
type: markdown
element fields :
content
align
#}
{% set align = element.align is defined and element.align is not empty ? element.align : 'inherit' %}
{% if element is not empty and element.content is not empty %}
<div style="text-align: {{align}};">
{{ element.content|markdown_to_html }}
</div>
{% endif %}
13 changes: 13 additions & 0 deletions src/Resources/views/Shop/UiElement/markdown.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{#
UI Element template
type: markdown
element fields :
content
align
#}
{% set align = element.align is defined and element.align is not empty ? element.align : 'inherit' %}
{% if element is not empty and element.content is not empty %}
<div style="text-align: {{align}};">
maximehuran marked this conversation as resolved.
Show resolved Hide resolved
{{ element.content|markdown_to_html }}
</div>
{% endif %}
12 changes: 12 additions & 0 deletions src/Resources/views/Shop/app.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% set highlightJsEnabled = monsieurbiz_sylius_rich_editor.highlight_js.shop_enabled|default('false') %}
{% set highlightJsTheme = monsieurbiz_sylius_rich_editor.highlight_js.theme|default('default') %}

{% if highlightJsEnabled == 'true' %}
{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'bundles/monsieurbizsyliusricheditorplugin/js/rich-editor-highlight.js'} %}
maximehuran marked this conversation as resolved.
Show resolved Hide resolved
{% if highlightJsTheme == 'default' %}
{% include '@SyliusUi/_stylesheets.html.twig' with {'path': 'bundles/monsieurbizsyliusricheditorplugin/css/rich-editor-highlight.css'} %}
{% else %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/{{ highlightJsTheme|escape('html_attr') }}.min.css">
{% endif %}

{% endif %}
11 changes: 11 additions & 0 deletions src/Resources/views/Wireframe/markdown.svg.twig

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Encore

// entries
.addEntry('rich-editor', './assets/js/app.js')
.addEntry('rich-editor-highlight', './assets/js/highlight.js')

// copy images
.copyFiles({
Expand Down
Loading