1

I use Pandoc to convert from HTML and Markdown to org-mode. The conversion leaves lots of extraneous org-mode PROPERTIES drawers. How can I direct org-mode to delete all PROPERTIES drawers?

ADDITION: I'm using this shell script to run the conversion.

function pandoc2org () {
    basename=${1%%.*}                       # remove old file extension
    pandoc -s -S "$1" -o $basename.org      # name file as oldfile.org 
}
  • 1
    Why not a shell script to remove all lines starting with : ? You can pipe the output of pandoc directly into it. Or are there other drawers after the conversion too? – dangom Apr 3 '17 at 23:24
  • @dangom How would I do that? – incandescentman Apr 3 '17 at 23:26
  • 1
    Tried pandoc -t org file.md | sed '/^:/ d' to do that right now. Problem is the indentation (pandoc adding whitespaces). I'll get it working and post as an answer in a min – dangom Apr 3 '17 at 23:32
2

If you don't mind using a shell script to accomplish what you want, you can try:

pandoc -t org file.md | sed -E "/^[[:space:]]+:/ d" > file.org

This will remove all lines starting with one (or more) spaces followed by a semicolon.

I believe you can fit it into your script by doing the following:

function pandoc2org () {
    basename=${1%%.*}                      
    pandoc -s -S "$1" -t org | sed -E "/^[[:space:]]+:/ d" > $basename.org
}

You can find an explanation of the function here.

  • 1
    Let me know if it doesn't work – dangom Apr 3 '17 at 23:37
  • Thanks! How would I add this to my existing script? – incandescentman Apr 3 '17 at 23:44
  • @incandescentman just added an edit – dangom Apr 3 '17 at 23:57
  • Do you also know how to get the sed command to replace non-breaking spaces (codepoint 160, #o240, #xa0) with regular spaces? I tried adding sed 's/\xA0/ /g' but it didn't work. – incandescentman Apr 4 '17 at 3:08
  • 1
    Reading the documentation you'll see that the -S option you are using in your script forces the insertion of non-breaking spaces. If there is no particular reason for you to use it, remove it. – dangom Apr 4 '17 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.