ponkotsu-md-editor 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+
2
+ @theme {
3
+ --accent-color: #007bff; /* 例: ブルー */
4
+ --accent-color-hover: #0056b3; /* 例: ダークブルー */
5
+ --preview-bg: #363636; /* 例: ダークグレー */
6
+ --text-primary: #ffffff; /* 例: ホワイト */
7
+ }
8
+
9
+ .editor-container {
10
+ position: relative;
11
+ }
12
+
13
+ #editor_content {
14
+ position: relative;
15
+ /* エディターのスタイルは既存のまま */
16
+ overflow: hidden; /* はみ出し防止 */
17
+ height: calc(24 * 20px);
18
+ }
19
+
20
+ #editor_content_placeholder {
21
+ position: absolute;
22
+ top: -17px; /* editor_contentのpaddingに合わせて調整 */
23
+ left: 13px; /* editor_contentのpaddingに合わせて調整 */
24
+ color: #999;
25
+ pointer-events: none;
26
+ z-index: 1;
27
+ white-space: pre-line; /* 改行を表示 */
28
+ /* デフォルトで表示 */
29
+ display: block;
30
+ max-height: calc(24 * 20px);
31
+ overflow: hidden;
32
+ }
33
+
34
+ /* emptyクラスがない時(コンテンツがある時)にプレースホルダーを隠す */
35
+ #editor_content:not(.empty) ~ #editor_content_placeholder {
36
+ display: none;
37
+ }
38
+
39
+ /*!* フォーカス時も隠す *!*/
40
+ /*#editor_content:focus ~ #editor_content_placeholder {*/
41
+ /* display: none;*/
42
+ /*}*/
@@ -0,0 +1,102 @@
1
+ <%
2
+ _options = {
3
+ form: form,
4
+ content: content,
5
+ lang: options[:lang] || :en,
6
+ preview: options[:preview] || true,
7
+ tools: options[:tools] || %w[bold italic strikethrough heading1 heading2 heading3 heading4 heading5 heading6 unordered_list ordered_list check_list blockquote link image code code_block table horizontal_rule],
8
+ placeholder: locals[:placeholder] || case lang
9
+ when :en
10
+ <<-EOS
11
+ EOS
12
+ when :ja
13
+ <<-EOS
14
+ Markdownで記事を書いてください...
15
+
16
+ 例:
17
+ # 見出し1
18
+ ## 見出し2
19
+ ### 見出し3
20
+
21
+ **太字** *斜体* ~~打ち消し線~~
22
+
23
+ - 箇条書きリスト
24
+ - リストアイテム2
25
+
26
+ 1. 番号付きリスト
27
+ 2. 番号付きアイテム2
28
+
29
+ - [ ] 未完了タスク
30
+ - [x] 完了済みタスク
31
+
32
+ > 引用ブロック
33
+ > 複数行の引用文
34
+
35
+ [リンク](https://example.com)
36
+ ![画像](画像URL)
37
+
38
+ `インラインコード`
39
+
40
+ ```
41
+ コードブロック
42
+ function example() {
43
+ return 'Hello';
44
+ }
45
+ ```
46
+
47
+ | 列1 | 列2 | 列3 |
48
+ |-----|-----|-----|
49
+ | セル1 | セル2 | セル3 |
50
+
51
+ ---
52
+
53
+ 詳しい記法はツールバーのボタンをご活用ください。
54
+ EOS
55
+ else
56
+ "Not supported language"
57
+ end
58
+ }
59
+ %>
60
+
61
+ <div class="markdown-editor">
62
+ <%= render "toolbar", options: _options %>
63
+ <%= render "input_area", options: _options %>
64
+ </div>
65
+ <div class="form-text medium-contrast-text">
66
+ <strong><%= case lang
67
+ when :en
68
+ "You can write in Markdown."
69
+ when :ja
70
+ "Markdownで記載できます。"
71
+ else
72
+ "N/A"
73
+ end %></strong>
74
+ <a href="#" data-bs-toggle="modal" data-bs-target="#markdownHelpModal" class="text-decoration-none" style="color: var(--accent-color);">
75
+ <%= case lang
76
+ when :en
77
+ "Writing Guide"
78
+ when :ja
79
+ "書き方ガイド"
80
+ else
81
+ "N/A"
82
+ end %>
83
+ </a> |
84
+ <strong><%= case lang
85
+ when :en
86
+ "Keyboard Shortcuts"
87
+ when :ja
88
+ "キーボードショートカット"
89
+ else
90
+ "N/A"
91
+ end %>:</strong>
92
+ <%= case lang
93
+ when :en
94
+ "Ctrl+B (Bold), Ctrl+I (Italic), Ctrl+K (Link), Tab (Indent)"
95
+ when :ja
96
+ "Ctrl+B (太字), Ctrl+I (斜体), Ctrl+K (リンク), Tab (インデント)"
97
+ else
98
+ "N/A"
99
+ end %>
100
+ </div>
101
+
102
+ <%= javascript_include_tag 'markdown_editor' %>
@@ -0,0 +1,22 @@
1
+ <%
2
+ form = locals[:form]
3
+ content = locals[:content]
4
+ placeholder = locals[:placeholder]
5
+ %>
6
+
7
+ <div class="editor-container">
8
+ <div id="editor_content"
9
+ contenteditable="true"
10
+ data-field="content"
11
+ class="form-control markdown-textarea">
12
+ <%= raw content %>
13
+ </div>
14
+
15
+ <div id="editor_content_placeholder">
16
+ <%= placeholder %>
17
+ </div>
18
+
19
+ <%= form.hidden_field :content, id: "content_hidden_field" %>
20
+
21
+ <%= render "preview_area" %>
22
+ </div>
@@ -0,0 +1,3 @@
1
+ <div class="markdown-preview" id="markdownPreview"
2
+ style="display: none; min-height: 500px; padding: 1rem; background-color: var(--preview-bg); border: 1px solid var(--border-color); border-radius: 0.375rem; color: var(--text-primary);">
3
+ </div>
@@ -0,0 +1,150 @@
1
+ <%
2
+ enable_bold = options[:tools].include?('bold')
3
+ enable_italic = options[:tools].include?('italic')
4
+ enable_strikethrough = options[:tools].include?('strikethrough')
5
+ enable_heading1 = options[:tools].include?('heading1')
6
+ enable_heading2 = options[:tools].include?('heading2')
7
+ enable_heading3 = options[:tools].include?('heading3')
8
+ enable_heading4 = options[:tools].include?('heading4')
9
+ enable_heading5 = options[:tools].include?('heading5')
10
+ enable_heading6 = options[:tools].include?('heading6')
11
+ enable_unordered_list = options[:tools].include?('unordered_list')
12
+ enable_ordered_list = options[:tools].include?('ordered_list')
13
+ enable_check_list = options[:tools].include?('check_list')
14
+ enable_blockquote = options[:tools].include?('blockquote')
15
+ enable_link = options[:tools].include?('link')
16
+ enable_image = options[:tools].include?('image')
17
+ enable_code = options[:tools].include?('code')
18
+ enable_code_block = options[:tools].include?('code_block')
19
+ enable_table = options[:tools].include?('table')
20
+ enable_horizontal_rule = options[:tools].include?('horizontal_rule')
21
+ enable_preview = options[:preview]
22
+ %>
23
+
24
+ <div class="editor-toolbar mb-2">
25
+ <div class="btn-group btn-group-sm" role="group">
26
+ <% if enable_bold %>
27
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('**', '**')" title="太字 (Ctrl+B)">
28
+ <i class="bi bi-type-bold"></i>
29
+ </button>
30
+ <% end %>
31
+
32
+ <% if enable_italic %>
33
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('*', '*')" title="斜体 (Ctrl+I)">
34
+ <i class="bi bi-type-italic"></i>
35
+ </button>
36
+ <% end %>
37
+
38
+ <% if enable_strikethrough %>
39
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('~~', '~~')" title="打ち消し線">
40
+ <i class="bi bi-type-strikethrough"></i>
41
+ </button>
42
+ <% end %>
43
+
44
+ <% if enable_code %>
45
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('`', '`')" title="インラインコード">
46
+ <i class="bi bi-code"></i>
47
+ </button>
48
+ <% end %>
49
+ </div>
50
+ <div class="btn-group btn-group-sm ms-2" role="group">
51
+ <% if enable_heading1 %>
52
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('# ', '')" title="見出し1">
53
+ <i class="bi bi-type-h1"></i>
54
+ </button>
55
+ <% end %>
56
+
57
+ <% if enable_heading2 %>
58
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('## ', '')" title="見出し2">
59
+ <i class="bi bi-type-h2"></i>
60
+ </button>
61
+ <% end %>
62
+
63
+ <% if enable_heading3 %>
64
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('### ', '')" title="見出し3">
65
+ <i class="bi bi-type-h3"></i>
66
+ </button>
67
+ <% end %>
68
+
69
+ <% if enable_heading4 %>
70
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('#### ', '')" title="見出し4">
71
+ <i class="bi bi-type-h4"></i>
72
+ </button>
73
+ <% end %>
74
+
75
+ <% if enable_heading5 %>
76
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('##### ', '')" title="見出し5">
77
+ <i class="bi bi-type-h5"></i>
78
+ </button>
79
+ <% end %>
80
+
81
+ <% if enable_heading6 %>
82
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('###### ', '')" title="見出し6">
83
+ <i class="bi bi-type-h6"></i>
84
+ </button>
85
+ <% end %>
86
+ </div>
87
+ <div class="btn-group btn-group-sm ms-2" role="group">
88
+ <% if enable_link %>
89
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('[', '](URL)')" title="リンク">
90
+ <i class="bi bi-link-45deg"></i>
91
+ </button>
92
+ <% end %>
93
+
94
+ <% if enable_unordered_list %>
95
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('- ', '')" title="箇条書きリスト">
96
+ <i class="bi bi-list-ul"></i>
97
+ </button>
98
+ <% end %>
99
+
100
+ <% if enable_ordered_list %>
101
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('1. ', '')" title="番号付きリスト">
102
+ <i class="bi bi-list-ol"></i>
103
+ </button>
104
+ <% end %>
105
+
106
+ <% if enable_code_block %>
107
+ <button type="button" class="btn btn-outline-secondary" onclick="insertCode()" title="コードスパンまたはコードブロック">
108
+ <i class="bi bi-code-square"></i>
109
+ </button>
110
+ <% end %>
111
+
112
+ <% if enable_blockquote %>
113
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('> ', '')" title="引用">
114
+ <i class="bi bi-quote"></i>
115
+ </button>
116
+ <% end %>
117
+
118
+ <% if enable_image %>
119
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('![', '](画像URL)')" title="画像">
120
+ <i class="bi bi-image"></i>
121
+ </button>
122
+ <% end %>
123
+
124
+ <% if enable_table %>
125
+ <button type="button" class="btn btn-outline-secondary" onclick="insertTable()" title="テーブル">
126
+ <i class="bi bi-table"></i>
127
+ </button>
128
+ <% end %>
129
+
130
+ <% if enable_horizontal_rule %>
131
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('\n---\n', '')" title="水平線">
132
+ <i class="bi bi-dash-lg"></i>
133
+ </button>
134
+ <% end %>
135
+
136
+ <% if enable_check_list %>
137
+ <button type="button" class="btn btn-outline-secondary" onclick="insertMarkdown('- [ ] ', '')" title="チェックボックス">
138
+ <i class="bi bi-check-square"></i>
139
+ </button>
140
+ <% end %>
141
+ </div>
142
+
143
+ <% if enable_preview %>
144
+ <div class="btn-group btn-group-sm ms-2" role="group">
145
+ <button type="button" class="btn btn-outline-primary" onclick="togglePreview()" id="previewToggle">
146
+ <i class="bi bi-eye"></i> プレビュー
147
+ </button>
148
+ </div>
149
+ <% end %>
150
+ </div>
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PonkotsuMdEditor
4
+ # Rails Engine for PonkotsuMdEditor gem
5
+ # This engine integrates the Markdown editor functionality into Rails applications
6
+ # by providing views, assets, and helper methods for rendering the editor components
7
+ class Engine < ::Rails::Engine
8
+ # Isolate this engine's namespace to prevent conflicts with the host application
9
+ isolate_namespace PonkotsuMdEditor
10
+
11
+ # Initialize helper methods to be available in ActionView
12
+ # This makes PonkotsuMdEditor::Helpers methods accessible in Rails views
13
+ initializer "ponkotsu_md_editor.helpers" do
14
+ ActionView::Base.include PonkotsuMdEditor::Helpers
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "editor/"
4
+
5
+ module PonkotsuMdEditor
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+
9
+ # Helper methods for rendering Markdown editor components in Rails views
10
+ # This module provides view helpers that can be used in ERB templates
11
+ # to integrate the PonkotsuMdEditor functionality
12
+ module Helpers
13
+ # Renders a Markdown editor component with the specified content and options
14
+ #
15
+ # @param content [String] Initial content to display in the editor (default: "")
16
+ # @param options [Hash] Configuration options for the editor (default: {})
17
+ # @return [String] Rendered HTML for the Markdown editor
18
+ #
19
+ # Example usage in a Rails view:
20
+ # <%= markdown_editor(form, :content, {
21
+ # lang: :en,
22
+ # preview: true,
23
+ # tools: [ :bold, :italic, :strikethrough ],
24
+ # placeholder: "This is Placeholder."
25
+ # }) %>
26
+ def markdown_editor(form, content = "", options = {})
27
+ render "editor", content: content, form: form, options: options
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ponkotsu
4
+ module Md
5
+ module Editor
6
+ VERSION = "0.1.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module Ponkotsu
2
+ module Md
3
+ module Editor
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ponkotsu-md-editor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - dhq_boiler
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 8.0.2
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 8.0.2
26
+ description: There is a bug in Chrome where entering large amounts of text into a
27
+ textarea element causes significant slowness (https://issues.chromium.org/issues/341564372).
28
+ This gem serves as a countermeasure for that issue.
29
+ email:
30
+ - dhq_boiler@live.jp
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - CHANGELOG.md
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - app/assets/javascripts/markdown_editor.js
40
+ - app/assets/stylesheets/markdown_editor.css
41
+ - app/ponkotsu/md/editor/_editor.html.erb
42
+ - app/ponkotsu/md/editor/_input_area.html.erb
43
+ - app/ponkotsu/md/editor/_preview_area.html.erb
44
+ - app/ponkotsu/md/editor/_toolbar.html.erb
45
+ - lib/ponkotsu/md/editor/engine.rb
46
+ - lib/ponkotsu/md/editor/helpers.rb
47
+ - lib/ponkotsu/md/editor/version.rb
48
+ - sig/ponkotsu/md/editor.rbs
49
+ homepage: https://github.com/dhq-boiler/ponkotsu-md-editor
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/dhq-boiler/ponkotsu-md-editor
54
+ source_code_uri: https://github.com/dhq-boiler/ponkotsu-md-editor
55
+ rubygems_mfa_required: 'true'
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 3.4.5
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.6.9
71
+ specification_version: 4
72
+ summary: A gem that provides a fun Markdown editor.
73
+ test_files: []