Compare commits

..

No commits in common. "94dd2f4a8e5ca50bbfb857395d98da88bf581b6c" and "249d2be0e0e7b47df7d0895dee21b3ecfb751902" have entirely different histories.

View File

@ -39,37 +39,24 @@
(?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 '((quote-block . org-gemini-quote-block) :translate-alist '((code . org-gemini-code-inline)
(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)
(template . org-gemini-template) (quote-block . org-gemini-quote-block)
(table . org-gemini-table))) (template . org-gemini-template)))
(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 (item contents info) (defun org-gemini-item (_input contents _info)
"Generate a Gemtext item from the org CONTENTS. "CONTENTS is the text of the individual item."
CONTENTS is the text of the individual item. (format "* %s" contents))
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."
@ -78,16 +65,13 @@ ITEM is the parsed-org element with all properties."
(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)
"Generate an inline code in Gemtext from the parsed INPUT. "INPUT is either a 'src-block' or 'example-block' element. INFO is a plist."
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 (or (caaar (org-element-property :caption src-block)) (let ((name (org-element-property :name 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 "")
@ -96,8 +80,7 @@ element. INFO is a plist."
(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. It's output just before each section. LINKS is a list of each link. INFO is a plist."
INFO is a plist."
(concat (concat
(mapconcat (mapconcat
(lambda (link) (lambda (link)
@ -109,10 +92,9 @@ INFO is a plist."
(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 (string-replace "\n" " " (anchor (org-export-data
(org-export-data (or desc (org-element-property :raw-link link))
(or desc (org-element-property :raw-link link)) info)))
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)
@ -134,9 +116,7 @@ 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."
;; CONTENTS is nil when the section has no text but it has properties setted. (let ((links
(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)))
@ -145,8 +125,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-str (if (not (org-string-nw-p links)) contents
(concat (org-element-normalize-string contents-str) "\n\n" links)) (concat (org-element-normalize-string contents) "\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
@ -156,8 +136,7 @@ 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. ELEMENT is an org-element. TOC is whether to show the table of contents. INFO is unimportant."
INFO is unimportant."
(let ((number (org-element-property :level element)) (let ((number (org-element-property :level element))
(text (text
(org-trim (org-trim
@ -217,10 +196,8 @@ 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
;; In Gemtext, text should not be indentend. Otherwise, ;; Contents, indented by length of bullet.
;; source code blocks, links, and other line types would not (org-ascii--indent-string body (length bullet))))
;; 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)))))
@ -297,24 +274,6 @@ 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