From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id wCnFLRYgFmDGaQAA0tVLHw (envelope-from ) for ; Sun, 31 Jan 2021 03:12:22 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id gAiKKRYgFmC5CwAAB5/wlQ (envelope-from ) for ; Sun, 31 Jan 2021 03:12:22 +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 306719403CA for ; Sun, 31 Jan 2021 03:12:22 +0000 (UTC) Received: from localhost ([::1]:44834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l639v-0007Sf-Vx for larch@yhetil.org; Sat, 30 Jan 2021 22:12:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5KkC-0001wf-S4 for emacs-orgmode@gnu.org; Thu, 28 Jan 2021 22:46:48 -0500 Received: from mail-qt1-x833.google.com ([2607:f8b0:4864:20::833]:41606) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l5KkA-0001P2-L4 for emacs-orgmode@gnu.org; Thu, 28 Jan 2021 22:46:48 -0500 Received: by mail-qt1-x833.google.com with SMTP id t14so5801322qto.8 for ; Thu, 28 Jan 2021 19:46:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=user-agent:from:to:subject:message-id:date:mime-version; bh=fRKrJaPvTyfrs3rgpm4doUX2PnDR6pUNXAfokfcavBU=; b=YGTntE3lArM8Z/YJk1Vf7eebMTuHd5w0LGcGrrVu2Luj22bbJNo+7HlGGsE39lfHmZ hSnQkRK4dqsTu7sR9zmKFnZasDeuqOKVjw9tFRDkWtjsZMOjmBlR1YcV5PDSpGGqtrex 0mdMe2PK8iUlRtV3sNwDwHmmVWnbJ/IbUS/MIDFDz0Lfg7aHPU3DIZldqQtMc5/q21Wu KeR+4Rb5OjN87wpYp+x3b0vij/ngr+ACE2Jzf4QFumTjKod41V4XUu3IQljpgPeadKCk Y9lErc6Uc2KVC2JOt+4o7Q874OQF1FBsGWrp032yI57/x4JNpvQiNjbjmWI03GTf3Xu1 Iy+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:from:to:subject:message-id:date :mime-version; bh=fRKrJaPvTyfrs3rgpm4doUX2PnDR6pUNXAfokfcavBU=; b=Fb+tn4nK3xlvusltN15eohnNAAt0/WNDBeUuxDeomz2y+oLkUmJiCyne7z34qPXldJ 4soO54MfHGD/uvY50kOIyYAVNCrzwVujQfhUwie1xP9DTjaMTquTX7rCbPkYFMkcBiO1 1WJqAUFuEYyJoZnnBrOZ50E/NVpilyo0f8WWxxCUS+aT1Urdx3iXyskI9ySZjLWHZNqJ Flt2j3deyg+NdaBgGjIlCe0rDmPPbYEVro07RYORv08niOScB8oTvPfACgw6OMEkUEJw vSpEswmS6SOAextpzsrvI50Y8GI7+VpYt2r3rgUsW3JRC0YmG1Kw1Xzoc5RmfsCaZacV bGpQ== X-Gm-Message-State: AOAM531mOodU1NkH7NrUk4zoslMBL4H4VPZCF7AAvNlxXoaJDawRxDJ6 nGkKynUki1e/WOqvE5YCKygqvyxaJa4= X-Google-Smtp-Source: ABdhPJxK8v+ancTHaHUr9ag4Iv+s9k0W1c6uidLm8GMmDAp5iUe2/nYaKjYjNCWfVeV1Zfoqd1THBQ== X-Received: by 2002:ac8:380e:: with SMTP id q14mr2746684qtb.260.1611892001733; Thu, 28 Jan 2021 19:46:41 -0800 (PST) Received: from localhost ([190.239.232.181]) by smtp.gmail.com with ESMTPSA id q3sm4962268qkb.73.2021.01.28.19.46.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Jan 2021 19:46:41 -0800 (PST) User-agent: mu4e 1.4.14; emacs 27.1 From: Rodrigo Morales To: emacs-orgmode@gnu.org Subject: [PATCH] ox-md.el export code blocks using grave accents Message-ID: <87bld8qug1.fsf@gmail.com> Date: Thu, 28 Jan 2021 22:43:26 -0500 MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::833; envelope-from=moralesrodrigo1100@gmail.com; helo=mail-qt1-x833.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 30 Jan 2021 22:11:09 -0500 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 X-Migadu-Spam-Score: -2.05 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=YGTntE3l; dmarc=pass (policy=none) header.from=gmail.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: 306719403CA X-Spam-Score: -2.05 X-Migadu-Scanner: scn1.migadu.com X-TUID: xG8WyrpblznO [PATCH] ox-md.el export code blocks using grave accents. This patch includes the following changes in =ox-md.el= + =org-md-example-block= now exports code blocks using triple grave accents instead of four spaces of indentation. This has been done for two main reasons: 1. To be able to include the language so that Markdown engines can syntax highlight the content of code blocks 2. To be able to put the source code and the results of evaluation in different code blocks. When using indentation, both the source code and the results are shown in the same code block by Markdown engines. + The variable =org-md-lang-export= is now included in order to map Org Mode language names to Markdown language names. The file =mre.org= contains a minimal reproducible example; =mre.md= , the resulting file when exporting using the current version; and =mre-patched.md=, the resulting file when exporting with the changes of this patch applied. The patch is shown below. #+begin_src dash :dir (progn default-directory) :epilogue ":" diff -u ox-md.el ox-md-patched.el #+end_src #+RESULTS: #+begin_example --- ox-md.el 2021-01-28 22:18:51.566067501 -0500 +++ ox-md-patched.el 2021-01-28 22:14:34.762735829 -0500 @@ -50,6 +50,14 @@ (const :tag "Use \"atx\" style" atx) (const :tag "Use \"Setext\" style" setext))) +(defcustom org-md-lang-export + '(("dash" . "sh")) + "Alist mapping languages to the corresponding language names in Markdown." + :group 'org-export-md + :type '(repeat + (cons + (string "Org Mode language name") + (string "Markdown language name")))) ;;;; Footnotes @@ -181,10 +189,24 @@ "Transcode EXAMPLE-BLOCK element into Markdown format. CONTENTS is nil. INFO is a plist used as a communication channel." - (replace-regexp-in-string - "^" " " - (org-remove-indentation - (org-export-format-code-default example-block info)))) + (let* (language + (org-language + (plist-get (car (cdr example-block)) :language)) + (markdown-language + (cdr (assoc org-language org-md-lang-export))) ; + (content + (org-remove-indentation + (org-export-format-code-default example-block info)))) + + (if markdown-language + (setq language markdown-language) + (setq language org-language)) + + (setq content (replace-regexp-in-string + "\\`" (concat "```" language "\n") + content)) + + (replace-regexp-in-string "\\'" "```" content))) (defun org-md-export-block (export-block contents info) "Transcode a EXPORT-BLOCK element from Org to Markdown. #+end_example -- Greetings, Rodrigo Morales.