ponkotsu-md-editor 0.2.7 → 0.2.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 814cbaf6bbcf3af21f91a4cc339ad7e72a5326e375a319382909874e37235f2b
4
- data.tar.gz: e99c17a575cb1bca23fce8ca35c7a29cff4b9fb05d566a4c8f66c54fa35da5f7
3
+ metadata.gz: f567d49c9ad448e6a591ba7c3db1d140769a37a24af287c3123f2353a4969be1
4
+ data.tar.gz: 2209e8d17248ef43460312a4bdbc3d4ab7bf027aea2377cff2d7d9a064e00905
5
5
  SHA512:
6
- metadata.gz: 217101a8e13d51a333740063c83ecb5c447a13e546bcea5483bc964ceaa634ef9595636cac83e79fd109658d5ce6719277e8b08b6209df6dfd74a7b48430f79c
7
- data.tar.gz: 808a20178b3f5345b7b908beca656fa9f38b8faa9eb91c0df56fb2b3c594beb33d7836cfff304ad8c5123e59cea4e7b5875459e117107ec0b96774ce960ba6c0
6
+ metadata.gz: 8e4364e50f2e63dd037ac17611eec7fcdde9a9b7d936f936a3c60d95566a19c4ccdf94b6bc89c6b69a239011e5dff926110aaa7e2c56fe1b161dc1953cdfea58
7
+ data.tar.gz: af2cb64d0b3e939358133658ecf13e4dd43a0fc2922855d9b05f5e15ad8ded9d86b8f00746c45bdaa625f0508a0ed2dacfff0e7656397fec8ff74c0da276e2e5
data/README.md CHANGED
@@ -1,39 +1,113 @@
1
- # Ponkotsu::Md::Editor
1
+ # PonkotsuMdEditor
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ [![Gem Version](https://badge.fury.io/rb/ponkotsu-md-editor.svg)](https://badge.fury.io/rb/ponkotsu-md-editor)
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ponkotsu/md/editor`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ PonkotsuMdEditorは、Railsアプリケーション向けのシンプルなMarkdownエディタGemです。
6
6
 
7
- ## Installation
7
+ PonkotsuMdEditor is a simple Markdown editor gem for Rails applications.
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
9
 
11
- Install the gem and add to the application's Gemfile by executing:
10
+ Markdownテキストベースの編集エリア、プレビュー、ツールバーなどを備え、簡単に組み込むことができます。
11
+
12
+ It provides a markdown text-based editing area, preview, toolbar, and can be easily integrated into your app.
13
+
14
+ ## 特徴/Features
15
+ - シンプルなUIで直感的にMarkdown編集
16
+ - Simple UI for intuitive Markdown editing
17
+ - プレビュー機能付き
18
+ - Includes preview feature
19
+ - JavaScript/CSSアセット同梱
20
+ - Bundled with JavaScript/CSS assets
21
+ - Railsビューに簡単組み込み
22
+ - Easy integration into Rails views
23
+ - textareaタグを使用していないので、Chromium系ブラウザにおける多量のテキスト入力でのパフォーマンス問題を回避(参照:https://issues.chromium.org/issues/341564372)
24
+ - Does not use textarea tag, so avoids performance issues with large text input on Chromium browsers (see: https://issues.chromium.org/issues/341564372)
25
+
26
+ ## インストール/Installation
27
+
28
+ Gemfileに以下を追加してください。
29
+
30
+ Add the following to your Gemfile:
31
+
32
+ ```ruby
33
+ gem 'ponkotsu-md-editor'
34
+ ```
35
+
36
+ その後、以下を実行します。
37
+
38
+ Then run:
12
39
 
13
40
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
41
+ bundle install
15
42
  ```
16
43
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
44
+ ## アセットについて/About Assets
45
+
46
+ 本GemはRailsエンジンとしてアセット(JavaScript/CSS)を自動でプリコンパイル・ロードします。
47
+
48
+ This gem automatically precompiles and loads assets (JavaScript/CSS) as a Rails engine.
49
+
50
+
51
+ 特別な設定や`application.js`/`application.css`へのrequire追加は不要です。
52
+
53
+ No special settings or require statements in `application.js`/`application.css` are needed.
54
+
55
+
56
+ **本番環境やプリコンパイルが必要な環境では、以下のコマンドを実行してください。**
57
+
58
+ **In production or environments requiring precompilation, run the following command:**
18
59
 
19
60
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
61
+ rails assets:precompile
62
+ ```
63
+
64
+ ## 使い方/Usage
65
+
66
+ ### ビューへの組み込み例(ERB)/Example of embedding in a view (ERB)
67
+
68
+ ```erb
69
+ <%= form_with model: @article, local: true, multipart: true, class: "article-form" do |form| %>
70
+
71
+ <%= markdown_editor(form, :content, @article.content, options: {
72
+ lang: :ja,
73
+ preview: true,
74
+ 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]
75
+ }) %>
76
+
77
+ <% end %>
78
+ ```
79
+
80
+ ### コントローラでのパラメータ受け取り/Receiving parameters in controller
81
+
82
+ hiddenフィールドにMarkdownテキストが格納されます。あとは良しなに。
83
+
84
+ The markdown text is stored in a hidden field. Handle as needed.
85
+
86
+ ```ruby
87
+ params[:model][:content] # => Markdown text
21
88
  ```
22
89
 
23
- ## Usage
90
+ ## 開発・テスト/Development & Testing
91
+
92
+ このgemは主にRailsのview要素(ヘルパー、パーシャル、JS/CSSアセット)を提供するため、RSpec等の通常のテストではUIや動作の自動テストは困難です。
93
+
94
+ This gem mainly provides Rails view elements (helpers, partials, JS/CSS assets), so UI and behavior cannot be automatically tested with standard RSpec, etc.
95
+
96
+
97
+ - UIやエディタの動作確認には、手動テストを推奨します。
98
+ - For UI/editor behavior, manual testing is recommended.
24
99
 
25
- TODO: Write usage instructions here
100
+ ## コントリビュート/Contributing
26
101
 
27
- ## Development
102
+ バグ報告・プルリクエストは歓迎します。
28
103
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
104
+ Bug reports and pull requests are welcome.
30
105
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
106
 
33
- ## Contributing
107
+ GitHub repository: https://github.com/dhq-boiler/ponkotsu-md-editor
34
108
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ponkotsu-md-editor.
109
+ ## ライセンス/License
36
110
 
37
- ## License
111
+ このGemは[MITライセンス](https://opensource.org/licenses/MIT)のもとで公開されています。
38
112
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
113
+ This gem is released under the [MIT License](https://opensource.org/licenses/MIT).
@@ -27,6 +27,23 @@
27
27
  textarea.addEventListener('blur', syncToHidden);
28
28
  // 初期化時にも同期
29
29
  syncToHidden();
30
+
31
+ // 初期状態でプレースホルダを表示するための空要素チェック
32
+ function updatePlaceholderVisibility() {
33
+ // <br>のみの場合も空とみなす
34
+ if (textarea.innerHTML.trim() === '&nbsp;' || textarea.innerHTML.trim() === '' || textarea.innerHTML.trim() === '\<br\>') {
35
+ textarea.classList.add('empty');
36
+ } else {
37
+ textarea.classList.remove('empty');
38
+ }
39
+ }
40
+
41
+ // 初期状態をチェック
42
+ updatePlaceholderVisibility();
43
+
44
+ // 入力時にプレースホルダの表示/非表示を制御
45
+ textarea.addEventListener('input', updatePlaceholderVisibility);
46
+ textarea.addEventListener('blur', updatePlaceholderVisibility);
30
47
  }
31
48
  } else {
32
49
  callback();
@@ -1,8 +1,9 @@
1
-
2
1
  @theme {
3
2
  --accent-color: #007bff; /* 例: ブルー */
4
3
  --accent-color-hover: #0056b3; /* 例: ダークブルー */
4
+ --accent-pink: #e83e8c; /* 追加: ピンク */
5
5
  --preview-bg: #363636; /* 例: ダークグレー */
6
+ --border-color: #444; /* 追加: プレビュー枠線色 */
6
7
  --text-primary: #ffffff; /* 例: ホワイト */
7
8
  }
8
9
 
@@ -39,4 +40,243 @@
39
40
  /*!* フォーカス時も隠す *!*/
40
41
  /*#editor_content:focus ~ #editor_content_placeholder {*/
41
42
  /* display: none;*/
42
- /*}*/
43
+ /*}*/
44
+
45
+ .ponkotsu-md-editor-form-text {
46
+ font-size: 0.875em;
47
+ color: #6c757d;
48
+ margin-top: 0.25rem;
49
+ }
50
+
51
+ .ponkotsu-md-editor-medium-contrast-text {
52
+ color: #495057;
53
+ }
54
+
55
+ .ponkotsu-md-editor-text-decoration-none {
56
+ text-decoration: none;
57
+ }
58
+
59
+ .ponkotsu-md-editor-form-control {
60
+ display: block;
61
+ width: 100%;
62
+ min-height: 120px;
63
+ padding: 0.5em 0.75em;
64
+ font-size: 1em;
65
+ line-height: 1.5;
66
+ color: #212529;
67
+ background-color: #fff;
68
+ background-clip: padding-box;
69
+ border: 1px solid #ced4da;
70
+ border-radius: 0.375rem;
71
+ transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
72
+ box-sizing: border-box;
73
+ }
74
+ .ponkotsu-md-editor-form-control:focus {
75
+ outline: none;
76
+ border-color: var(--accent-color, #007bff);
77
+ box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
78
+ }
79
+
80
+ .ponkotsu-md-editor-markdown-textarea {
81
+ min-height: 240px;
82
+ resize: vertical;
83
+ font-family: inherit;
84
+ background: none;
85
+ box-shadow: none;
86
+ }
87
+
88
+ .ponkotsu-md-editor-popover-modal {
89
+ background: #222;
90
+ color: #fff;
91
+ border-radius: 8px;
92
+ box-shadow: 0 0 20px #000a;
93
+ max-width: 900px;
94
+ width: 80vw;
95
+ }
96
+ .ponkotsu-md-editor-popover-header {
97
+ display: flex;
98
+ align-items: center;
99
+ justify-content: space-between;
100
+ padding: 1rem;
101
+ border-bottom: 1px solid #444;
102
+ }
103
+ .ponkotsu-md-editor-popover-title {
104
+ font-size: 1.25rem;
105
+ font-weight: bold;
106
+ }
107
+ .ponkotsu-md-editor-btn-close {
108
+ background: none;
109
+ border: none;
110
+ font-size: 1.5rem;
111
+ color: #fff;
112
+ cursor: pointer;
113
+ }
114
+ .ponkotsu-md-editor-popover-body {
115
+ padding: 1.5rem;
116
+ max-height: 70vh;
117
+ overflow-y: auto;
118
+ }
119
+ .ponkotsu-md-editor-nav {
120
+ display: flex;
121
+ border-bottom: 1px solid #444;
122
+ margin-bottom: 1rem;
123
+ list-style: none;
124
+ padding-left: 0;
125
+ }
126
+ .ponkotsu-md-editor-nav-tabs .ponkotsu-md-editor-nav-link {
127
+ border: none;
128
+ background: none;
129
+ color: #fff;
130
+ padding: 0.5rem 1rem;
131
+ cursor: pointer;
132
+ border-radius: 0.375rem 0.375rem 0 0;
133
+ margin-right: 0.25rem;
134
+ }
135
+ .ponkotsu-md-editor-nav-link.active {
136
+ background: #333;
137
+ color: var(--accent-color, #007bff);
138
+ font-weight: bold;
139
+ }
140
+ .ponkotsu-md-editor-nav-fill {
141
+ flex: 1 1 auto;
142
+ }
143
+ .ponkotsu-md-editor-nav-item {
144
+ flex: 1 1 0;
145
+ text-align: center;
146
+ }
147
+ .ponkotsu-md-editor-tab-content {
148
+ margin-top: 1rem;
149
+ }
150
+ .ponkotsu-md-editor-tab-pane {
151
+ display: none;
152
+ }
153
+ .ponkotsu-md-editor-tab-pane.active,
154
+ .ponkotsu-md-editor-tab-pane.show {
155
+ display: block;
156
+ }
157
+ .ponkotsu-md-editor-table-responsive {
158
+ overflow-x: auto;
159
+ }
160
+ .ponkotsu-md-editor-table {
161
+ width: 100%;
162
+ border-collapse: collapse;
163
+ margin-bottom: 1rem;
164
+ color: #fff;
165
+ background: #222;
166
+ }
167
+ .ponkotsu-md-editor-table th,
168
+ .ponkotsu-md-editor-table td {
169
+ border: 1px solid #444;
170
+ padding: 0.5rem;
171
+ }
172
+ .ponkotsu-md-editor-table-dark {
173
+ background: #222;
174
+ }
175
+ .ponkotsu-md-editor-table-striped tbody tr:nth-child(odd) {
176
+ background: #2a2a2a;
177
+ }
178
+ .ponkotsu-md-editor-table-sm th,
179
+ .ponkotsu-md-editor-table-sm td {
180
+ padding: 0.25rem 0.5rem;
181
+ font-size: 0.9em;
182
+ }
183
+ .ponkotsu-md-editor-table-bordered th,
184
+ .ponkotsu-md-editor-table-bordered td {
185
+ border: 1px solid #666;
186
+ }
187
+ .ponkotsu-md-editor-alert {
188
+ padding: 1rem;
189
+ border-radius: 0.375rem;
190
+ margin-top: 1.5rem;
191
+ margin-bottom: 1rem;
192
+ background: #e9f7fd;
193
+ color: #222;
194
+ border: 1px solid #b6e2f7;
195
+ }
196
+ .ponkotsu-md-editor-alert-info {
197
+ background: #e9f7fd;
198
+ color: #222;
199
+ border-color: #b6e2f7;
200
+ }
201
+ .ponkotsu-md-editor-mt-4 {
202
+ margin-top: 1.5rem;
203
+ }
204
+ .ponkotsu-md-editor-high-contrast-text {
205
+ color: #fff;
206
+ font-weight: bold;
207
+ }
208
+
209
+ .markdown-preview,
210
+ .ponkotsu-md-editor-markdown-preview {
211
+ min-height: 500px;
212
+ padding: 1rem;
213
+ background-color: var(--preview-bg);
214
+ border: 1px solid var(--border-color);
215
+ border-radius: 0.375rem;
216
+ color: var(--text-primary);
217
+ word-break: break-word;
218
+ overflow-x: auto;
219
+ }
220
+
221
+ .ponkotsu-md-editor-toolbar {
222
+ display: flex;
223
+ flex-wrap: wrap;
224
+ align-items: center;
225
+ margin-bottom: 0.5rem;
226
+ }
227
+ .ponkotsu-md-editor-btn-group {
228
+ display: inline-flex;
229
+ align-items: center;
230
+ margin-right: 0.5rem;
231
+ }
232
+ .ponkotsu-md-editor-btn-group-sm > .ponkotsu-md-editor-btn {
233
+ font-size: 0.9em;
234
+ padding: 0.25em 0.5em;
235
+ }
236
+ .ponkotsu-md-editor-btn {
237
+ display: inline-block;
238
+ font-weight: 400;
239
+ color: #222;
240
+ text-align: center;
241
+ vertical-align: middle;
242
+ user-select: none;
243
+ background-color: #fff;
244
+ border: 1px solid #ced4da;
245
+ padding: 0.375rem 0.75rem;
246
+ font-size: 1em;
247
+ line-height: 1.5;
248
+ border-radius: 0.375rem;
249
+ transition: color 0.15s, background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
250
+ margin-right: 0.2em;
251
+ cursor: pointer;
252
+ }
253
+ .ponkotsu-md-editor-btn:last-child {
254
+ margin-right: 0;
255
+ }
256
+ .ponkotsu-md-editor-btn-outline {
257
+ background-color: #fff;
258
+ color: #222;
259
+ border: 1px solid #ced4da;
260
+ }
261
+ .ponkotsu-md-editor-btn-outline:hover,
262
+ .ponkotsu-md-editor-btn-outline:focus {
263
+ background-color: #f0f0f0;
264
+ border-color: var(--accent-color, #007bff);
265
+ color: var(--accent-color, #007bff);
266
+ }
267
+ .ponkotsu-md-editor-btn-outline-primary {
268
+ background-color: #fff;
269
+ color: var(--accent-color, #007bff);
270
+ border: 1px solid var(--accent-color, #007bff);
271
+ }
272
+ .ponkotsu-md-editor-btn-outline-primary:hover,
273
+ .ponkotsu-md-editor-btn-outline-primary:focus {
274
+ background-color: var(--accent-color, #007bff);
275
+ color: #fff;
276
+ }
277
+ .ponkotsu-md-editor-mb-2 {
278
+ margin-bottom: 0.5rem;
279
+ }
280
+ .ponkotsu-md-editor-ms-2 {
281
+ margin-left: 0.5rem;
282
+ }
@@ -61,7 +61,7 @@
61
61
  <%= render "ponkotsu_md_editor/toolbar", locals: { options: _options } %>
62
62
  <%= render "ponkotsu_md_editor/input_area", locals: { form: _form, attribute: locals[:attribute], content: locals[:content], options: _options } %>
63
63
  </div>
64
- <div class="form-text medium-contrast-text">
64
+ <div class="ponkotsu-md-editor-form-text ponkotsu-md-editor-medium-contrast-text">
65
65
  <strong><%= case _options[:lang]
66
66
  when :en
67
67
  "You can write in Markdown."
@@ -70,7 +70,7 @@
70
70
  else
71
71
  "N/A"
72
72
  end %></strong>
73
- <a href="#" data-bs-toggle="modal" data-bs-target="#markdownHelpModal" class="text-decoration-none" style="color: var(--accent-color);">
73
+ <a href="#" id="markdownHelpGuideLink" popovertarget="markdownHelpPopover" class="ponkotsu-md-editor-text-decoration-none" style="color: var(--accent-color);">
74
74
  <%= case _options[:lang]
75
75
  when :en
76
76
  "Writing Guide"
@@ -97,5 +97,5 @@
97
97
  "N/A"
98
98
  end %>
99
99
  </div>
100
-
100
+ <%= render "ponkotsu_md_editor/markdown_help_modal", locals: { options: _options } %>
101
101
  <%= javascript_include_tag 'markdown_editor' %>
@@ -7,7 +7,7 @@
7
7
  <div id="editor_content"
8
8
  contenteditable="true"
9
9
  data-field="content"
10
- class="form-control markdown-textarea">
10
+ class="ponkotsu-md-editor-form-control ponkotsu-md-editor-markdown-textarea">
11
11
  <%
12
12
  def crlf_to_br(text)
13
13
  text.gsub(/\r\n|\r|\n/, "<br>").html_safe