emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Searching for a headline
@ 2017-02-26 13:41 Mark Meyer
  2017-02-26 15:27 ` Nicolas Goaziou
  0 siblings, 1 reply; 15+ messages in thread
From: Mark Meyer @ 2017-02-26 13:41 UTC (permalink / raw)
  To: emacs-orgmode

Hi,
I'm using org-publish-external-link to look up a the link target for a
headline. The following code works, although I'd expect it to fail:

(org-publish-resolve-external-link
  (concat "* " (org-element-property :raw-value headline))
  source-file)

``headline'' is a headline as returned by org-element, while
``source-file'' is a ``.org'' file.

I'd expect that this needs to be

(org-publish-resolve-external-link
  (concat (make-string (org-element-property :level headline) ?*)
   " " (org-element-property :raw-value headline))
  source-file)

I.e. for a level 3 headline it should be ``*** foobar'' and not ``*
foobar''. ``org-publish-resolve-external-link'' uses
``org-export-string-to-search-cell'' internally.

Can someone point me to some docuentation on how the searching works?

Cheers, Mark

-- 
  Mark Meyer
  mark@ofosos.org

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 13:41 Searching for a headline Mark Meyer
@ 2017-02-26 15:27 ` Nicolas Goaziou
  2017-02-26 16:11   ` Mark Meyer
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Goaziou @ 2017-02-26 15:27 UTC (permalink / raw)
  To: Mark Meyer; +Cc: emacs-orgmode

Hello,

Mark Meyer <mark@ofosos.org> writes:

> I'm using org-publish-external-link to look up a the link target for a
> headline. The following code works, although I'd expect it to fail:
>
> (org-publish-resolve-external-link
>   (concat "* " (org-element-property :raw-value headline))
>   source-file)
>
> ``headline'' is a headline as returned by org-element, while
> ``source-file'' is a ``.org'' file.
>
> I'd expect that this needs to be
>
> (org-publish-resolve-external-link
>   (concat (make-string (org-element-property :level headline) ?*)
>    " " (org-element-property :raw-value headline))
>   source-file)
>
> I.e. for a level 3 headline it should be ``*** foobar'' and not ``*
> foobar''. ``org-publish-resolve-external-link'' uses
> ``org-export-string-to-search-cell'' internally.
>
> Can someone point me to some docuentation on how the searching works?

The first argument for `org-publish-external-link' is a so-called
"fuzzy" search string. In such a string "*whatever" is meant to match
a headline named "whatever", whatever its level is. IOW, the "*"
character denotes a headline, not a level.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 15:27 ` Nicolas Goaziou
@ 2017-02-26 16:11   ` Mark Meyer
  2017-02-26 16:39     ` Nicolas Goaziou
  0 siblings, 1 reply; 15+ messages in thread
From: Mark Meyer @ 2017-02-26 16:11 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

On 02/26/17 16:27, Nicolas Goaziou wrote:
> The first argument for `org-publish-external-link' is a so-called
> "fuzzy" search string. In such a string "*whatever" is meant to match
> a headline named "whatever", whatever its level is. IOW, the "*"
> character denotes a headline, not a level.

Can you point me to a way to match a path in the tree?

Thanks.

Cheers, Mark
-- 
  Mark Meyer
  mark@ofosos.org

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 16:11   ` Mark Meyer
@ 2017-02-26 16:39     ` Nicolas Goaziou
  2017-02-26 16:58       ` Mark Meyer
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Goaziou @ 2017-02-26 16:39 UTC (permalink / raw)
  To: Mark Meyer; +Cc: emacs-orgmode

> Can you point me to a way to match a path in the tree?

There isn't. Internal links do not point to paths in the tree. You can,
however, point to a specific headline using its unique name, if
possible, or a custom ID otherwise.

Regards,

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 16:39     ` Nicolas Goaziou
@ 2017-02-26 16:58       ` Mark Meyer
  2017-02-26 17:28         ` Nicolas Goaziou
  0 siblings, 1 reply; 15+ messages in thread
From: Mark Meyer @ 2017-02-26 16:58 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

