1

I have a folder with some files written in markdown format that I would like to convert in html using markdown-mode.

I want a local value for the variable markdown-css-paths, in order to have a custom file as style sheet of the resulting html files. So, I create a .dir-locals.el file in the same folder of the markdown files and inside it I put this:

((markdown-mode
 (markdown-css-paths ("test.css"))))

I reload all the buffers, then invoke C-h v markdown-css-paths [RET] to make sure the variable is set correctly, which it is:

markdown-css-paths is a variable defined in ‘markdown-mode.el’.
Its value is (("test.css"))
Original value was nil
Local in buffer nuovo-corso.md; global value is nil

The problem is: when I try to convert the files in html (with the command C-c C-c m), no test.css style sheet is included.

The same thing happend with at least another variable, markdown-xhtml-header-content: it seems as if, during conversion, markdown-mode doesn't rely on the .dir-locals.el variable values.

When, instead, I set those variables in .emacs, everything works as expected.

What am I doing wrong? I'm using emacs 26.1 and markdown-mode 20180904.1601.

1

I think you are using the wrong syntax in your .dir-locals.el. You should use association lists, rather than regular lists. i.e., :

((markdown-mode . ((markdown-css-paths  . "test.css"))))

When I do this, the value of markdown-css-paths is "test.css", which is a character string. That's what you need. In your example, the value of markdown-css-paths is actually set to (("test.css")), which isn't a string, it's a list containing a list that contains a string.

This is explained in the manual at (emacs) Directory Variables. You can find that by:

  • C-h r, which opening the manual (aka 'r'ead manual)
  • m, which then prompts you for an item from the menu
  • Directory Variables, which you can then enter, with the help of tab completion.
  • Thanks for your reply! I've read the manual entry you suggested and modified .dir-locals.el to use association lists. Sadly, it still doesn't work: markdown-mode outputs html without the correct css file associated. I've also tried to change "test.css" to ("test.css") (markdown-css-paths is not a string but a list of string, this was another mistake I made) but without success. – cvd-00 Sep 28 '18 at 21:45
  • Hmm. I think the problem is that dir-local variables are only in effect for buffers visiting a file in the directory in question. markdown-mode creates the markdown buffers without actually creating a file in the directory first, so the directory local settings don't get applied. I'm not sure how to fix this. – Tyler Oct 1 '18 at 15:54

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.