-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
beec4b9
commit 458e1b1
Showing
5 changed files
with
141 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
version: '1.0' | ||
license: community | ||
--- | ||
|
||
# EasyMDE | ||
|
||
:::info | ||
Before Avo 3.17 this field was called `markdown`. It was renamed to `easy_mde` so we can add our own implementation with `markdown`. | ||
::: | ||
|
||
<Image src="/assets/img/fields/easy_mde.jpg" width="906" height="421" alt="Trix field" /> | ||
|
||
The `easy_mde` field renders a [EasyMDE Markdown Editor](https://github.com/Ionaru/easy-markdown-editor) and is associated with a text or textarea column in the database. | ||
`easy_mde` field converts text within the editor into raw Markdown text and stores it back in the database. | ||
|
||
```ruby | ||
field :description, as: :easy_mde | ||
``` | ||
|
||
:::info | ||
The `easy_mde` field is hidden from the **Index** view. | ||
::: | ||
|
||
## Options | ||
|
||
<Option name="`always_show`"> | ||
|
||
By default, the content of the `easy_mde` field is not visible on the `Show` view, instead, it's hidden under a `Show Content` link that, when clicked, displays the content. You can set `easy_mde` to always display the content by setting `always_show` to `true`. | ||
|
||
<!-- @include: ./../common/default_boolean_false.md--> | ||
</Option> | ||
|
||
<Option name="`height`"> | ||
Sets the value of the editor | ||
|
||
#### Default | ||
|
||
`auto` | ||
|
||
#### Possible values | ||
|
||
`auto` or any number in pixels. | ||
</Option> | ||
|
||
<Option name="`spell_checker`"> | ||
Toggles the editor's spell checker option. | ||
|
||
```ruby | ||
field :description, as: :easy_mde, spell_checker: true | ||
``` | ||
|
||
<!-- @include: ./../common/default_boolean_false.md--> | ||
</Option> | ||
|
||
<!-- ## Enable spell checker --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,90 @@ | ||
--- | ||
version: '1.0' | ||
version: '3.17' | ||
license: community | ||
--- | ||
|
||
# Markdown | ||
|
||
<Image src="/assets/img/fields/markdown.jpg" width="906" height="421" alt="Trix field" /> | ||
:::info | ||
In Avo 3.17 we renamed the `markdown` field `easy_mde` and introduced this custom one. | ||
::: | ||
|
||
The `Markdown` field renders a [EasyMDE Markdown Editor](https://github.com/Ionaru/easy-markdown-editor) and is associated with a text or textarea column in the database. | ||
`Markdown` field converts text within the editor into raw Markdown text and stores it back in the database. | ||
This field is inspired by the wonderful GitHub editor we all love and use. | ||
|
||
The Markdown field is hidden from the **Index** view. | ||
It supports applying styles to the markup and dropping files in the editor. The file will be taken over by Rails and persisted using Active Storage. | ||
|
||
|
||
```ruby | ||
field :description, as: :markdown | ||
field :body, as: :markdown | ||
``` | ||
|
||
## Options | ||
|
||
<Option name="`always_show`"> | ||
|
||
By default, the content of the `Markdown` field is not visible on the `Show` view, instead, it's hidden under a `Show Content` link that, when clicked, displays the content. You can set Markdown to always display the content by setting `always_show` to `true`. | ||
:::warning | ||
Please add the `redcarpet` gem to your `Gemfile` | ||
```ruby | ||
gem "redcarpet" | ||
``` | ||
::: | ||
|
||
<!-- @include: ./../common/default_boolean_false.md--> | ||
</Option> | ||
## Customize the parser & renderer | ||
|
||
<Option name="`height`"> | ||
Sets the value of the editor | ||
There are two places where we parse the markdown into the HTML you see. | ||
|
||
#### Default | ||
1. In the controller | ||
2. In the <Show /> field component | ||
|
||
`auto` | ||
You may customize the renderer by overriding the implementation. | ||
|
||
### Everywhere | ||
|
||
#### Possible values | ||
Both parsers inherit from the same parser from the field. So you can override in the field and it will be visible everywhere. | ||
|
||
`auto` or any number in pixels. | ||
</Option> | ||
```ruby | ||
# config/initializers/avo.rb | ||
|
||
module Avo | ||
module Fields | ||
class MarkdownField < BaseField | ||
def self.parser | ||
# update this to your liking | ||
renderer = ::Redcarpet::Render::HTML.new(hard_wrap: true) | ||
::Redcarpet::Markdown.new(renderer, lax_spacing: true, fenced_code_blocks: true, hard_wrap: true) | ||
end | ||
end | ||
end | ||
end | ||
``` | ||
|
||
<Option name="`spell_checker`"> | ||
Toggles the editor's spell checker option. | ||
### In the controller | ||
|
||
```ruby | ||
field :description, as: :markdown, spell_checker: true | ||
module Avo | ||
class MarkdownPreviewsController < ApplicationController | ||
def create | ||
# fetch the resource to get some information off of it | ||
resource_class = Avo.resource_manager.get_resource_by_name(params[:resource_class]) | ||
# initialize it | ||
resource = resource_class.new view: :edit | ||
# run field detection | ||
resource.detect_fields | ||
# fetch the field | ||
field = resource.get_field(params[:field_id]) | ||
# render the result | ||
@result = field.parser.render(params[:body]) | ||
end | ||
end | ||
end | ||
``` | ||
|
||
<!-- @include: ./../common/default_boolean_false.md--> | ||
</Option> | ||
### In the `ShowFieldComponent` | ||
|
||
<!-- ## Enable spell checker --> | ||
```ruby | ||
# app/components/avo/fields/markdown_field/show_component.rb | ||
|
||
class Avo::Fields::MarkdownField::ShowComponent < Avo::Fields::ShowComponent | ||
def parsed_body | ||
renderer = Redcarpet::Render::HTML.new(hard_wrap: true) | ||
parser = Redcarpet::Markdown.new(renderer, lax_spacing: true, fenced_code_blocks: true, hard_wrap: true) | ||
parser.render(@field.value) | ||
end | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes