I have a very complex (at least to my mind) text replacement task. ideally this would be a function or macro I could run over every org header in a buffer.
I want to
1. move over any TODO state to a line beneath the header starting with tags:
2. then move over any org tags following that todo state into the tags line proceeded by a comma
the issue is that of course the org header changes in depth across the file and the header name changes of course.
this is for getting ready to use org export to markdown. since org markdown export cant convert org tags and states into markdown tags I want this step of pre proceesing. I would then export each changed heading to md and use the first line as meatadata.
the markdown app can the read these exported tags and thus keeping/"exporting" my org rating and todo state .
as an example this org section:
*** ✔ Kopitiam :3star:
pretty good malasyian food. Had a nice frothy tea, the nasi lamak and blue rice with pandan cream
all was ok but nothing outstanding
*** Brussels
**** ✔ Tonton Garby :3star:
very good sandwhices in brussels
would look like this after the find and replace
*** Kopitiam
tags: #✔ , #3star
pretty good malasyian food. Had a nice frothy tea, the nasi lamak and blue rice with pandan cream
all was ok but nothing outstanding
*** Brussels
**** Tonton Garby
tags: #✔ , #3star
very good sandwhices in brussels
is something like that even possible within emacs or do I need to some other tools like python?
EDIT:
someone helped me try a outside emacs solution using perl
#!/usr/bin/env perl
use strict;
use warnings;
sub fmt_tags {
return unless defined $+{tags};
map {q/#/ . $_} $+{tags} =~ /\w+/g
}
sub check_tag {
defined $+{checked}? q{#} . $+{checked} : q{}
}
while (<>) {
s/
(?<stars>[*]{2,4})
\s+
(?<checked>✔)?
\s+
(?<title>.+?)
\s+
((?<tags>:.+\n)?|\n)$
/$+{stars} $+{title}\ntags: @{[join ', ', check_tag(), fmt_tags()]}\n/x;
print;
}
this seems to work, yet docent really pick up the TOVISIT
tags...
pandoc
? It can export Org mode files to Markdown of various flavors. But you might want to add more details in your question.tags: #tag1,#tag2
. I want to not loose the org data such as tags and todo state and thus transfer it as "metadata" in my exported md files after I fix the org file.