From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id CJwcHHT3cGZHNAEAqHPOHw:P1 (envelope-from ) for ; Tue, 18 Jun 2024 02:56:52 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id CJwcHHT3cGZHNAEAqHPOHw (envelope-from ) for ; Tue, 18 Jun 2024 04:56:52 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=G2A1BzIK; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1718679412; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=16L2WSQ0daF7SrsAmGTFN7fcqTalzjPnmUTBh2kSZjg=; b=GDpTzfoyMdel7AUYXX7HXVAP7oY9txhlZgmUb2sfc4/xhBWWxu7QqfOuw4WscIPR3Webem 5npZnbCQHhAIqQ3tVKcZlGLpiqZMZkZrbpNx6MWQ23CLatphjvq1vIWvOzEVKYqKvhF9cv 79rnANuYQeL+UI5/39k5Pv6B15E8yhEyJAEybkd1W0S7IZjM8417boGCjRyG8irFgk9ZPA nCjpG3D9l0SjKkYtEhKv6umvZwThnpzPykYQRibhwNAwK8ufKODEfWrttiZ88K2Eu9S80/ UXz11UAsyT3XWM5iB5VL1UEu/U6wvvN7Ost5gu/+YGRF/ZlPpnARF4ASe0hIKQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=G2A1BzIK; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1718679412; a=rsa-sha256; cv=none; b=fk/jVyEyi/WUMULS/6PmnDnkAJj5LIn6tTARwlJCywLDymSyCEv4MBGQBjO30DytLLw4Wk xgBQsHtz2imOoo74Y/4huSQe3Vpcf2EOdzBVFhfV0ggiDE1cXRY2y6qrBbQShyb7ZbOzpI EdJWwZ+NwazhMwJH66E8dvF5Mca0WETj9yhdccoMiiDcaBkefTa+3Ixukk/fhegQNRDJ4m eid8l2uiVOgiToN+c85cXb/SOrkmzf0ZD3mr4q5LqprFhQamXRDp5YLvf7xD3fS0Q3OGuk XwBBgvqPK9HE2NwMxu1WPQ5P01j3dOvVSfmwwtqnqIEdSB4lLl3rVlRreMJF5Q== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1FA143BCFD for ; Tue, 18 Jun 2024 04:56:52 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJP0Q-0004qP-5d; Mon, 17 Jun 2024 22:55:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJP0O-0004pz-IZ for emacs-orgmode@gnu.org; Mon, 17 Jun 2024 22:55:32 -0400 Received: from mail-yw1-x1144.google.com ([2607:f8b0:4864:20::1144]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sJP0M-0000Hw-U9 for emacs-orgmode@gnu.org; Mon, 17 Jun 2024 22:55:32 -0400 Received: by mail-yw1-x1144.google.com with SMTP id 00721157ae682-62f79de5f49so6332487b3.2 for ; Mon, 17 Jun 2024 19:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718679330; x=1719284130; darn=gnu.org; h=mime-version:user-agent:message-id:date:subject:to:from:from:to:cc :subject:date:message-id:reply-to; bh=16L2WSQ0daF7SrsAmGTFN7fcqTalzjPnmUTBh2kSZjg=; b=G2A1BzIK43zJImJ69mPGO2+j1xhPGnc9MlrF0FOoyYYrKJ73ZxiJVzHEmDr7IEsGFm 8m0yxxmLtD84sQHHtiPj0FGJ6p9GCBfZawcXeoMSLGsHtHydAC6Aku0EignB4ngr+rFh HBVgd2ojH77e8+vaXSigFpCV4kza/9Kis/Z0J4b9UJhZMap6dues5dwDryGWv/o5A7KY SHVWSCPWtY/XG7NyqFfsQItajkrdRm7XUqeIMzxa+wndhb/pHG1dxlXgOBOXgmzvI952 1aMqep9a54fkf8hWcSV2dN7FmIdMmcJNi9AJfkPK65t07LLbrh2DUhcRjA6CCYUjw4h6 Q2qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718679330; x=1719284130; h=mime-version:user-agent:message-id:date:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=16L2WSQ0daF7SrsAmGTFN7fcqTalzjPnmUTBh2kSZjg=; b=Ci42pUI7+eoan3hDWLIamc1QjqdEdZgmpXAHOX6HmRBR+0TCX0qX8IlSKiDrRm835n j0udTZkLiDodPK13uYSCPMqILOlDHJ8InE+I7z6cKM1oLEccsrgHUra2kcdOqKtLIwo8 HrigMwAAJk4FYeC80UmoduzhGXewdvV96thKsRUblv31440+pQW7zqjsaA6HYLU/0Fzi VpVtiP4j6eHIg7yF12a/wisMuLrRahkz3hRYSC0G0KgfMj4oWolKtV3CmLtiXLtj2Oqq b2fq9GZyPz0KcOLMljV9ZG93jgZMJamQvwhbbpWurUY++/zb3PEpHpnVW328+pDPT6lv WiAw== X-Gm-Message-State: AOJu0YyRh4MVBRGavU8tV8auHF4Jjt33s68rWsGYEproo/opaV5OZtwR n+Mot9e/+mwXBgLfOrJgZ0prcVXb6ImHGYVoIG+unOeM2SXU3dU8 X-Google-Smtp-Source: AGHT+IE5R7gEa7YEqcn6yn3Dl3TYxAlYjckMvvUqIGNE4Cf5Swn/usrFE7GfenMbi12zW0yubpLZog== X-Received: by 2002:a05:690c:3347:b0:62c:ecad:e8cc with SMTP id 00721157ae682-6322256333bmr90145877b3.2.1718679329676; Mon, 17 Jun 2024 19:55:29 -0700 (PDT) Received: from gnus (static-198-54-132-177.cust.tzulo.com. [198.54.132.177]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b2a5c2fbbasm61287126d6.60.2024.06.17.19.55.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 19:55:29 -0700 (PDT) From: Suhail Singh To: Org mailing list Subject: [PATCH] [BUG] Support attr_html in source code and fixed-width blocks Date: Mon, 17 Jun 2024 22:55:28 -0400 Message-ID: <87v8277ye7.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::1144; envelope-from=suhailsingh247@gmail.com; helo=mail-yw1-x1144.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 1FA143BCFD X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -9.60 X-Spam-Score: -9.60 X-TUID: TK7ajV6vcJ6o --=-=-= Content-Type: text/plain Unlike example blocks, source code and fixed-width blocks don't support the attr_html keyword. Contrast these outputs: #+begin_src emacs-lisp :results value replace :wrap src html (require 'org) (require 'ox-html) (org-export-string-as "#+attr_html: :class foo ,#+begin_src sh :exports code pwd ,#+end_src" 'html t) #+end_src #+RESULTS: #+begin_src html
pwd
#+end_src #+begin_src emacs-lisp :results value replace :wrap src html (require 'org) (require 'ox-html) (org-export-string-as "#+attr_html: :class foo ,#+RESULTS: : blah" 'html t) #+end_src #+RESULTS: #+begin_src html
blah
#+end_src With the output for example blocks: #+begin_src emacs-lisp :results value replace :wrap src html (require 'org) (require 'ox-html) (org-export-string-as "#+attr_html: :class foo ,#+begin_example hello world! ,#+end_example" 'html t) #+end_src #+RESULTS: #+begin_src html
hello world!
#+end_src The attached patches are a straight-forward copy-paste of relevant code from org-html-example-block. It may be better to refactor this logic and ensure that it is applied on all relevant AST nodes (others are probably affected as well). --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ox-html-Add-support-for-attr_html-for-source-code-bl.patch >From 7a61bb6a7c7e1122199232a1c01885fb270dd370 Mon Sep 17 00:00:00 2001 From: Suhail Date: Mon, 17 Jun 2024 21:04:18 -0400 Subject: [PATCH 1/2] ox-html: Add support for attr_html for source code blocks * lisp/ox-html.el (org-html-src-block): Handle attr_html in a manner similar to example blocks. TINYCHANGE --- lisp/ox-html.el | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index d1687cf5a..675d85ffe 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -3667,14 +3667,24 @@ (defun org-html-src-block contextual information." (if (org-export-read-attribute :attr_html src-block :textarea) (org-html--textarea-block src-block) - (let* ((lang (org-element-property :language src-block)) + (let* ((attributes (org-export-read-attribute :attr_html src-block)) + (lang (org-element-property :language src-block)) (code (org-html-format-code src-block info)) (label (let ((lbl (org-html--reference src-block info t))) (if lbl (format " id=\"%s\"" lbl) ""))) (klipsify (and (plist-get info :html-klipsify-src) (member lang '("javascript" "js" "ruby" "scheme" "clojure" "php" "html"))))) - (format "
\n%s%s\n
" + (if-let ((class-val (plist-get attributes :class))) + (setq attributes (plist-put attributes :class (concat "org-src-container " class-val))) + (setq attributes (plist-put attributes :class "org-src-container"))) + (format "\n%s%s\n" + (let* ((reference (org-html--reference src-block info)) + (a (org-html--make-attribute-string + (if (or (not reference) (plist-member attributes :id)) + attributes + (plist-put attributes :id reference))))) + (if (org-string-nw-p a) (concat " " a) "")) ;; Build caption. (let ((caption (org-export-get-caption src-block))) (if (not caption) "" -- 2.45.2 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-ox-html-Add-support-for-attr_html-in-fixed-width-blo.patch >From 5d4fa5c3e0a7933d10d8f1ece3e368d35e4838ad Mon Sep 17 00:00:00 2001 From: Suhail Date: Mon, 17 Jun 2024 22:00:35 -0400 Subject: [PATCH 2/2] ox-html: Add support for attr_html in fixed-width blocks * lisp/ox-html.el (org-html-fixed-width): Handle attr_html in a manner similar to example blocks. TINYCHANGE --- lisp/ox-html.el | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 675d85ffe..848017f1d 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2728,13 +2728,23 @@ (defun org-html-export-block ;;;; Fixed Width -(defun org-html-fixed-width (fixed-width _contents _info) +(defun org-html-fixed-width (fixed-width _contents info) "Transcode a FIXED-WIDTH element from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." - (format "
\n%s
" - (org-html-do-format-code - (org-remove-indentation - (org-element-property :value fixed-width))))) + (let ((attributes (org-export-read-attribute :attr_html fixed-width))) + (if-let ((class-val (plist-get attributes :class))) + (setq attributes (plist-put attributes :class (concat "example " class-val))) + (setq attributes (plist-put attributes :class "example"))) + (format "\n%s" + (let* ((reference (org-html--reference fixed-width info)) + (a (org-html--make-attribute-string + (if (or (not reference) (plist-member attributes :id)) + attributes + (plist-put attributes :id reference))))) + (if (org-string-nw-p a) (concat " " a) "")) + (org-html-do-format-code + (org-remove-indentation + (org-element-property :value fixed-width)))))) ;;;; Footnote Reference -- 2.45.2 --=-=-= Content-Type: text/plain Suhail (2): ox-html: Add support for attr_html for source code blocks ox-html: Add support for attr_html in fixed-width blocks lisp/ox-html.el | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) base-commit: e666660c7d9fa3a74a7f5246d72e6020ab33cfd2 -- 2.45.2 --=-=-=--