bordaigorl / sublime-evernote

Open and Save Evernote notes from Sublime Text 3 using Markdown
Other
1.15k stars 105 forks source link

No closing </em> error - Grab Evernote Markdown before sync? #25

Open mAAdhaTTah opened 10 years ago

mAAdhaTTah commented 10 years ago

I'm getting this error when trying to export a .md file to Evernote. It's probably an issue in my Markdown, rather than an export issue, but is there some way to grab the EML file from this plugin so I can look at it to see where the issue is?

bordaigorl commented 10 years ago

You have two options:

  1. either you modify the sourcecode of the plugin to set the DEBUG variable to True
  2. or in ST's console you do from Evernote.lib.markdown2 import markdown as md and then you can call md("some *markdown* code _here_") and see what the output is
mAAdhaTTah commented 10 years ago

I'm unfortunately not terribly familiar with python - what would I run to run it over the whole file? And the source code isn't made available if you install via package manager :(.

mAAdhaTTah commented 10 years ago

Nevermind, I'll figure it out, thanks.

bordaigorl commented 10 years ago

From the console, after doing

from Evernote.lib.markdown2 import markdown as md

and

from Evernote.sublime_evernote import EvernoteDo

you can do

 print(md(view.substr(sublime.Region(0,view.size())), EvernoteDo.MD_EXTRAS))

to visualize the output of the markdown parser on the whole file.

mAAdhaTTah commented 10 years ago

Actually, this might be a bug. Here's the Markdown:

* error reporting
    * search for error_reporting, look at suggested values
    * search for html_errors, turn to On
* output buffering
    * output_buffering
* timezone
    * set default timezone - used America/New_York
    * sometimes, there's another ini file that also has the timezone, 99-stuff, may have other stuff

And the output:

<ul>
<li>error reporting
<ul>
<li>search for error<em>reporting, look at suggested values</li>
<li>search for html</em>errors, turn to On</li>
</ul></li>
<li>output buffering
<ul>
<li>output_buffering</li>
</ul></li>
<li>timezone
<ul>
<li>set default timezone - used America/New_York</li>
<li>sometimes, there's another ini file that also has the timezone, 99-stuff, may have other stuff</li>
</ul></li>
</ul>

It's adding these random <em>s.

Edit: not random, turning _ -> <em>s incorrectly.

mAAdhaTTah commented 10 years ago

It does this to underscores within code blocks too.

bordaigorl commented 10 years ago

Have you tried turning the code_friendly setting on?

bordaigorl commented 10 years ago

Ok, I think I can confirm this is a bug of the markdown parser. It might be worth opening an issue at trentm/python-markdown2

It should work with the code_friendly setting set to true though (set it in your Evernote.sublime-settings file)

Another workaround is escaping the _ with \_ as in

* error reporting
    * search for error\_reporting, look at suggested values
    * search for html\_errors, turn to On
* output buffering
    * output\_buffering
* timezone
    * set default timezone - used America/New\_York
    * sometimes, there's another ini file that also has the timezone, 99-stuff, may have other stuff

Yet another reason why we should try to migrate to a better converter...this one was chosen by previous developers so I was sticking to it but it is a bit buggy and difficult to modify...

mAAdhaTTah commented 10 years ago

Switch, imo. Can I help at all?

bordaigorl commented 10 years ago

@mAAdhaTTah thanks for offering your help! First: does the code_friendly setting solve your problem for the moment? As for the switch I have been considering switching to mistune which seems to support all the important extensions plus it is much easier to maintain and modify.

The main changes involve not producing any forbidden elements or attributes which include things like id or style. Plus, inlining of style and pygments highligting should be added. All of this should be possible by just adding a subclass of Renderer. My modified version of markdown2.py also supported todo-boxes with a syntax similar to that of github task lists...

If you'd like to give this a try fork the repo, start a new branch called mistune and then submit a PR, even if partial, so you can receive feedback along the way.

mAAdhaTTah commented 10 years ago

Sounds good - I'm not sure when I'll get to this, tbh, but I've added it to my project list.

bordaigorl commented 10 years ago

@mAAdhaTTah good :+1: I forgot to mention: if we do switch it would be a good chance to revamp the metadata parsing (it's not included in mistune) using a proper YAML parser as pyYAML. This way we can more easily support

  1. note guid in metadata
  2. custom metadata for local copies of notes
lepture commented 10 years ago

BTW. Mistune is faster than markdown2 and more correct than markdown2. If you have any trouble with mistune, you can always ping me.

bordaigorl commented 10 years ago

@lepture I know! It's just I made many modifications to markdown2 to make it work properly and now I would have to write a custom renderer for mistune. It would be for sure a better solution than the current one (my modifications are allover the place and difficult to maintain because of the hackish structure of the original script) but it requires time for testing...it's in the roadmap anyways =) Something I support with my custom markdown2 and which is not supported by mistune AFAIK is Github-style checkboxes. Any hint on how to add that?

lepture commented 10 years ago

@bordaigorl you can approach it with two ways.

  1. extends the lexer for list
  2. extends the renderer for list item

I think extending the renderer is simpler.

def list(self, text):
    # do something with text
    # for example
    checkbox, raw = gfm_checkbox(text)
    if checkbox:
        return '<li><input type="checkbox">%s</li>' % raw
    return '<li>%s</li>' % raw
nicholasserra commented 10 years ago

Out of the box, markdown adding emphasis in the middle of works is a grey area. As stated, in markdown2, if you want to remove the underscore -> emphasis conversion, you can use the code-friendly extra. Right now we don't have github flavored markdown as an extra, and recommend handing that in your application.

freshfey commented 8 years ago

Was there ever an update on this? I've both checked code_style and escaping the character, no success

bordaigorl commented 8 years ago

Hi @freshfey the setting you should try is not code_style as you wrote, but code_friendly. Specifically, you should open your Evernote settings and set

"code_friendly": true

if you want to have _s interpreted as normal characters inside a word.

If this does not work, I will need to see some input that allows me to reproduce your issue.

freshfey commented 8 years ago

@bordaigorl sorry, I meant to write code_friendly.

I've tried it with a new file in the mean time and it seems to work now! It could be that the one imported from Evernote was corrupted somehow because there was a lot of formatting going on