Compare commits
10 Commits
249d2be0e0
...
94dd2f4a8e
Author | SHA1 | Date |
---|---|---|
Lucien Cartier-Tilet | 94dd2f4a8e | |
cnngimenez | 168f820ea4 | |
cnngimenez | d0f2cabb2b | |
cnngimenez | 7465109046 | |
cnngimenez | 2046ff20b8 | |
cnngimenez | 07882c1987 | |
cnngimenez | 5420b6cea8 | |
cnngimenez | 527ce87206 | |
cnngimenez | 7c3300ace1 | |
cnngimenez | 747201272b |
77
ox-gemini.el
77
ox-gemini.el
|
@ -39,24 +39,37 @@
|
|||
(?f "To file"
|
||||
(lambda (a s v b)
|
||||
(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)
|
||||
(headline . org-gemini-headline)
|
||||
(link . org-gemini-link)
|
||||
(section . org-gemini-section)
|
||||
(src-block . org-gemini-code-block)
|
||||
(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)
|
||||
"CONTENTS is the text of the paragraph."
|
||||
(concat (replace-regexp-in-string "\n" " " contents)
|
||||
"\n"))
|
||||
|
||||
(defun org-gemini-item (_input contents _info)
|
||||
"CONTENTS is the text of the individual item."
|
||||
(format "* %s" contents))
|
||||
(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-quote-block (_input contents _info)
|
||||
"CONTENTS is the text of the quote."
|
||||
|
@ -65,13 +78,16 @@
|
|||
(replace-regexp-in-string "\n\\'" "" contents)))
|
||||
|
||||
(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 ``
|
||||
(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 (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
|
||||
(format "```%s\n%s```"
|
||||
(or name "")
|
||||
|
@ -80,7 +96,8 @@
|
|||
(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)
|
||||
|
@ -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")
|
||||
raw-path))
|
||||
(desc (org-element-contents link))
|
||||
(anchor (org-export-data
|
||||
(or desc (org-element-property :raw-link link))
|
||||
info)))
|
||||
(anchor (string-replace "\n" " "
|
||||
(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)
|
||||
|
@ -116,7 +134,9 @@ 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."
|
||||
(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)
|
||||
;; Take care of links in first section of the document.
|
||||
(not (org-element-lineage section '(headline)))
|
||||
|
@ -125,8 +145,8 @@ contextual information."
|
|||
(org-ascii--current-text-width section info)
|
||||
info))))
|
||||
(org-remove-indentation
|
||||
(if (not (org-string-nw-p links)) contents
|
||||
(concat (org-element-normalize-string contents) "\n\n" links))
|
||||
(if (not (org-string-nw-p links)) contents-str
|
||||
(concat (org-element-normalize-string contents-str) "\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
|
||||
|
@ -136,7 +156,8 @@ 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
|
||||
|
@ -196,8 +217,10 @@ holding contextual information."
|
|||
(format "%c "
|
||||
(nth (mod (1- low-level) (length bullets)) bullets))))
|
||||
(concat bullet title "\n" pre-blanks
|
||||
;; Contents, indented by length of bullet.
|
||||
(org-ascii--indent-string body (length bullet))))
|
||||
;; 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))
|
||||
;; Else: Standard headline.
|
||||
(concat title "\n" pre-blanks body)))))
|
||||
|
||||
|
@ -274,6 +297,24 @@ 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
|
||||
|
|
Loading…
Reference in New Issue