Compare commits
10 Commits
249d2be0e0
...
94dd2f4a8e
Author | SHA1 | Date | |
---|---|---|---|
94dd2f4a8e | |||
|
168f820ea4 | ||
|
d0f2cabb2b | ||
|
7465109046 | ||
|
2046ff20b8 | ||
|
07882c1987 | ||
|
5420b6cea8 | ||
|
527ce87206 | ||
|
7c3300ace1 | ||
|
747201272b |
77
ox-gemini.el
77
ox-gemini.el
|
@ -39,24 +39,37 @@
|
||||||
(?f "To file"
|
(?f "To file"
|
||||||
(lambda (a s v b)
|
(lambda (a s v b)
|
||||||
(org-gemini-export-to-file a s v b nil)))))
|
(org-gemini-export-to-file a s v b nil)))))
|
||||||
:translate-alist '((code . org-gemini-code-inline)
|
:translate-alist '((quote-block . org-gemini-quote-block)
|
||||||
|
(code . org-gemini-code-inline)
|
||||||
|
(export-block . org-gemini-export-block)
|
||||||
(paragraph . org-gemini-paragraph)
|
(paragraph . org-gemini-paragraph)
|
||||||
(headline . org-gemini-headline)
|
(headline . org-gemini-headline)
|
||||||
(link . org-gemini-link)
|
(link . org-gemini-link)
|
||||||
(section . org-gemini-section)
|
(section . org-gemini-section)
|
||||||
(src-block . org-gemini-code-block)
|
(src-block . org-gemini-code-block)
|
||||||
(item . org-gemini-item)
|
(item . org-gemini-item)
|
||||||
(quote-block . org-gemini-quote-block)
|
(template . org-gemini-template)
|
||||||
(template . org-gemini-template)))
|
(table . org-gemini-table)))
|
||||||
|
|
||||||
(defun org-gemini-paragraph (_paragraph contents _info)
|
(defun org-gemini-paragraph (_paragraph contents _info)
|
||||||
"CONTENTS is the text of the paragraph."
|
"CONTENTS is the text of the paragraph."
|
||||||
(concat (replace-regexp-in-string "\n" " " contents)
|
(concat (replace-regexp-in-string "\n" " " contents)
|
||||||
"\n"))
|
"\n"))
|
||||||
|
|
||||||
(defun org-gemini-item (_input contents _info)
|
(defun org-gemini-item (item contents info)
|
||||||
"CONTENTS is the text of the individual item."
|
"Generate a Gemtext item from the org CONTENTS.
|
||||||
(format "* %s" contents))
|
CONTENTS is the text of the individual item.
|
||||||
|
ITEM is the parsed-org element with all properties."
|
||||||
|
(concat "* "
|
||||||
|
;; vv Code from ox-md! vv
|
||||||
|
(pcase (org-element-property :checkbox item)
|
||||||
|
(`on "[X] ")
|
||||||
|
(`trans "[-] ")
|
||||||
|
(`off "[ ] "))
|
||||||
|
(let ((tag (org-element-property :tag item)))
|
||||||
|
(and tag (format "%s :: " (org-export-data tag info))))
|
||||||
|
;; ^^ ^^
|
||||||
|
contents))
|
||||||
|
|
||||||
(defun org-gemini-quote-block (_input contents _info)
|
(defun org-gemini-quote-block (_input contents _info)
|
||||||
"CONTENTS is the text of the quote."
|
"CONTENTS is the text of the quote."
|
||||||
|
@ -65,13 +78,16 @@
|
||||||
(replace-regexp-in-string "\n\\'" "" contents)))
|
(replace-regexp-in-string "\n\\'" "" contents)))
|
||||||
|
|
||||||
(defun org-gemini-code-inline (input _contents info)
|
(defun org-gemini-code-inline (input _contents info)
|
||||||
"INPUT is either a 'src-block' or 'example-block' element. INFO is a plist."
|
"Generate an inline code in Gemtext from the parsed INPUT.
|
||||||
|
INPUT is either a \\='src-block\\=' or \\='example-block\\='
|
||||||
|
element. INFO is a plist."
|
||||||
;; there's a bug here where there's a trailing space in the ``
|
;; there's a bug here where there's a trailing space in the ``
|
||||||
(format "`%s`" (org-export-format-code-default input info)))
|
(format "`%s`" (org-export-format-code-default input info)))
|
||||||
|
|
||||||
(defun org-gemini-code-block (src-block _contents info)
|
(defun org-gemini-code-block (src-block _contents info)
|
||||||
"SRC-BLOCK is a codeblock. INFO is a plist."
|
"SRC-BLOCK is a codeblock. INFO is a plist."
|
||||||
(let ((name (org-element-property :name src-block)))
|
(let ((name (or (caaar (org-element-property :caption src-block))
|
||||||
|
(org-element-property :name src-block))))
|
||||||
(org-remove-indentation
|
(org-remove-indentation
|
||||||
(format "```%s\n%s```"
|
(format "```%s\n%s```"
|
||||||
(or name "")
|
(or name "")
|
||||||
|
@ -80,7 +96,8 @@
|
||||||
(defun org-gemini--describe-links (links _width info)
|
(defun org-gemini--describe-links (links _width info)
|
||||||
"Describe links is the footer-portion of the link data.
|
"Describe links is the footer-portion of the link data.
|
||||||
|
|
||||||
It's output just before each section. LINKS is a list of each link. INFO is a plist."
|
It's output just before each section. LINKS is a list of each link.
|
||||||
|
INFO is a plist."
|
||||||
(concat
|
(concat
|
||||||
(mapconcat
|
(mapconcat
|
||||||
(lambda (link)
|
(lambda (link)
|
||||||
|
@ -92,9 +109,10 @@ It's output just before each section. LINKS is a list of each link. INFO is a
|
||||||
(concat (file-name-sans-extension (org-element-property :path link)) ".gmi")
|
(concat (file-name-sans-extension (org-element-property :path link)) ".gmi")
|
||||||
raw-path))
|
raw-path))
|
||||||
(desc (org-element-contents link))
|
(desc (org-element-contents link))
|
||||||
(anchor (org-export-data
|
(anchor (string-replace "\n" " "
|
||||||
(or desc (org-element-property :raw-link link))
|
(org-export-data
|
||||||
info)))
|
(or desc (org-element-property :raw-link link))
|
||||||
|
info))))
|
||||||
(format "=> %s %s\n" (url-encode-url path) anchor)))
|
(format "=> %s %s\n" (url-encode-url path) anchor)))
|
||||||
links "")
|
links "")
|
||||||
(when (car links)
|
(when (car links)
|
||||||
|
@ -116,7 +134,9 @@ Note: the footer with the actual links are handled in
|
||||||
"Transcode a SECTION element from Org to GEMINI.
|
"Transcode a SECTION element from Org to GEMINI.
|
||||||
CONTENTS is the contents of the section. INFO is a plist holding
|
CONTENTS is the contents of the section. INFO is a plist holding
|
||||||
contextual information."
|
contextual information."
|
||||||
(let ((links
|
;; CONTENTS is nil when the section has no text but it has properties setted.
|
||||||
|
(let ((contents-str (or contents "")) ;; ensure that contents is a string.
|
||||||
|
(links
|
||||||
(and (plist-get info :ascii-links-to-notes)
|
(and (plist-get info :ascii-links-to-notes)
|
||||||
;; Take care of links in first section of the document.
|
;; Take care of links in first section of the document.
|
||||||
(not (org-element-lineage section '(headline)))
|
(not (org-element-lineage section '(headline)))
|
||||||
|
@ -125,8 +145,8 @@ contextual information."
|
||||||
(org-ascii--current-text-width section info)
|
(org-ascii--current-text-width section info)
|
||||||
info))))
|
info))))
|
||||||
(org-remove-indentation
|
(org-remove-indentation
|
||||||
(if (not (org-string-nw-p links)) contents
|
(if (not (org-string-nw-p links)) contents-str
|
||||||
(concat (org-element-normalize-string contents) "\n\n" links))
|
(concat (org-element-normalize-string contents-str) "\n\n" links))
|
||||||
;; Do not apply inner margin if parent headline is low level.
|
;; Do not apply inner margin if parent headline is low level.
|
||||||
(let ((headline (org-export-get-parent-headline section)))
|
(let ((headline (org-export-get-parent-headline section)))
|
||||||
(if (or (not headline) (org-export-low-level-p headline info)) 0
|
(if (or (not headline) (org-export-low-level-p headline info)) 0
|
||||||
|
@ -136,7 +156,8 @@ contextual information."
|
||||||
(element info _text-width &optional _underline _notags toc)
|
(element info _text-width &optional _underline _notags toc)
|
||||||
"Build a title heading.
|
"Build a title heading.
|
||||||
|
|
||||||
ELEMENT is an org-element. TOC is whether to show the table of contents. INFO is unimportant."
|
ELEMENT is an org-element. TOC is whether to show the table of contents.
|
||||||
|
INFO is unimportant."
|
||||||
(let ((number (org-element-property :level element))
|
(let ((number (org-element-property :level element))
|
||||||
(text
|
(text
|
||||||
(org-trim
|
(org-trim
|
||||||
|
@ -196,8 +217,10 @@ holding contextual information."
|
||||||
(format "%c "
|
(format "%c "
|
||||||
(nth (mod (1- low-level) (length bullets)) bullets))))
|
(nth (mod (1- low-level) (length bullets)) bullets))))
|
||||||
(concat bullet title "\n" pre-blanks
|
(concat bullet title "\n" pre-blanks
|
||||||
;; Contents, indented by length of bullet.
|
;; In Gemtext, text should not be indentend. Otherwise,
|
||||||
(org-ascii--indent-string body (length bullet))))
|
;; source code blocks, links, and other line types would not
|
||||||
|
;; be interpreted by clients because of the initial spacing.
|
||||||
|
body))
|
||||||
;; Else: Standard headline.
|
;; Else: Standard headline.
|
||||||
(concat title "\n" pre-blanks body)))))
|
(concat title "\n" pre-blanks body)))))
|
||||||
|
|
||||||
|
@ -274,6 +297,24 @@ Return output file name."
|
||||||
(org-publish-org-to
|
(org-publish-org-to
|
||||||
'gemini filename ".gmi" plist pub-dir))
|
'gemini filename ".gmi" plist pub-dir))
|
||||||
|
|
||||||
|
(defun org-gemini-export-block (export-block _contents _info)
|
||||||
|
"Transcode a EXPORT-BLOCK element from Org to Markdown.
|
||||||
|
CONTENTS is nil. INFO is a plist holding contextual information."
|
||||||
|
(when (member (org-element-property :type export-block)
|
||||||
|
'("GEMINI" "GMI" "GEMTEXT"))
|
||||||
|
(org-remove-indentation (org-element-property :value export-block))))
|
||||||
|
|
||||||
|
(defun org-gemini-table (table contents info)
|
||||||
|
"Generate a Gemtext table from the parsed Org.
|
||||||
|
Use the `org-ascii-table' but surrounded by backticks.
|
||||||
|
Parameters: TABLE is the parsed org-element table. CONTENTS is the text with
|
||||||
|
properties. INFO is a plist with export options."
|
||||||
|
(let ((name (or (caaar (org-element-property :caption table))
|
||||||
|
(org-element-property :name table))))
|
||||||
|
(format "```%s\n%s\n```\n"
|
||||||
|
(or name "")
|
||||||
|
(org-ascii-table table contents info))))
|
||||||
|
|
||||||
|
|
||||||
(provide 'ox-gemini)
|
(provide 'ox-gemini)
|
||||||
;;; ox-gemini.el ends here
|
;;; ox-gemini.el ends here
|
||||||
|
|
Loading…
Reference in New Issue
Block a user