From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id GNGLF65ELGbKbgAAqHPOHw:P1 (envelope-from ) for ; Sat, 27 Apr 2024 02:19:58 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id GNGLF65ELGbKbgAAqHPOHw (envelope-from ) for ; Sat, 27 Apr 2024 02:19:58 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XhuhCV4U; dmarc=pass (policy=none) header.from=gmail.com; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1714177198; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=kLQTEiZhxHnr3+2ZFDCkNNuljxgHXUvqT5S+3KPcTxM=; b=V5z2+wUuECnBg02Kz5YgLzvesEgbwltZXFmxMDgC6jZH2qoHgjmj2V65n8v/MtT0pS4ATG k3CxjERuFWB3tA3Idn5dPY5bg/BzTAzQYo3PLZ4efy0gz+qiputVpDL6IGsKUe5fSFstif ZYQPwxFAso0rm9M9dIh70sr2vHwMAUJo/E3o6nWJ3szpyYNFgiJDKmKIGirdE4/ggBwDZU 0bkUx3nwBt2UyBggRtPoJWouQW/YJymOvN0qV4jn6zvB9L/VO/NmLs48sWjjNhMt55YZLg scU6rCoC8KhE7GmrxL50UtRLCYee54Le2p4wZ2nmCy/t8guDjgtjBHzssD0DJA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1714177198; a=rsa-sha256; cv=none; b=RP2NlBK9WaAJI+ZUGgXTe6eq29JFpyf4aNFwn5iUzDfJRp5NyavPrrn+zLsTSY5ywUvJBR kwIal52WngfKq2LLVSbQnQq4hVC3cM/Y36dI+xCv5tQv+rueqn1BC7DuR/6rLZnE1dc8ox J2RuPjelqSAh6QCJpM0Bv9/Fx/Yey/GTggKna7nSghI4QQHPsuZaTiqgOZsE2lAjetClgo bKhti6Do7qu4P0L8zP+sAB0C4aymNBhrosAXNh1/ikcz0cOqSBixDPaanomGAqkSj9RXsm fhsqS6BLHB+Wn4ZbkYFPZCPUTm9Bbl0hmSlB8r1BKcmlawD6mHxFkmyLzNOnxg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XhuhCV4U; dmarc=pass (policy=none) header.from=gmail.com; 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" 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 1CCC561094 for ; Sat, 27 Apr 2024 02:19:58 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s0Vml-00059g-5H; Fri, 26 Apr 2024 20:19:23 -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 1s0Vmc-000595-Jc for emacs-orgmode@gnu.org; Fri, 26 Apr 2024 20:19:15 -0400 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s0VmZ-00029i-Np for emacs-orgmode@gnu.org; Fri, 26 Apr 2024 20:19:14 -0400 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-5196fe87775so3036439e87.3 for ; Fri, 26 Apr 2024 17:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714177146; x=1714781946; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=kLQTEiZhxHnr3+2ZFDCkNNuljxgHXUvqT5S+3KPcTxM=; b=XhuhCV4UyGOay7rJ7nuvHLis35CNG6D3u9+tOz8gC8zyVzKJtfntevCg4wOcKk4wly FD5uneHdjd6qbB0j5NK+i34tDhmxv3IRdLtdyR3xhwJKg2ClTkVYyDEjkKgvebxJds1a g31Hom65ny6Ap8ND2TycvxT7Pls9HAXeX6vEyZ8p2ogiT/2X0FhpkiXiZqO9tii48ahq OUDRqF/C4GgQxdFsmfPCkWVeX5SXI1TQr9NQLJpZHL0tt/7ID+RvXF6Z+QlUg4AGkXt+ /ssxUQuxHj3m627R/hywbrS5synzG6uBAgDP4cR1zsdYqEFnTgzA4Q1tfqMdp6Eq6aZv R/JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714177146; x=1714781946; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kLQTEiZhxHnr3+2ZFDCkNNuljxgHXUvqT5S+3KPcTxM=; b=VfEujY/8q/NSEtEDGFt41JxHHWaCAGcytg9ADjHPiojMt21VGpUey28/TWlr8JcOgN x6YYGjNUN2rChWdz2Eh4TZRfJIXZKzE1VOqKEyA6I4S+2G/YQF8/r+E0MPxMl0sLlqZ7 FjIxsayieX7HXLeZChu3+F3YjyAX1mj0b4BPcKcJwvs+HNIFsFDQk3ftVUG/Dilq+RLt 3owcdwnXQid7QvdihEPJj34ekq1NlSDlIgbYN2B1zphILiFOFUluLgJJOmb1essIlD8N 7P+tCNq7eJswv441A4njlRxfWFJ/uhLA9hPP79suuJi/Z94JmG6m3k9m/OgcXHx/ZoTc 8ZZg== X-Gm-Message-State: AOJu0YxnfWKfMhSNs/kp54YTGmnNyuEsbMoBalzZ4Jk+6MGSlX32dngJ yaO9WJ1x/rtL3nAV0g6+HIkWRRiu+1+mD6Gj3knbyET6jbVuDMzFVmGZ56k+Lr27WxGi5GLa9WK 4omt0K3Pjpisu7YpLvmrLKcVCXhA= X-Google-Smtp-Source: AGHT+IFsKDSC5WfNlkMeRjaZibp3EBiE7bJtmyxigu4AYoqk5MRpOUNn8ROjQ/Zr4T9j4Q9l8j7tnUjj78dBXwoD6ks= X-Received: by 2002:a19:7417:0:b0:51c:c63c:c2af with SMTP id v23-20020a197417000000b0051cc63cc2afmr635282lfe.28.1714177145617; Fri, 26 Apr 2024 17:19:05 -0700 (PDT) MIME-Version: 1.0 References: <87mspgtexv.fsf@localhost> In-Reply-To: <87mspgtexv.fsf@localhost> From: Matt Price Date: Fri, 26 Apr 2024 20:18:54 -0400 Message-ID: Subject: Re: keeping subtree heading on export To: Ihor Radchenko Cc: Org Mode Content-Type: multipart/alternative; boundary="000000000000d8c6b4061708f75f" Received-SPF: pass client-ip=2a00:1450:4864:20::135; envelope-from=moptop99@gmail.com; helo=mail-lf1-x135.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, HTML_MESSAGE=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-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-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -6.70 X-Spam-Score: -6.70 X-Migadu-Queue-Id: 1CCC561094 X-Migadu-Scanner: mx11.migadu.com X-TUID: poz7LQs9eXNM --000000000000d8c6b4061708f75f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable thanks for the response, Ihor -- reply inline below: On Fri, Apr 26, 2024 at 9:45=E2=80=AFAM Ihor Radchenko wrote: > Matt Price writes: > > > ... I need to export each individual page > > of the "book" to its own markdown page. However, jupyter-book expects = to > > find the title of the page in the initial first-level heading. So I'd > like > > to retain the subtree "title" as a first-level heading, and demote the > > remaining headings to their original state within the larger org > document. > > > > Does anyone know of an existing exporter that already does this, from > which > > I can steal? Or if not, how would you suggest I go about doing this? > > May you provide an example demonstrating initial Org mode document and > how the exported md documents should look like? > > I don't think my request was very clear. Let's say I'm writing a "book" (really a documentation set of some kind) with several "chapters" (really, each chapter is an indiviual html page, though more complex nesting is permitted by jupyter-book). I write in org-mode: ----- * Chapter 1 text ** Chapter 1.1 text ** Chapter 1.2 * Chapter 2 text ** Chapter 2.1 text ----- And I want to produce two markdown files: chapter-1.md: ----- # Chapter 1 text ## Chapter 1.1 text ## Chapter 1.2 ------ chapter-2.md ---- # Chapter 2 text ## Chapter 2.1 text ----- I tried to learn a little more on my own after posting. I can set `org-md-toplevel-hlevel` to `2`, and then in the template function add the title property "manually" by extracting it from the info communication channel: ------ (defun org-myst-inner-template (contents info) "Return body of document after converting it to Markdown syntax. CONTENTS is the transcoded contents string. INFO is a plist holding export options." (let* ((depth (plist-get info :with-toc)) (headlines (and depth (org-export-collect-headlines info depth))) (toc-string (or (mapconcat (lambda (headline) (org-myst-format-toc headline info)) headlines "\n") "")) (toc-tail (if headlines "\n\n" "")) (front-matter (org-myst-front-matter)) (title (org-export-data (plist-get info :title) info))) (org-trim (concat front-matter toc-string toc-tail "\n" "# " title "\n\n" contents (org-myst-footnote-section info))))) ------ This works ok! But the problem ocmes because I would like to be able to *also* sometimes export a whole file (rather than just a subtree) using the same exporter.That's because I have inherited osme projects where files take hte form: chapter-1.org ------ * Chapter 1 text ** Chapter 1.1 text ** Chapter 1.2 ------ etc. The real problem I have is that, when exporting a subtree, I want to set org-md-toplevel-hlevel to "2" and add the title; when exporting a whole file, I want to set org-md-toplevel-hlevel to "1" and ignore the title. I don't think this is how org exporters are supposed to work, but I'm trying to interface to an established system that has chosen osme un-org-like conventions. Is this clearer, and do you see a way to do this? I am just looking at the source code and I wonder if I could add some (let) bindings inside org-myst-export-to-markdown and ....-as-markdown before calling org-export-to-[buffer|file]. hmm. Just tried it and it seems to work. Something seems wrong about this kind of code, though, in which I let-bind a variable in one function solely so that I can use it in another. Is there a better way? Un that case ,I would want to set > -- > Ihor Radchenko // yantar92, > Org mode contributor, > Learn more about Org mode at . > Support Org development at , > or support my work at > --000000000000d8c6b4061708f75f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
thanks for the response, Ihor -- reply inline below: =