On 02/26/17 17:39, Nicolas Goaziou wrote:
> There isn't. Internal links do not point to paths in the tree. You can,
> however, point to a specific headline using its unique name, if
> possible, or a custom ID otherwise.

What do you mean by unique name? Is this a property that is available
via org-element or do I have to set this in the source document?

I'm trying to link to all the headlines from a table of contents (EPUB
expoerter). Basically I'm using a `:completion-function' to generate all
the meta data and I need to link to most of the headlines down to a
certain level during the toc generation.

Thanks.

Cheers, Mark
-- 
  Mark Meyer
  mark@ofosos.org

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 16:58       ` Mark Meyer
@ 2017-02-26 17:28         ` Nicolas Goaziou
  2017-02-26 17:54           ` Mark Meyer
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Goaziou @ 2017-02-26 17:28 UTC (permalink / raw)
  To: Mark Meyer; +Cc: emacs-orgmode

Mark Meyer <mark@ofosos.org> writes:

> What do you mean by unique name? Is this a property that is available
> via org-element or do I have to set this in the source document?

According to its docstring, `org-publish-resolve-external-link' is used
to resolve the following links:

  [[file.org::*heading][description]]
  [[file.org::#custom-id][description]]
  [[file.org::fuzzy][description]]

It is used by the exporter, and it assumes "file.org" belongs to the
publishing project.

IOW, if you are not writing an export back-end, this is not the right
tool.

> I'm trying to link to all the headlines from a table of contents (EPUB
> expoerter). Basically I'm using a `:completion-function' to generate all
> the meta data and I need to link to most of the headlines down to a
> certain level during the toc generation.

I don't know the EPUB exporter. You probably could modify the Org source
itself instead of the output.

Regards,

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 17:28         ` Nicolas Goaziou
@ 2017-02-26 17:54           ` Mark Meyer
  2017-02-26 18:12             ` Nicolas Goaziou
  2017-02-26 19:32             ` Eric Abrahamsen
  0 siblings, 2 replies; 15+ messages in thread
From: Mark Meyer @ 2017-02-26 17:54 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

On 02/26/17 18:28, Nicolas Goaziou wrote:
> I don't know the EPUB exporter. You probably could modify the Org source
> itself instead of the output.

I wrote it yesterday, the code's up at

 https://github.com/ofosos/org-epub

it's a little crufty, because I did write it for org 8 initially.

Hmm, I have to think about it. I would like to either have a 1:1 mapping
between the elements `org-element' delvers and the links the export
backend generates or create a function that runs before the export that
generates :custom_id properties for every element that doesn't have one.

This was easier in org 8, since every internal link was just something
like `sec-8-2'.

Thanks for you quick replies.

Cheers, Mark
-- 
  Mark Meyer
  mark@ofosos.org

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 17:54           ` Mark Meyer
@ 2017-02-26 18:12             ` Nicolas Goaziou
  2017-02-26 18:21               ` Mark Meyer
  2017-02-26 19:32             ` Eric Abrahamsen
  1 sibling, 1 reply; 15+ messages in thread
From: Nicolas Goaziou @ 2017-02-26 18:12 UTC (permalink / raw)
  To: Mark Meyer; +Cc: emacs-orgmode

Mark Meyer <mark@ofosos.org> writes:

> On 02/26/17 18:28, Nicolas Goaziou wrote:
> I wrote it yesterday, the code's up at
>
>  https://github.com/ofosos/org-epub

Great.

> it's a little crufty, because I did write it for org 8 initially.
>
> Hmm, I have to think about it. I would like to either have a 1:1 mapping
> between the elements `org-element' delvers and the links the export
> backend generates or create a function that runs before the export that
> generates :custom_id properties for every element that doesn't have
> one.

Did you look at `org-html--format-toc-headline'?

Also, if you want to collect headlines above a given level, there is
`org-export-collect-headlines'.

> This was easier in org 8, since every internal link was just something
> like `sec-8-2'.

It is also easy in Org 9 : (org-export-get-reference headline info). See
its use in the function above.

Regards,

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 18:12             ` Nicolas Goaziou
@ 2017-02-26 18:21               ` Mark Meyer
  2017-02-26 18:28                 ` Nicolas Goaziou
  0 siblings, 1 reply; 15+ messages in thread
From: Mark Meyer @ 2017-02-26 18:21 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

On 02/26/17 19:12, Nicolas Goaziou wrote:
> It is also easy in Org 9 : (org-export-get-reference headline info). See
> its use in the function above.

I am under the impression that I don't have access to the `INFO' plist
that is required by `org-export-get-reference' - at least not from the
`:completion-function'.

I'll definitely looking into `org-export-collect-headlines'.

Cheers, Mark
-- 
  Mark Meyer
  mark@ofosos.org

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 18:21               ` Mark Meyer
@ 2017-02-26 18:28                 ` Nicolas Goaziou
  2017-02-26 18:30                   ` Mark Meyer
  2017-02-26 21:46                   ` Mark Meyer
  0 siblings, 2 replies; 15+ messages in thread
From: Nicolas Goaziou @ 2017-02-26 18:28 UTC (permalink / raw)
  To: Mark Meyer; +Cc: emacs-orgmode

Mark Meyer <mark@ofosos.org> writes:

> On 02/26/17 19:12, Nicolas Goaziou wrote:
>> It is also easy in Org 9 : (org-export-get-reference headline info). See
>> its use in the function above.
>
> I am under the impression that I don't have access to the `INFO' plist
> that is required by `org-export-get-reference' - at least not from the
> `:completion-function'.

Since you're writing the back-end, you don't need to
use :completion-function, do you?

Just write the TOC the way you like.

Regards,

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 18:28                 ` Nicolas Goaziou
@ 2017-02-26 18:30                   ` Mark Meyer
  2017-02-26 21:46                   ` Mark Meyer
  1 sibling, 0 replies; 15+ messages in thread
From: Mark Meyer @ 2017-02-26 18:30 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

On 02/26/17 19:28, Nicolas Goaziou wrote:
> Since you're writing the back-end, you don't need to
> use :completion-function, do you?
> 
> Just write the TOC the way you like.

Yay! You're completely right. The use case is, folding multiple
documents into a single EPUB (via a project), but I can easily write the
partial tocs into one/multiple temp buffers and copy them over after that.

Thanks.

Cheers, Mark

-- 
  Mark Meyer
  mark@ofosos.org

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 17:54           ` Mark Meyer
  2017-02-26 18:12             ` Nicolas Goaziou
@ 2017-02-26 19:32             ` Eric Abrahamsen
  2017-02-26 20:40               ` Mark Meyer
  1 sibling, 1 reply; 15+ messages in thread
From: Eric Abrahamsen @ 2017-02-26 19:32 UTC (permalink / raw)
  To: emacs-orgmode

Mark Meyer <mark@ofosos.org> writes:

> On 02/26/17 18:28, Nicolas Goaziou wrote:
>> I don't know the EPUB exporter. You probably could modify the Org source
>> itself instead of the output.
>
> I wrote it yesterday, the code's up at
>
>  https://github.com/ofosos/org-epub
>
> it's a little crufty, because I did write it for org 8 initially.

This is cool to see! It's something I always wanted for Org. A couple of
years ago I barely got off the ground with something I was
(optimistically) calling epub-mode, which would be a dired-based mode
for creating/editing Epub files. The idea was always to later add Org
export/publish support, to do what you're doing in this package.

I put together just the very beginnings of the package, I think it's
capable of unzipping and re-zipping an Epub file, and generating a new
(empty) template directory structure. Take a look and see if anything in
there is interesting to you -- I think its main strength is using esxml
to generate the XML files, so you don't have to do that with strings.
The idea was that that would also make it easier to manipulate resources
later on, while editing. Anyway, it ain't much:

https://github.com/girzel/epub-mode/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 19:32             ` Eric Abrahamsen
@ 2017-02-26 20:40               ` Mark Meyer
  2017-02-26 21:34                 ` Eric Abrahamsen
  0 siblings, 1 reply; 15+ messages in thread
From: Mark Meyer @ 2017-02-26 20:40 UTC (permalink / raw)
  To: emacs-orgmode

On 02/26/17 20:32, Eric Abrahamsen wrote:
> I put together just the very beginnings of the package, I think it's
> capable of unzipping and re-zipping an Epub file, and generating a new
> (empty) template directory structure. Take a look and see if anything in
> there is interesting to you -- I think its main strength is using esxml
> to generate the XML files, so you don't have to do that with strings.
> The idea was that that would also make it easier to manipulate resources
> later on, while editing. Anyway, it ain't much:
> 
> https://github.com/girzel/epub-mode/

Oh, this is nice :) That's a very good use of esxml. I definitely like it.

