From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id WwMrKhFjbmAMAwEAgWs5BA (envelope-from ) for ; Thu, 08 Apr 2021 03:57:37 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 6EjeIhFjbmBUXQAAbx9fmQ (envelope-from ) for ; Thu, 08 Apr 2021 01:57:37 +0000 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 E7D471FD19 for ; Thu, 8 Apr 2021 03:57:36 +0200 (CEST) Received: from localhost ([::1]:49422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUJvL-0007Yp-IO for larch@yhetil.org; Wed, 07 Apr 2021 21:57:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUJun-0007YW-9T for emacs-orgmode@gnu.org; Wed, 07 Apr 2021 21:57:01 -0400 Received: from out2.migadu.com ([2001:41d0:2:aacc::]:41851) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUJui-0005VA-NG for emacs-orgmode@gnu.org; Wed, 07 Apr 2021 21:57:01 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=despisinggravity.com; s=key1; t=1617847010; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=qBh17ihHEYDmP8FUSi758/3E0bYWu/FL3bNXplBcdL0=; b=57YG8lBDTRQY4mCiD7yqfiC4lmzZH6YBKRSwuHXFXrK/sgOHF1ee1buTpX2UeB98JLCN0x lIH3Xcshppqcf22L1rjHYa8LWoI5CebfAjc2MSYmqNxscXEOkQGl7dnvQkt1C1zGPntSLC UiPcyOss1VUrMI9D5qDYM/kAElsohNFW03mBGLuBoVMso20qgNpSwwqtiPqs+Y5V2DUsyb p5oe9EZznDIi/5E1OHZi36lKWJ4OTusgfgAS0IjEdJkum7u65I/Luhx6aCz4oPR53lfUkr WFLcSOowo5rpNqLQjB8fXzZEQrDhEAcQsJw0Sn+Nhnk4CQ/sTKpFc7CpB6P0aQ== From: Nick Daly To: emacs-orgmode@gnu.org Subject: [PATCH] ob-plantuml: Add PlantUML block post-processing. Date: Wed, 07 Apr 2021 20:56:47 -0500 Message-ID: <87r1jl35eo.fsf@europa> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Auth-User: nick@despisinggravity.com Received-SPF: pass client-ip=2001:41d0:2:aacc::; envelope-from=nick+orgmode-org@despisinggravity.com; helo=out2.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 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" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1617847057; 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=qBh17ihHEYDmP8FUSi758/3E0bYWu/FL3bNXplBcdL0=; b=OKA4nH3SBW4G42LDPT5A74a5BKYFYDvvvW/F1cxcLKSLElLlzOz7LHVKweEgRVgHQ98Ds+ A5fyR1gr5fI2ybH9uxQje1SzL3Bfd14J2Q975aWxsA1pgClnsgQADD/NgKjWWtXwVWQl5D n7jnKIaEqSx36O2osZb6Enhbe0uBknfCINUoxBdfrkmIRHRUvmYsDizvpbA1TI/T1POQsQ n9Jv1ruoz5alGxIEhzzDADjcrVE5Q/XHapxV+H2oA8r5iUn+yXtMhyzJN53GUiW9dwNDOe tznkpg5LE8ms/1ZsFeKsqMVoDBhGmHTowDlelyX1tcRNzemhrG5j0yG7u+b8NQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1617847057; a=rsa-sha256; cv=none; b=pudIkgkMB9HZs25vHgkUXBPvXvMjbcC2yFjPk7IPwuRH/fb98xPi+DX4UVu1leIqszmE4Z csXpMCipFkNAQppPdV/O/hct4jDo6aDnxpYQV31JfYrhA9I6lAReIA82wkN5WKyz6yMWoe J6wkMlw0YsL3QvuV6utAOU4BJYr5TgHnMBZt7FRDYrOiq2vXY/uAlRrlo6Y8z4fOH2o4mk ykOPlPCqzZd3Og9v7BOZywLztlbKh7SCwe6jJSpM4UeAl546FMikmRJdh/Xaph91T9P0b9 ucfQEjjcEqQvbT65NrPVAG1j8pzrnIpqxsOELtIySRDqIhU3/vDQmPjKNYrGdA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=despisinggravity.com header.s=key1 header.b=57YG8lBD; dmarc=pass (policy=quarantine) header.from=despisinggravity.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -2.64 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=despisinggravity.com header.s=key1 header.b=57YG8lBD; dmarc=pass (policy=quarantine) header.from=despisinggravity.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: E7D471FD19 X-Spam-Score: -2.64 X-Migadu-Scanner: scn0.migadu.com X-TUID: 4ft590Vxu9tN --=-=-= Content-Type: text/plain Hi folks, Please see the attached patch that allows for post-processing of PlantUML diagrams based on the exported file extension. I currently use this to transform text in PlantUML SVGs to paths with Inkscape so that they can be embedded in PDFs with the text displaying at the correct size in the image. Since this post-processing occurs as part of the export process it works perfectly with Babel's caching. This ends up saving me a bunch of time when making changes to only one of a half-dozen figures. The concept could also work as post-execute advice on `org-babel-execute:plantuml', but I thought it would be more accessible to users as a new customizable variable built into `ob-plantuml.el'. The only part I'm unsure about is that I use "%s" as the replacement character when running commands over the exported file. For example, my "use Inkscape to pathify SVG text" command looks like: inkscape %s -T -l %s I'm uncertain whether that's a non-recommended replacement character but, either way, it functions well enough. Please let me know if the patch is attached incorrectly: I tried git-send-email but think I screwed it up somewhere as the previous emails never appeared on the list. Thanks for your time, Nick --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ob-plantuml-Add-PlantUML-block-post-processing.patch Content-Description: PlantUML post-processing patch >From 527610e8a415a45bffac53b9b508b472311627c3 Mon Sep 17 00:00:00 2001 From: Nick Daly Date: Mon, 5 Apr 2021 21:48:03 -0500 Subject: [PATCH] ob-plantuml: Add PlantUML block post-processing. * lisp/ob-plantuml.el (org-babel-plantuml-post-process): New function. After `org-babel-execute:plantuml' finishes exporting a file, read the file's extension and synchronously performs commands associated with that extension, in order, as defined in `org-babel-plantuml-post-export-commands'. If a command contains "%s", that token is replaced with the output file's name. If a command errors, it is skipped and execution continues with subsequent commands. (org-babel-execute:plantuml): Use new function. --- lisp/ob-plantuml.el | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lisp/ob-plantuml.el b/lisp/ob-plantuml.el index 93c653870..682fcbe48 100644 --- a/lisp/ob-plantuml.el +++ b/lisp/ob-plantuml.el @@ -71,6 +71,20 @@ You can also configure extra arguments via `org-plantuml-executable-args'." :package-version '(Org . "9.4") :type '(repeat string)) +(defcustom org-babel-plantuml-post-export-commands '(("svg" "inkscape %s -T -l %s")) + "List of file extensions and associated commands. + +The commands are run, in sequence, as a post-processing step for +each exported file with the associated extension. Any \"%s\" in +the command is replaced with the output file's name. + +For example, the default value converts text in an SVG to +paths, so that the text displays at the correct size when the +image is embedded in a PDF." + :group 'org-babel + :version "24.1" + :type '(alist :key-type string :value-type (repeat string))) + (defun org-babel-variable-assignments:plantuml (params) "Return a list of PlantUML statements assigning the block's variables. PARAMS is a property list of source block parameters, which may @@ -145,12 +159,32 @@ This function is called by `org-babel-execute-src-block'." " "))) (with-temp-file in-file (insert full-body)) (message "%s" cmd) (org-babel-eval cmd "") + (org-babel-plantuml-post-process out-file) nil)) ;; signal that output has already been written to file (defun org-babel-prep-session:plantuml (_session _params) "Return an error because plantuml does not support sessions." (error "Plantuml does not support sessions")) +(defun org-babel-plantuml-post-process (out-file) + "Run post-processing commands on the output file. + +See also `org-babel-plantuml-post-export-commands'." + + (defun org-babel-plantuml-post-process-loop (out-file command-list) + "Run each command in the command list over the output file." + (if command-list + (progn + (let ((cmd (replace-regexp-in-string "%s" out-file (car command-list))) + (rest (cdr command-list))) + (message "%s" cmd) + (org-babel-eval cmd "") + (org-babel-plantuml-post-process-loop out-file rest))))) + + (org-babel-plantuml-post-process-loop out-file + (cdr (assoc (file-name-extension out-file) + org-babel-plantuml-post-export-commands)))) + (provide 'ob-plantuml) ;;; ob-plantuml.el ends here -- 2.20.1 --=-=-=--