On Fri, Apr 26, 2024 at 9:45=E2=80=AFAM Ihor Radchenko <yantar92@posteo.net> wrote:
Matt Price <moptop99@gmail.com> writes= :

> ... I need to export each individual page
> of the "book" to its own markdown page.=C2=A0 However, jupyt= er-book expects to
> find the title of the page in the initial first-level heading.=C2=A0 S= o I'd like
> to retain the subtree "title" as a first-level heading, and = demote the
> remaining headings to their original state within the larger org docum= ent.
>
> Does anyone know of an existing exporter that already does this, from = which
> I can steal? Or if not, how would you suggest I go about doing this?
May you provide an example demonstrating initial Org mode document and
how the exported md documents should look like?


I don't think my request was very = clear.=C2=A0 Let's say I'm writing a "book" (really a doc= umentation set of some kind) with several "chapters" (really, eac= h chapter is an indiviual html page, though more complex nesting is permitt= ed by jupyter-book).

I write in org-mode:

-----
* Chapter 1
text
** Chapter 1.1=
text
** Chapter 1.2
* Chapter 2
text
** Chapter 2.1
text=
-----

And I want to produce two mar= kdown files:

chapter-1.md:
-----
# Chapter 1
text
## =C2=A0Chapter 1.1
text
## =C2=A0Chapter = 1.2
------

