Install and use ToastUi markdown editor
Replace all usages of pagedown-bootstrap editor with the new editor. Add styles to ensure the editor preview matches the final output.
This commit is contained in:

committed by
Dominic Sauer

parent
96f5f1f8d7
commit
9c71c6667a
@ -1,41 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PagedownFormBuilder < ActionView::Helpers::FormBuilder
|
||||
def pagedown(method, args)
|
||||
def pagedown(method, args = {})
|
||||
# Adopt simple form builder to work with form_for
|
||||
@attribute_name = method
|
||||
@input_html_options = args[:input_html]
|
||||
|
||||
@template.capture do
|
||||
@template.concat wmd_button_bar
|
||||
@template.concat wmd_textarea
|
||||
@template.concat wmd_preview if show_wmd_preview?
|
||||
@template.concat form_textarea
|
||||
@template.concat @template.tag.div(class: 'markdown-editor', data: {behavior: 'markdown-editor-widget', id: label_target})
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def wmd_button_bar
|
||||
@template.tag.div(nil, id: "wmd-button-bar-#{base_id}")
|
||||
end
|
||||
|
||||
def wmd_textarea
|
||||
def form_textarea
|
||||
@template.text_area @object_name, @attribute_name,
|
||||
**@input_html_options,
|
||||
class: 'form-control wmd-input',
|
||||
id: "wmd-input-#{base_id}"
|
||||
end
|
||||
|
||||
def wmd_preview
|
||||
@template.tag.div(nil, class: 'wmd-preview',
|
||||
id: "wmd-preview-#{base_id}")
|
||||
end
|
||||
|
||||
def show_wmd_preview?
|
||||
@input_html_options[:preview].present?
|
||||
**(@input_html_options || {}),
|
||||
id: label_target,
|
||||
class: 'd-none'
|
||||
end
|
||||
|
||||
def base_id
|
||||
options[:pagedown_id_suffix] || @attribute_name
|
||||
options[:markdown_id_suffix] || @attribute_name
|
||||
end
|
||||
|
||||
def label_target
|
||||
"markdown-input-#{base_id}"
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user