Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emacs style extras comment not working as expected #365

Open
dflogeras opened this issue Jul 24, 2020 · 4 comments
Open

Emacs style extras comment not working as expected #365

dflogeras opened this issue Jul 24, 2020 · 4 comments

Comments

@dflogeras
Copy link

Hello, the documentation here:

https://github.com/trentm/python-markdown2/wiki/Extras

Indicates you can embed which extras you would like enabled in a comment. I've tried that verbatim and it doesn't seem to work for me. After looking in the code, it appears to me (not an expert by any means) that it also wants to see the emacs tokens '-*-' before and after the comment. I also tried that, to no avail.

Finally, the help indicates that "use-file-vars: Look for an Emacs-style markdown-extras file variable to turn
on Extras." might be necessary although the code seems to not use it. I tried for fun, but still nothing.

Some clarification would be greatly appreciated, I like the idea of this feature so I can stop trying to remember "how did I process this particular file?" and just embed it.

@ghost
Copy link

ghost commented Nov 21, 2020

I also tried this on the beginning of the document and at the end , and it is simply not working.:

<!--
  Local Variables: classesDict = {"table":"table"}
  markdown-extras: "attr_list", "attr_plus", "html-classes":classesDict
  End:
  -->

and I tried the one-liner ( and I know, it is boring) it does also not work

<!-- markdown-extras: code-friendly, footnotes -->

It looks like the fenced-code-blocks does also not work and the use-file-vars

@Crozzers
Copy link
Contributor

Crozzers commented Jul 2, 2022

Have you tried passing in the use_file_vars kwarg?

import markdown2

text = """<!-- markdown-extras: code-friendly, footnotes -->
This markdown text will be converted with the "code-friendly" and "footnotes"
extras enabled."""

markdown2.markdown(text, use_file_vars=True)

EDIT:
After peeking into the source code it turns out that even though the wiki states that emacs var one-liners use <!-- [stuff] -->, the function _get_emacs_vars looks for one-liners like -*- [stuff] -*-. When using the latter syntax, it is not removed from the final HTML and when using the former syntax it is not detected correctly

@dflogeras
Copy link
Author

dflogeras commented Jul 2, 2022

@Crozzers

Interesting, after your comment regarding -*- I think I found the missing link (or at least for me wishing to run from the command line).

I embedded this:
<!-- -*- markdown-extras: yadda,yadda -*- -->

Then executed the standalone module using
markdown2 --use-file-vars=doesntmatter myfile.md

instead of the documented way:
markdown2 -x use-file-vars myfile.md

And that both takes effect, and also doesn't appear in the final html. It's a bit weird, and not sure why --use-file-vars takes an arg, but it works here for me.

@Crozzers
Copy link
Contributor

Crozzers commented Jul 2, 2022

It's a bit weird, and not sure why --use-file-vars takes an arg

The use_file_vars "extra" doesn't get passed in via the extras dictionary, it gets passed as a separate kwarg, as you can see from the snippet below:

def markdown(text, html4tags=False, tab_width=DEFAULT_TAB_WIDTH,
safe_mode=None, extras=None, link_patterns=None,
footnote_title=None, footnote_return_symbol=None,
use_file_vars=False, cli=False):

In any case, I've submitted a pull request that should take one-liners (like -*- [stuff] -*-) and wrap them in HTML comment tags so that they don't appear (visible) in the final HTML output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants