qiita_org 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e8c82431a22c64669538797e28a4063ec88e0716014fec98371f3fa03833fa5
4
- data.tar.gz: 060c5ba8fb541193fec02aa66570300d2b3801e5c3ead68339267d514c1ae36f
3
+ metadata.gz: 9e7a075ad1c16002e53fff794d556f9ce5bb2c6e7d5e37768a37a8deb59f28e9
4
+ data.tar.gz: aad3df025127c3e87d3ccb71a262f28083904d63b12e7371cea4c80cf68ecdf1
5
5
  SHA512:
6
- metadata.gz: fe04ad5ab1e88a6b722b71e705b0e96fd2378bf19a70f3cdc98e6158ca3c52e707586bd2889c483d249fb658660315445f1d0b0d80402a07f1c597f20a71376d
7
- data.tar.gz: e83f076ae7624915c4569f1bc81455882b854d694f0898aab5810825d4653d28356c259657515942c0bc86ea1508f327610fcd228539187ab592f9397d195ba3
6
+ metadata.gz: c4e4645899b5b8ef3cf84b4203b911d3cdc3da1cf3f58d67cc1ca8d64b06f95ada184fe7491102c69fd9d75da91346db01f734ad384fcbac492a9169d81238cf
7
+ data.tar.gz: 72dcab368ce64937c26ed77e89d25face880d71cff3ac9ff5e2797dcdb78023d4d5e6be1a747813426a3851ad6f2a9b9edd7d3bffa9bd4156e8962763b039a48
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qiita_org (0.1.4)
4
+ qiita_org (0.1.8)
5
5
  colorize
6
6
  command_line (> 2.0.0)
7
7
  fileutils
