emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: "Johan Bolmsjö" <org-mode@johan.bitmaster.se>
Cc: emacs-orgmode@gnu.org
Subject: Re: [BUG] ox-html does not export captions of source blocks without language
Date: Mon, 16 Jan 2023 10:09:31 +0000	[thread overview]
Message-ID: <87tu0qdc4k.fsf@localhost> (raw)
In-Reply-To: <87zgb90win.fsf@localhost>

[-- Attachment #1: Type: text/plain, Size: 560 bytes --]

Ihor Radchenko <yantar92@posteo.net> writes:

> Here is the plan to resolve this issue:
>
> 1. We update the manual allowing src blocks to have empty language spec

See the attached patch.

> 2. We update org-syntax document

It turned out to be unnecessary.  org-syntax document already declares
block DATA to be optional:

#+begin_name [DATA]
#+end_name

See https://orgmode.org/worg/org-syntax.html#Blocks

Code blocks fall within a subset of this rule.

> 3. We change org-html-src-block to add caption to src blocks without lang

See the attached patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-manual.org-Clarify-that-LANGUAGE-may-be-omitted-.patch --]
[-- Type: text/x-patch, Size: 2704 bytes --]

From a7c5aa3431cc1946aa7f8055c39e18e5afc4cef4 Mon Sep 17 00:00:00 2001
Message-Id: <a7c5aa3431cc1946aa7f8055c39e18e5afc4cef4.1673863743.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Mon, 16 Jan 2023 12:59:47 +0300
Subject: [PATCH 1/2] org-manual.org: Clarify that LANGUAGE may be omitted in
 code blocks

* doc/org-manual.org (Structure of Code Blocks):
(Editing Source Code): Clarify that <language> is optional.  Link to
possible consequences of <language> being omitted.
---
 doc/org-manual.org | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 4466af8e4..c241e170f 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -17313,9 +17313,16 @@ ** Structure of Code Blocks
 - =<language>= ::
 
   #+cindex: language, in code blocks
-  Mandatory.  It is the identifier of the source code language in the
+  Optional.  It is the identifier of the source code language in the
   block.  See [[*Languages]], for identifiers of supported languages.
 
+  When =<language>= identifier is omitted, the block also cannot
+  have =<switches>= and =<header arguments>=.
+
+  Language identifier is also used to fontify code blocks in Org
+  buffers, when ~org-src-fontify-natively~ is set to non-~nil~.  See
+  [[*Editing Source Code]].
+
 - =<switches>= ::
 
   #+cindex: switches, in code blocks
@@ -18951,6 +18958,9 @@ ** Editing Source Code
   header line, then the edit buffer uses that major mode.  Use this
   variable to arbitrarily map language identifiers to major modes.
 
+  When language identifier is omitted in the src block, Org mode's
+  behavior is undefined.
+
 - ~org-src-window-setup~ ::
 
   #+vindex: org-src-window-setup
@@ -18976,10 +18986,13 @@ ** Editing Source Code
 
 #+vindex: org-src-fontify-natively
 #+vindex: org-src-block-faces
-Set ~org-src-fontify-natively~ to non-~nil~ to turn on native code
-fontification in the /Org/ buffer.  Fontification of code blocks can
-give visual separation of text and code on the display page.  To
-further customize the appearance of ~org-block~ for specific
+Fontification of code blocks can give visual separation of text and
+code on the display page.  Set ~org-src-fontify-natively~ to non-~nil~
+to turn on native code fontification in the /Org/ buffer.  The
+fontification follows the major mode used to edit the code block (see
+~org-src-lang-modes~ above).
+
+To further customize the appearance of ~org-block~ for specific
 languages, customize ~org-src-block-faces~.  The following example
 shades the background of regular blocks, and colors source blocks only
 for Python and Emacs Lisp languages.
-- 
2.39.0


[-- Attachment #3: 0002-org-html-src-block-Treat-code-blocks-without-LANG-eq.patch --]
[-- Type: text/x-patch, Size: 3530 bytes --]

From 8c832d374066bbba430dc21a6b4fb098361c44a9 Mon Sep 17 00:00:00 2001
Message-Id: <8c832d374066bbba430dc21a6b4fb098361c44a9.1673863743.git.yantar92@posteo.net>
In-Reply-To: <a7c5aa3431cc1946aa7f8055c39e18e5afc4cef4.1673863743.git.yantar92@posteo.net>
References: <a7c5aa3431cc1946aa7f8055c39e18e5afc4cef4.1673863743.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Mon, 16 Jan 2023 13:04:01 +0300
Subject: [PATCH 2/2] org-html-src-block: Treat code blocks without LANG
 equally
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/ox-html.el (org-html-src-block): Do not treat src blocks
without LANG as example blocks.  Instead, export them using "nil"
language.  This way, such src blocks will get captions, unlike example
blocks.

The new behavior is consistent with ox-latex and ox-ascii.

Reported-by: Johan Bolmsjö <org-mode@johan.bitmaster.se>
Link: https://orgmode.org/list/87zgb90win.fsf@localhost
---
 lisp/ox-html.el | 52 ++++++++++++++++++++++++-------------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 7b79c57d4..5e58ccba3 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -3616,32 +3616,32 @@ (defun org-html-src-block (src-block _contents info)
 	   (klipsify  (and  (plist-get info :html-klipsify-src)
                             (member lang '("javascript" "js"
 					   "ruby" "scheme" "clojure" "php" "html")))))
