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

Adding Support for webclips and new codeblocks #210

Open
wants to merge 6 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions lib/html2text.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def tag_str(tag, attrs, start):
if start:
attr_str = ""
for k in attrs:
attr_str += (' %s="%s"' % (k, attrs[k]))
attr_str += (' %s="%s"' % (k, attrs[k].replace('"',"'")))
return "<%s%s%s>" % (tag, attr_str, '/' if start == 2 else '')
else:
return "</%s>" % tag
Expand Down Expand Up @@ -444,23 +444,50 @@ def handle_tag(self, tag, attrs, start):
self.inheader = False
return # prevent redundant emphasis marks on headers

if attrs and "-evernote-webclip" in attrs.get("style", "") and start:
if start:
self.out('\n\n'+tag_str(tag, attrs, start)+'\n ')
else:
self.out('\n'+tag_str(tag, attrs, start)+'\n\n')
self.verbatim = [tag, 1]
return

if tag == 'div':
if self.google_doc:
if start and google_has_height(tag_style):
self.p()
else:
self.soft_br()
self.br()
else:
if start == 1:
if attrs and attrs.get("title") != "footnotes":
if attrs and '-en-paragraph:true' in attrs.get("style"):
self.block_stack.append(False)
self.p()
elif attrs and '-en-codeblock:true' in attrs.get("style"):
self.o("```")
self.block_stack.append("encodeblock")
self.pre = "encodeblock"
self.startpre = 1
elif self.pre:
self.block_stack.append(False)
elif attrs and attrs.get("title") != "footnotes":
self.block_stack.append(True)
self.o(tag_str(tag+' markdown="1"', attrs, start))
self.p()
else:
self.block_stack.append(False)
self.p()
elif start == 0:
if self.block_stack.pop():
t = self.block_stack.pop()
if t == "encodeblock":
self.pre = 0
self.o("```")
elif t == True:
self.o('</%s>' % tag)
self.p()
elif self.pre:
self.pbr()
else:
self.p()

if tag == 'p':
if self.google_doc:
Expand Down Expand Up @@ -738,7 +765,9 @@ def o(self, data, puredata=0, force=0):
bq = (">" * self.blockquote)
if not (force and data and data[0] == ">") and self.blockquote: bq += " "

if self.pre == "indent":
if self.verbatim:
data = data.replace("\n", "\n ")
elif self.pre == "indent":
if not self.list:
bq += " "
#else: list content is already partially indented
Expand Down
1 change: 1 addition & 0 deletions sublime_evernote.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ def load_settings(self):
css[tag] = css[tag].strip()
if len(css[tag]) > 0 and not css[tag].endswith(";"):
css[tag] = css[tag] + ";"
css['pre'] = css.get('pre', "") + "-en-codeblock:true;"
EvernoteDo.MD_EXTRAS['inline-css'] = css
self.md_syntax = self.settings.get("md_syntax")
if not self.md_syntax:
Expand Down