I thought about doing the zipping in `org-epub', but had to get some
other stuff working first. But you already wrote the code :)

Cheers, Mark
-- 
  Mark Meyer
  mark@ofosos.org

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 20:40               ` Mark Meyer
@ 2017-02-26 21:34                 ` Eric Abrahamsen
  0 siblings, 0 replies; 15+ messages in thread
From: Eric Abrahamsen @ 2017-02-26 21:34 UTC (permalink / raw)
  To: emacs-orgmode

Mark Meyer <mark@ofosos.org> writes:

> On 02/26/17 20:32, Eric Abrahamsen wrote:
>> I put together just the very beginnings of the package, I think it's
>> capable of unzipping and re-zipping an Epub file, and generating a new
>> (empty) template directory structure. Take a look and see if anything in
>> there is interesting to you -- I think its main strength is using esxml
>> to generate the XML files, so you don't have to do that with strings.
>> The idea was that that would also make it easier to manipulate resources
>> later on, while editing. Anyway, it ain't much:
>> 
>> https://github.com/girzel/epub-mode/
>
> Oh, this is nice :) That's a very good use of esxml. I definitely like it.
>
> I thought about doing the zipping in `org-epub', but had to get some
> other stuff working first. But you already wrote the code :)

Now's when I admit to having stolen most of the zipping stuff from
ox-odt :)

