Compare commits

..

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

View File

@ -39,37 +39,24 @@
(?f "To file"
(lambda (a s v b)
(org-gemini-export-to-file a s v b nil)))))
:translate-alist '((quote-block . org-gemini-quote-block)
(code . org-gemini-code-inline)
(export-block . org-gemini-export-block)
:translate-alist '((code . org-gemini-code-inline)
(paragraph . org-gemini-paragraph)
(headline . org-gemini-headline)
(link . org-gemini-link)
(section . org-gemini-section)
(src-block . org-gemini-code-block)
(item . org-gemini-item)
(template . org-gemini-template)
(table . org-gemini-table)))
(quote-block . org-gemini-quote-block)
(template . org-gemini-template)))
(defun org-gemini-paragraph (_paragraph contents _info)
"CONTENTS is the text of the paragraph."
(concat (replace-regexp-in-string "\n" " " contents)
"\n"))
(defun org-gemini-item (item contents info)
"Generate a Gemtext item from the org 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-item (_input contents _info)
"CONTENTS is the text of the individual item."
(format "* %s" contents))
(defun org-gemini-quote-block (_input contents _info)
"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)))
(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 ``
(format "`%s`" (org-export-format-code-default input info)))
(defun org-gemini-code-block (src-block _contents info)
"SRC-BLOCK is a codeblock. INFO is a plist."
(let ((name (or (caaar (org-element-property :caption src-block))
(org-element-property :name src-block))))
(let ((name (org-element-property :name src-block)))
(org-remove-indentation
(format "```%s\n%s```"
(or name "")
@ -96,8 +80,7 @@ element. INFO is a plist."
(defun org-gemini--describe-links (links _width info)
"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
(mapconcat
(lambda (link)
@ -109,10 +92,9 @@ INFO is a plist."
(concat (file-name-sans-extension (org-element-property :path link)) ".gmi")
raw-path))
(desc (org-element-contents link))
(anchor (string-replace "\n" " "
(org-export-data
(or desc (org-element-property :raw-link link))
info))))
(anchor (org-export-data
(or desc (org-element-property :raw-link link))
info)))
(format "=> %s %s\n" (url-encode-url path) anchor)))
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.
CONTENTS is the contents of the section. INFO is a plist holding
contextual information."
;; 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
(let ((links
(and (plist-get info :ascii-links-to-notes)
;; Take care of links in first section of the document.
(not (org-element-lineage section '(headline)))
@ -145,8 +125,8 @@ contextual information."
(org-ascii--current-text-width section info)
info))))
(org-remove-indentation
(if (not (org-string-nw-p links)) contents-str
(concat (org-element-normalize-string contents-str) "\n\n" links))
(if (not (org-string-nw-p links)) contents
(concat (org-element-normalize-string contents) "\n\n" links))
;; Do not apply inner margin if parent headline is low level.
(let ((headline (org-export-get-parent-headline section)))
(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)
"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))
(text
(org-trim
@ -217,10 +196,8 @@ holding contextual information."
(format "%c "
(nth (mod (1- low-level) (length bullets)) bullets))))
(concat bullet title "\n" pre-blanks
;; In Gemtext, text should not be indentend. Otherwise,
;; source code blocks, links, and other line types would not
;; be interpreted by clients because of the initial spacing.
body))
;; Contents, indented by length of bullet.
(org-ascii--indent-string body (length bullet))))
;; Else: Standard headline.
(concat title "\n" pre-blanks body)))))
@ -297,24 +274,6 @@ Return output file name."
(org-publish-org-to
'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)
;;; ox-gemini.el ends here