Compare commits

...

10 Commits

Author SHA1 Message Date
Lucien Cartier-Tilet 94dd2f4a8e
fix: remove newlines in link descriptions
Currently, when an orgmode link has a newline in its description, it
is passed to the description of the Gemini link. Example:

```org
[[https://example.com][This is a link with a
newline to example.com]]
```

Which exports to:

```gmi
=> https://example.com This is a link with a
newline to example.com
```

This commit fixes this by replacing newlines with a simple space. The
new output is:

```gmi
=> https://example.com This is a link with a newline to example.com
```

It also fixes a compilation error on Emacs 30 by properly escaping
quotation marks.

Signed-off-by: Lucien Cartier-Tilet <lucien@phundrak.com>
2023-05-11 13:22:33 +02:00
cnngimenez 168f820ea4 Checkdoc pass. Melpazoid checks pass. 2022-04-18 11:33:45 -03:00
cnngimenez d0f2cabb2b Force no indentation to text in deep headlines. 2022-04-17 16:06:05 -03:00
cnngimenez 7465109046 Fixed #2. Fixed #1 too. 2022-02-04 15:54:19 -03:00
cnngimenez 2046ff20b8 Items with checkbox and description can be exported. 2022-02-04 11:51:00 -03:00
cnngimenez 07882c1987 Support for `#+BEGIN_EXPORT gemini`. Byte-compile is happy. 2022-01-16 00:40:58 -03:00
cnngimenez 5420b6cea8 Export source block: Use caption instead of name if exists. 2022-01-15 20:49:52 -03:00
cnngimenez 527ce87206 Merge 2022-01-10 19:12:19 -03:00
cnngimenez 7c3300ace1 Bug fixed when section has no text but has properties.
An error appeared when a header has no text but it has properties. For instance:
```org
* A header
:PROPERTIES:
:ID:       7159694c-0e06-41d6-a2fc-1ae3f9ba0321
:END:

* Another header
```

"A header" is processed by `org-gemini-section` and throws error when
exporting: `contents` parameter is nil instead of empty string. "Another
header" is considered a headline and not a section.
2022-01-10 21:02:28 +00:00
cnngimenez 747201272b Bug fixed when section has no text but has properties.
An error appeared when a header has no text but it has properties. For instance:
```org
* A header
:PROPERTIES:
:ID:       7159694c-0e06-41d6-a2fc-1ae3f9ba0321
:END:

* Another header
```

"A header" is processed by `org-gemini-section` and throws error when
exporting: `contents` parameter is nil instead of empty string. "Another
header" is considered a headline and not a section.
2022-01-10 15:30:46 -03:00
1 changed files with 59 additions and 18 deletions

View File

@ -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