-      (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
-	(format "<div class=\"org-src-container\">\n%s%s\n</div>"
-		;; Build caption.
-		(let ((caption (org-export-get-caption src-block)))
-		  (if (not caption) ""
-		    (let ((listing-number
-			   (format
-			    "<span class=\"listing-number\">%s </span>"
-			    (format
-			     (org-html--translate "Listing %d:" info)
-			     (org-export-get-ordinal
-			      src-block info nil #'org-html--has-caption-p)))))
-		      (format "<label class=\"org-src-name\">%s%s</label>"
-			      listing-number
-			      (org-trim (org-export-data caption info))))))
-		;; Contents.
-		(if klipsify
-		    (format "<pre><code class=\"src src-%s\"%s%s>%s</code></pre>"
-			    lang
-			    label
-			    (if (string= lang "html")
-				" data-editor-type=\"html\""
-			      "")
-			    code)
-		  (format "<pre class=\"src src-%s\"%s>%s</pre>"
-                          lang label code)))))))
+      (format "<div class=\"org-src-container\">\n%s%s\n</div>"
+	      ;; Build caption.
+	      (let ((caption (org-export-get-caption src-block)))
+		(if (not caption) ""
+		  (let ((listing-number
+			 (format
+			  "<span class=\"listing-number\">%s </span>"
+			  (format
+			   (org-html--translate "Listing %d:" info)
+			   (org-export-get-ordinal
+			    src-block info nil #'org-html--has-caption-p)))))
+		    (format "<label class=\"org-src-name\">%s%s</label>"
+			    listing-number
+			    (org-trim (org-export-data caption info))))))
+	      ;; Contents.
+	      (if klipsify
+		  (format "<pre><code class=\"src src-%s\"%s%s>%s</code></pre>"
+			  lang ; lang being nil is OK.
+			  label
+			  (if (string= lang "html")
+			      " data-editor-type=\"html\""
+			    "")
+			  code)
+		(format "<pre class=\"src src-%s\"%s>%s</pre>"
+                        ;; Lang being nil is OK.
+                        lang label code))))))
 
 ;;;; Statistics Cookie
 
-- 
2.39.0


[-- Attachment #4: Type: text/plain, Size: 224 bytes --]


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

  reply	other threads:[~2023-01-16 10:10 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14 21:40 [BUG] ox-html does not export captions of source blocks without language Johan Bolmsjö
2022-12-14 21:51 ` Kaushal Modi
2022-12-14 22:05   ` Johan Bolmsjö
2022-12-15  9:31 ` [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language) Ihor Radchenko
2022-12-15 10:32   ` Kaushal Modi
2022-12-15 11:32   ` Max Nikulin
2022-12-15 14:29     ` Tim Cross
2022-12-15 15:07       ` Ihor Radchenko
2022-12-17  5:17         ` Tom Gillespie
2022-12-18  1:33           ` Tim Cross
2022-12-17 14:47         ` [Syntax discussion] Should we treat src blocks without LANG as paragraphs? Max Nikulin
2022-12-18 13:35           ` [BUG] org-latex-src-block-backend is directly used as variable instead of querying export option (was: [Syntax discussion] Should we treat src blocks without LANG as paragraphs?) Ihor Radchenko
2022-12-18 13:40             ` Timothy
2022-12-21 12:14               ` Ihor Radchenko
2022-12-27 14:18           ` [FR] Present list of errors in separate buffer when running org-export, similar to what org-lint does " Ihor Radchenko
2022-12-27 18:39             ` Tim Cross
2022-12-17  9:56     ` [Syntax discussion] Should we treat src blocks without LANG as paragraphs? (was: [BUG] ox-html does not export captions of source blocks without language) Ihor Radchenko
2022-12-15 13:32   ` Timothy
2022-12-27 14:08 ` [BUG] ox-html does not export captions of source blocks without language Ihor Radchenko
2023-01-16 10:09   ` Ihor Radchenko [this message]
2023-01-16 10:31     ` [ANN] orgtbl-fit tbanelwebmin
2023-01-24 19:55       ` Ihor Radchenko
2023-01-25 15:02         ` tbanelwebmin
2023-01-26 10:35           ` Ihor Radchenko
2023-01-26 19:13             ` tbanelwebmin
2023-02-20 10:50               ` Ihor Radchenko
2023-03-01 11:48                 ` tbanelwebmin
2023-03-03 15:13                   ` Ihor Radchenko
2023-03-05 18:46                     ` tbanelwebmin
2023-01-23 13:32     ` [BUG] ox-html does not export captions of source blocks without language Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tu0qdc4k.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=org-mode@johan.bitmaster.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).