chapter-2.md
----
# Chapter 2
text
## Chapter 2.1
text
-----

I tried to learn a little more on my own after postin= g.=C2=A0 I can set `org-md-toplevel-hlevel` to `2`, and then in the templat= e function add the title property "manually" by extracting it fro= m the info communication channel:

------
(defun org-myst-inner-template (contents info)
=C2=A0 "Return body= of document after converting it to Markdown syntax.
CONTENTS is the tra= nscoded contents string.=C2=A0 INFO is a plist
holding export options.&q= uot;
=C2=A0 (let* ((depth (plist-get info :with-toc))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(headlines (and depth (org-export-collect-headlines inf= o depth)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(toc-string (or (mapconcat = (lambda (headline)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (org-myst-format-toc headline info))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 headlines "\n")
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"= "))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(toc-tail (if headlines "= ;\n\n" ""))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(front-matt= er (org-myst-front-matter))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(title (or= g-export-data (plist-get info :title) info)))
=C2=A0 =C2=A0 (org-trim (c= oncat front-matter toc-string toc-tail "\n" "# " title = "\n\n" =C2=A0contents (org-myst-footnote-section info)))))
<= div>------

This works ok!=C2=A0 But the problem oc= mes because I would like to be able to *also* sometimes export a whole file= (rather than just a subtree) using the same exporter.That's because I = have inherited osme projects where files take hte form:

------
* Chapter 1
text
** Chapter 1.1
text
** Chapter 1.2
------
etc.=C2=A0

The real = problem I have is that, when exporting a subtree, I want to set org-md-topl= evel-hlevel to "2" and add the title; when exporting a whole file= , I want to set org-md-toplevel-hlevel to "1" and ignore the titl= e.=C2=A0

I don't think this is how org ex= porters are supposed to work, but I'm trying to interface to an establi= shed system that has chosen osme un-org-like conventions.=C2=A0
<= div>
Is this clearer, and do you see a way to do this?=C2=A0 = I am just looking at the source code and I wonder if I could add some (let)= bindings inside org-myst-export-to-markdown and ....-as-markdown before ca= lling org-export-to-[buffer|file].=C2=A0

hmm.= Just tried it and it seems to work.=C2=A0 Something seems wrong about this= kind of code, though, in which I let-bind a variable in one function solel= y so that I can use it in another.=C2=A0 Is there a better way?



=C2=A0Un that case ,I would= want to set
=C2=A0
--
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>
--000000000000d8c6b4061708f75f--