And yes, I think keeping everything in sexps until the last possible
moment is going to make the whole project much more viable.

Anyway, see what you want to do with that. I'm still theoretically
interested in having a non-org-related package that can be used for
creating and editing Epub files, and then providing a secondary package
that publishes a set of Org files into Epub, using the first package.
But obviously I've been in no hurry to write this package :) Maybe your
work will inspire me to get off my butt; otherwise use the code as you
see fit.

E

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Searching for a headline
  2017-02-26 18:28                 ` Nicolas Goaziou
  2017-02-26 18:30                   ` Mark Meyer
@ 2017-02-26 21:46                   ` Mark Meyer
  1 sibling, 0 replies; 15+ messages in thread
From: Mark Meyer @ 2017-02-26 21:46 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

On 02/26/17 19:28, Nicolas Goaziou wrote:
> Since you're writing the back-end, you don't need to
> use :completion-function, do you?
> 
> Just write the TOC the way you like.

I defined `*org-epub-current-file*' as a special variable and set it in
the publish function. Then I extracted the headlines in
`org-epub-template' (should find a better place). And this works like a
charm.

And now I can use the same heading text multiple times and get a proper
export.

Thank you very much.

Cheers, Mark
-- 
  Mark Meyer
  mark@ofosos.org

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-02-26 21:46 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-26 13:41 Searching for a headline Mark Meyer
2017-02-26 15:27 ` Nicolas Goaziou
2017-02-26 16:11   ` Mark Meyer
2017-02-26 16:39     ` Nicolas Goaziou
2017-02-26 16:58       ` Mark Meyer
2017-02-26 17:28         ` Nicolas Goaziou
2017-02-26 17:54           ` Mark Meyer
2017-02-26 18:12             ` Nicolas Goaziou
2017-02-26 18:21               ` Mark Meyer
2017-02-26 18:28                 ` Nicolas Goaziou
2017-02-26 18:30                   ` Mark Meyer
2017-02-26 21:46                   ` Mark Meyer
2017-02-26 19:32             ` Eric Abrahamsen
2017-02-26 20:40               ` Mark Meyer
2017-02-26 21:34                 ` Eric Abrahamsen

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).