@@ -0,0 +1,313 @@
1
+ ;;; ox-qmd.el --- Qiita Markdown Back-End for Org Export Engine
2
+
3
+ ;; Copyright (C) 2015-2020 0x60DF
4
+
5
+ ;; Author: 0x60DF <0x60DF@gmail.com>
6
+ ;; URL: https://github.com/0x60df/ox-qmd
7
+ ;; Version: 1.0.5
8
+ ;; Package-Requires: ((org "8.0"))
9
+ ;; Keywords: wp
10
+
11
+ ;; This file is not part of GNU Emacs.
12
+
13
+ ;; This program is free software: you can redistribute it and/or modify
14
+ ;; it under the terms of the GNU General Public License as published by
15
+ ;; the Free Software Foundation, either version 3 of the License, or
16
+ ;; (at your option) any later version.
17
+
18
+ ;; This program is distributed in the hope that it will be useful,
19
+ ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ ;; GNU General Public License for more details.
22
+
23
+ ;; You should have received a copy of the GNU General Public License
24
+ ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
25
+
26
+ ;;; Commentary:
27
+
28
+ ;; This library implements a Markdown back-end (qiita flavor) for
29
+ ;; Org exporter, based on `md' back-end and `gfm' back-end.
30
+
31
+ ;; See http://orgmode.org/ for infomation about Org-mode and `md' back-end.
32
+ ;; See http://github.com/larstvei/ox-gfm for information about `gfm' back-end.
33
+
34
+ ;;; Code:
35
+
36
+ (require 'ox-md)
37
+
38
+
39
+ ;;; User-Configurable Variables
40
+
41
+ (defvar ox-qmd-language-keyword-alist '(("emacs-lisp" . "el")))
42
+ (defvar ox-qmd-unfill-paragraph t)
43
+
44
+
45
+
46
+ ;;; Define Back-End
47
+
48
+ (org-export-define-derived-backend 'qmd 'md
49
+ :filters-alist '((:filter-paragraph . org-qmd--unfill-paragraph))
50
+ :menu-entry
51
+ '(?9 "Export to Qiita Markdown"
52
+ ((?0 "To temporary buffer"
53
+ (lambda (a s v b) (org-qmd-export-as-markdown a s v)))
54
+ (?9 "To file" (lambda (a s v b) (org-qmd-export-to-markdown a s v)))
55
+ (?o "To file and open"
56
+ (lambda (a s v b)
57
+ (if a (org-qmd-export-to-markdown t s v)
58
+ (org-open-file (org-qmd-export-to-markdown nil s v)))))
59
+ (?s "To temporary buffer from subtree"
60
+ (lambda (a s v b) (org-qmd-export-as-markdown a t v)))))
61
+ :translate-alist '((headline . org-qmd--headline)
62
+ (inner-template . org-qmd--inner-template)
63
+ (keyword . org--qmd-keyword)
64
+ (strike-through . org-qmd--strike-through)
65
+ (underline . org-qmd--undeline)
66
+ (src-block . org-qmd--src-block)
67
+ (latex-fragment . org-qmd--latex-fragment)
68
+ (latex-environment . org-qmd--latex-environment)
69
+ (table . org-qmd--table)))
70
+
71
+
72
+
73
+ ;;; Filters
74
+
75
+ (defun org-qmd--unfill-paragraph (paragraph backend info)
76
+ "Unfill PARAGRAPH element.
77
+ Remove newline from PARAGRAPH and replace line-break string
78
+ with newline in PARAGRAPH if user-configurable variable
79
+ `ox-qmd-unfill-paragraph' is non-nil."
80
+ (if (and (org-export-derived-backend-p backend 'qmd)
81
+ ox-qmd-unfill-paragraph)
82
+ (concat (replace-regexp-in-string
83
+ " \n" "\n" (replace-regexp-in-string
84
+ "\\([^ ][^ ]\\|[^ ] \\| [^ ]\\)\n" "\\1" paragraph))
85
+ "\n")
86
+ paragraph))
87
+
88
+
89
+
90
+ ;;; Transcode Functions
91
+
92
+ (defun org-qmd--headline (headline contents info)
93
+ "Transcode HEADLINE element into Qiita Markdown format.
94
+ CONTENTS is a content of the HEADLINE. INFO is a plist used
95
+ as a communication channel."
96
+ (let* ((info (copy-sequence info))
97
+ (info (plist-put info :with-toc nil)))
98
+ (org-md-headline headline contents info)))
99
+
100
+
101
+ (defun org-qmd--inner-template (contents info)
102
+ "Return body of document after converting it to Qiita Markdown syntax.
103
+ CONTENTS is the transcoded contents string. INFO is a plist
104
+ holding export options."
105
+ (let* ((info (copy-sequence info))
106
+ (info (plist-put info :with-toc nil)))
107
+ (org-md-inner-template contents info)))
108
+
109
+
110
+ (defun org-qmd--keyword (keyword contents info)
111
+ "Transcode a KEYWORD element into Qiita Markdown format.
112
+ CONTENTS is nil. INFO is a plist used as a communication
113
+ channel."
114
+ (let* ((info (copy-sequence info))
115
+ (info (plist-put info :with-toc nil)))
116
+ (org-html-keyword keyword contents info)))
117
+
118
+
119
+ (defun org-qmd--src-block (src-block contents info)
120
+ "Transcode SRC-BLOCK element into Qiita Markdown format.
121
+ CONTENTS is nil. INFO is a plist used as a communication
122
+ channel."
123
+ (let* ((lang (org-element-property :language src-block))
124
+ (lang (or (cdr (assoc lang ox-qmd-language-keyword-alist)) lang))
125
+ (name (org-element-property :name src-block))
126
+ (code (org-export-format-code-default src-block info))
127
+ (prefix (concat "```" lang (if name (concat ":" name) nil) "\n"))
128
+ (suffix "```"))
129
+ (concat prefix code suffix)))
130
+
131
+
132
+ (defun org-qmd--strike-through (strike-through contents info)
133
+ "Transcode STRIKE-THROUGH element into Qiita Markdown format.
134
+ CONTENTS is a content of the STRIKE-THROUGH. INFO is a plist
135
+ used as a communication channel."
136
+ (format "~~%s~~" contents))
137
+
138
+
139
+ (defun org-qmd--undeline (underline contents info)
140
+ "Transcode UNDERLINE element into Qiita Markdown format.
141
+ CONTENTS is a content of the UNDELINE. INFO is a plist used
142
+ as a communication channel."
143
+ contents)
144
+
145
+
146
+ (defun org-qmd--latex-fragment (latex-fragment contents info)
147
+ "Transcode a LATEX-FRAGMENT element into Qiita Markdown format.
148
+ CONTENTS is nil. INFO is a plist used as a communication
149
+ channel."
150
+ (replace-regexp-in-string
151
+ "^\\\\(\\(.+\\)\\\\)$" "$\\1$"
152
+ (replace-regexp-in-string
153
+ "^\\\\\\[\\(.+\\)\\\\\\]$" "$$\\1$$"
154
+ (let* ((info (copy-sequence info))
155
+ (info (plist-put info :with-latex 'verbatim)))
156
+ (org-html-latex-fragment latex-fragment contents info)))))
157
+
158
+
159
+ (defun org-qmd--latex-environment (latex-environment contents info)
160
+ "Transcode a LATEX-ENVIRONMENT element into Qiita Markdown format.
161
+ CONTENTS is nil. INFO is a plist used as a communication
162
+ channel."
163
+ (replace-regexp-in-string
164
+ "^.*?\\\\begin{.+}.*?$" "```math"
165
+ (replace-regexp-in-string
166
+ "^.*?\\\\end{.+}.*?$" "```"
167
+ (let* ((info (copy-sequence info))
168
+ (info (plist-put info :with-latex 'verbatim)))
169
+ (org-html-latex-environment latex-environment contents info)))))
170
+
171
+
172
+ (defun org-qmd--table (table contents info)
173
+ "Transcode a TABLE element into Qiita Markdown format.
174
+ CONTENTS is a content of the table. INFO is a plist used as
175
+ a communication channel."
176
+ (letrec ((filter (lambda (p l)
177
+ (cond ((null l) l)
178
+ ((funcall p (car l)) (funcall filter p (cdr l)))
179
+ (t (cons (car l) (funcall filter p (cdr l)))))))
180
+ (zip (lambda (&rest l)
181
+ (cond ((null (car l)) (car l))
182
+ (t (cons (mapcar 'car l)
183
+ (apply zip (mapcar 'cdr l))))))))
184
+ (let* ((rows (org-element-map table 'table-row 'identity info))
185
+ (non-rule-rows
186
+ (funcall filter (lambda (row)
187
+ (eq 'rule (org-element-property :type row)))
188
+ rows))
189
+ (alignments (org-element-map (car non-rule-rows) 'table-cell
190
+ (lambda (cell)
191
+ (org-export-table-cell-alignment cell info))
192
+ info))
193
+ (widths (mapcar
194
+ (lambda (column)
195
+ (let ((max-difference
196
+ (apply
197
+ 'max (mapcar
198
+ (lambda (cell)
199
+ (- (org-element-property :end cell)
200
+ (org-element-property :begin cell)))
201
+ column))))
202
+ (if (< max-difference 4) 3 (- max-difference 1))))
203
+ (apply
204
+ zip (mapcar
205
+ (lambda (row)
206
+ (org-element-map row 'table-cell 'identity info))
207
+ non-rule-rows))))
208
+ (joined-rows
209
+ (mapcar (lambda (row)
210
+ (let ((cells
211
+ (org-element-map row 'table-cell 'identity info)))
212
+ (mapconcat
213
+ (lambda (tuple)
214
+ (let ((alignment (car tuple))
215
+ (width (cadr tuple))
216
+ (cell (caddr tuple)))
217
+ (format (format " %%-%ds" (- width 1))
218
+ (or (org-export-data
219
+ (org-element-contents cell)
220
+ info)
221
+ ""))))
222
+ (funcall zip alignments widths cells)
223
+ "|")))
224
+ non-rule-rows))
225
+ (joined-rows-with-delimiter-row
226
+ (cons (car joined-rows)
227
+ (cons (mapconcat
228
+ (lambda (tuple)
229
+ (let ((alignment (car tuple))
230
+ (width (cadr tuple)))
231
+ (format "%s%s%s"
232
+ (if (memq alignment '(left center))
233
+ ":" "-")
234
+ (make-string (- width 2) ?-)
235
+ (if (memq alignment '(right center))
236
+ ":" "-"))))
237
+ (funcall zip alignments widths)
238
+ "|")
239
+ (cdr joined-rows)))))
240
+ (mapconcat (lambda (row) (format "|%s|" row))
241
+ joined-rows-with-delimiter-row
242
+ "\n"))))
243
+
244
+
245
+
246
+ ;;; Interactive function
247
+
248
+ ;;;###autoload
249
+ (defun org-qmd-export-as-markdown (&optional async subtreep visible-only)
250
+ "Export current buffer to a Qiita Markdown buffer.
251
+
252
+ If narrowing is active in the current buffer, only export
253
+ its narrowed part.
254
+
255
+ If a region is active, export that region.
256
+
257
+ A non-nil optional argument ASYNC means the process should
258
+ happen asynchronously. The resulting buffer should be
259
+ accessible through the `org-export-stack' interface.
260
+
261
+ When optional argument SUBTREEP is non-nil, export the
262
+ sub-tree at point, extracting information from the headline
263
+ properties first.
264
+
265
+ When optional argument VISIBLE-ONLY is non-nil, don't export
266
+ contents of hidden elements.
267
+
268
+ Export is done in a buffer named \"*Org QMD Export*\", which
269
+ will be displayed when
270
+ `org-export-show-temporary-export-buffer' is non-nil."
271
+ (interactive)
272
+ (org-export-to-buffer 'qmd "*Org QMD Export*"
273
+ async subtreep visible-only nil nil (lambda () (text-mode))))
274
+
275
+ ;;;###autoload
276
+ (defun org-qmd-convert-region-to-md ()
277
+ "Convert region into Qiita Markdown format.
278
+ Assume the current region has org-mode syntax, and convert
279
+ it to Qiita Markdown. This can be used in any buffer. For
280
+ example, you can write an itemized list in org-mode syntax
281
+ in a Markdown buffer and use this command to convert it."
282
+ (interactive)
283
+ (org-export-replace-region-by 'qmd))
284
+
285
+
286
+ ;;;###autoload
287
+ (defun org-qmd-export-to-markdown (&optional async subtreep visible-only)
288
+ "Export current buffer to a Qiita Markdown file.
289
+
290
+ If narrowing is active in the current buffer, only export
291
+ its narrowed part.
292
+
293
+ If a region is active, export that region.
294
+
295
+ A non-nil optional argument ASYNC means the process should
296
+ happen asynchronously. The resulting file should be
297
+ accessible through the `org-export-stack' interface.
298
+
299
+ When optional argument SUBTREEP is non-nil, export the
300
+ sub-tree at point, extracting information from the headline
301
+ properties first.
302
+
303
+ When optional argument VISIBLE-ONLY is non-nil, don't export
304
+ contents of hidden elements.
305
+
306
+ Return output file's name."
307
+ (interactive)
308
+ (let ((outfile (org-export-output-file-name ".md" subtreep)))
309
+ (org-export-to-file 'qmd outfile async subtreep visible-only)))
310
+
311
+ (provide 'ox-qmd)
312
+
313
+ ;;; ox-qmd.el ends here
@@ -39,7 +39,8 @@ class QiitaPost
39
39
  @conf = JSON.load(File.read(conf_path))
40
40
  @access_token = @conf["access_token"]
41
41
  @teams_url = @conf["teams_url"]
42
- @ox_qmd_load_path = @conf["ox_qmd_load_path"]
42
+ lib = File.expand_path("../../../lib", __FILE__)
43
+ @ox_qmd_load_path = File.join(lib, "qiita_org", "ox-qmd", "ox-qmd") # @conf["ox_qmd_load_path"]
43
44
  end
44
45
 
45
46
  # src.org -> src.md
@@ -1,3 +1,3 @@
1
1
  module QiitaOrg
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiita_org
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenta Yamamoto
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-01 00:00:00.000000000 Z
11
+ date: 2020-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -959,6 +959,7 @@ files:
959
959
  - lib/qiita_org/get_template.rb
960
960
  - lib/qiita_org/hoge.txt
961
961
  - lib/qiita_org/list.rb
962
+ - lib/qiita_org/ox-qmd/ox-qmd.el
962
963
  - lib/qiita_org/post.rb
963
964
  - lib/qiita_org/search_conf_path.rb
964
965
  - lib/qiita_org/template.org
@@ -968,7 +969,7 @@ homepage: https://github.com/yamatoken/qiita_org
968
969
  licenses:
969
970
  - MIT
970
971
  metadata: {}
971
- post_install_message:
972
+ post_install_message:
972
973
  rdoc_options: []
973
974
  require_paths:
974
975
  - lib
@@ -984,7 +985,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
984
985
  version: '0'
985
986
  requirements: []
986
987
  rubygems_version: 3.1.4
987
- signing_key:
988
+ signing_key:
988
989
  specification_version: 4
989
990
  summary: this is qiita post gem from org.
990
991
  test_files: []