Skip to content

Conversation

@Crozzers
Copy link
Contributor

@Crozzers Crozzers commented Jul 2, 2022

This PR fixes a couple of issues.

Issue 1: AttributeError being raised when specifying some extras via emacs local variables

> import markdown2
> text = "-*- markdown-extras: footnotes -*-\nRandom unimportant text"
> markdown2.markdown(text, use_file_vars=True)
AttributeError: 'Markdown' object has no attribute 'footnotes'

This error happened because the self.footnotes dictionary is created by the self.reset() function, which is called BEFORE the emacs local variables get parsed. This means that the self.footnotes dictionary doesn't get created because, when it is called, the footnotes extra has not been specified.
This PR puts the self.footnotes dict creation (and some other extras setup) into a separate _setup_extras function which gets called during self.reset() and after the emacs local variables are parsed.

Issue 2: Emacs local variables appearing in the HTML output

Previously, an emacs one-liner would be parsed but have no changes made to it, meaning that it would appear in the final HTML.

> import markdown2
> text = "-*- markdown-extras: footnotes -*-\nRandom unimportant text"
> print(markdown2.markdown(text, use_file_vars=True))
<p>-<em>- markdown-extras: footnotes -</em>-</p>
<p>Random unimportant text</p>

This PR changes this so that these one-liners get automatically wrapped in HTML comments, so the output looks more like this:

<!-- -*- markdown-extras: footnotes -*- -->
<p>Random unimportant text</p>

Crozzers added 3 commits July 2, 2022 13:01
…variable.

The problem was that certain dictionaries/class attributes would only be created by the `reset` function which was called
before emacs style local variables were processed.
This commit moves this dictionary creation into a new `_setup_extras` function that is called during `self.reset()`
and also after the emacs style local variables have been processed.
@nicholasserra
Copy link
Collaborator

Awesome, thank you!

@nicholasserra nicholasserra merged commit 3e79e61 into trentm:master Jul 11, 2022
@Crozzers
Copy link
Contributor Author

Crozzers commented Jul 11, 2022

I've also edited the use file vars wiki page to show one-liner syntax examples better as previously it said emacs one-liners could be used like so:

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

Even though the library would only parse one-liners if they included the -*- markers. I've updated the example to the following:

-*- markdown-extras: code-friendly, footnotes -*-

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

Successfully merging this pull request may close these issues.

2 participants