Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	st3/mdpopups/rgba.py
  • Loading branch information
facelessuser committed Dec 15, 2015
2 parents a49674a + 0aaac6d commit 83d9d80
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 37 deletions.
15 changes: 4 additions & 11 deletions st3/mdpopups/mdx/betterem.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
# Smart rules for when "smart underscore" is enabled
# SMART: ___strong,em___
SMART_UNDER_STRONG_EM = r'(?<!\w)(_{3})(?![\s_])%s(?<!\s)\2(?!\w)' % SMART_UNDER_CONTENT
# ___strong,em_strong__
# ___strong,em_ strong__
SMART_UNDER_STRONG_EM2 = \
r'(?<!\w)(_{3})(?![\s_])%s(?<!\s)_(?!\w)%s(?<!\s)_{2}(?!\w)' % (SMART_UNDER_MIXED_CONTENT, SMART_UNDER_CONTENT)
# ___em,strong__em_
# ___em,strong__ em_
SMART_UNDER_EM_STRONG = \
r'(?<!\w)(_{3})(?![\s_])%s(?<!\s)_{2}(?!\w)%s(?<!\s)_(?!\w)' % (SMART_UNDER_MIXED_CONTENT, SMART_UNDER_CONTENT)
# __strong__
Expand All @@ -74,12 +74,12 @@
# Smart rules for when "smart asterisk" is enabled
# SMART: ***strong,em***
SMART_STAR_STRONG_EM = r'(?:(?<=_)|(?<![\w\*]))(\*{3})(?![\s\*])%s(?<!\s)\2(?:(?=_)|(?![\w\*]))' % SMART_STAR_CONTENT
# ***strong,em*strong**
# ***strong,em* strong**
SMART_STAR_STRONG_EM2 = \
r'(?:(?<=_)|(?<![\w\*]))(\*{3})(?![\s\*])%s(?<!\s)\*(?:(?=_)|(?![\w\*]))%s(?<!\s)\*{2}(?:(?=_)|(?![\w\*]))' % (
SMART_STAR_MIXED_CONTENT, SMART_STAR_CONTENT
)
# ***em,strong**em*
# ***em,strong** em*
SMART_STAR_EM_STRONG = \
r'(?:(?<=_)|(?<![\w\*]))(\*{3})(?![\s\*])%s(?<!\s)\*{2}(?:(?=_)|(?![\w\*]))%s(?<!\s)\*(?:(?=_)|(?![\w\*]))' % (
SMART_STAR_MIXED_CONTENT, SMART_STAR_CONTENT
Expand All @@ -89,10 +89,6 @@
# SMART *em*
SMART_STAR_EM = r'(?:(?<=_)|(?<![\w\*]))(\*)(?![\s\*])%s(?<!\s)\2(?:(?=_)|(?![\w\*]))' % SMART_STAR_CONTENT

smart_enable_keys = [
"all", "asterisk", "underscore", "none"
]


class BetterEmExtension(Extension):
"""Add extension to Markdown class."""
Expand All @@ -104,9 +100,6 @@ def __init__(self, *args, **kwargs):
'smart_enable': ["underscore", "Treat connected words intelligently - Default: underscore"]
}

if "smart_enable" in kwargs and kwargs["smart_enable"] not in smart_enable_keys:
del kwargs["smart_enable"]

super(BetterEmExtension, self).__init__(*args, **kwargs)

def extendMarkdown(self, md, md_globals):
Expand Down
13 changes: 6 additions & 7 deletions st3/mdpopups/mdx/inlinehilite.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@
from __future__ import unicode_literals
from markdown import Extension
from markdown.inlinepatterns import Pattern
try:
from markdown.extensions import codehilite
except:
codehilite = None
from markdown.extensions import codehilite
# import traceback
try:
from pygments import highlight
Expand Down Expand Up @@ -155,7 +152,7 @@ def get_settings(self):
self.use_pygments = self.config['use_pygments']
self.use_codehilite_settings = self.config['use_codehilite_settings']
self.style_plain_text = self.config['style_plain_text']
if codehilite and self.use_codehilite_settings:
if self.use_codehilite_settings:
for ext in self.markdown.registeredExtensions:
if isinstance(ext, codehilite.CodeHiliteExtension):
self.guess_lang = ext.config['guess_lang'][0]
Expand All @@ -169,7 +166,9 @@ def get_settings(self):
def codehilite(self, lang, src):
"""Syntax highlite the inline code block."""

process_text = self.style_plain_text or lang != 'text'
process_text = self.style_plain_text or lang or self.guess_lang
if not lang and self.style_plain_text and not self.guess_lang:
lang = 'text'
sublime_hl_enabled, sublime_hl = self.config.get("sublime_hl", None)
if sublime_hl_enabled:
code = sublime_hl.syntax_highlight(src, lang, inline=True)
Expand Down Expand Up @@ -213,7 +212,7 @@ def codehilite(self, lang, src):
def handleMatch(self, m):
"""Handle the pattern match."""

lang = m.group('lang') if m.group('lang') else 'text'
lang = m.group('lang') if m.group('lang') else ''
src = m.group('code').strip()
self.get_settings()
return self.codehilite(lang, src)
Expand Down
20 changes: 8 additions & 12 deletions st3/mdpopups/mdx/superfences.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
from markdown.extensions import Extension
from markdown.preprocessors import Preprocessor
from markdown.blockprocessors import CodeBlockProcessor
try:
from markdown.extensions.codehilite import CodeHilite, CodeHiliteExtension, parse_hl_lines
except Exception:
CodeHilite = None
from markdown.extensions.codehilite import CodeHilite, CodeHiliteExtension, parse_hl_lines
try:
from pygments import highlight
from pygments.lexers import get_lexer_by_name, guess_lexer
Expand Down Expand Up @@ -281,12 +278,12 @@ def extendMarkdown(self, md, md_globals):
if not hasattr(md, "superfences"):
md.superfences = []
md.superfences.insert(0, sf_entry)
if config.get("uml_flow", False): # Disable for Sublime Text
if config.get("uml_flow", True):
extend_super_fences(
md, "flow", "flow",
lambda s, l, c="uml-flowchart": uml_format(s, l, c)
)
if config.get("uml_sequence", False): # Disable for Sublime Text
if config.get("uml_sequence", True):
extend_super_fences(
md, "sequence", "sequence",
lambda s, l, c="uml-sequence-diagram": uml_format(s, l, c)
Expand Down Expand Up @@ -358,11 +355,10 @@ def check_codehilite(self):
"""Check for code hilite extension to get its config."""

if not self.checked_for_codehilite:
if CodeHilite:
for ext in self.markdown.registeredExtensions:
if isinstance(ext, CodeHiliteExtension):
self.codehilite_conf = ext.config
break
for ext in self.markdown.registeredExtensions:
if isinstance(ext, CodeHiliteExtension):
self.codehilite_conf = ext.config
break
self.checked_for_codehilite = True

def clear(self):
Expand All @@ -389,7 +385,7 @@ def eval(self, m, start, end):
elif len(m.group(1)) != self.ws_len and m.group(2) != '':
# Not indented enough
self.clear()
elif self.fence_end.match(m.group(0)) is not None:
elif self.fence_end.match(m.group(0)) is not None and not m.group(2).startswith(' '):
# End of fence
self.process_nested_block(m, start, end)
else:
Expand Down
38 changes: 32 additions & 6 deletions st3/mdpopups/rgba.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def fromhsv(self, h, s, v):
"""Convert to RGB from HSV."""

r, g, b = hsv_to_rgb(h, s, v)
self.r = round_int(r * 255) & 0xFF
self.g = round_int(g * 255) & 0xFF
self.b = round_int(b * 255) & 0xFF
self.r = round_int(r * 255.0) & 0xFF
self.g = round_int(g * 255.0) & 0xFF
self.b = round_int(b * 255.0) & 0xFF

def tohls(self):
"""Convert to HLS color format."""
Expand All @@ -150,9 +150,35 @@ def fromhls(self, h, l, s):
"""Convert to RGB from HSL."""

r, g, b = hls_to_rgb(h, l, s)
self.r = round_int(r * 255) & 0xFF
self.g = round_int(g * 255) & 0xFF
self.b = round_int(b * 255) & 0xFF
self.r = round_int(r * 255.0) & 0xFF
self.g = round_int(g * 255.0) & 0xFF
self.b = round_int(b * 255.0) & 0xFF

def tohwb(self):
"""Convert to HWB from RGB."""

h, s, v = self.tohsv()
w = (1.0 - s) * v
b = 1.0 - v
return h, w, b

def fromhwb(self, h, w, b):
"""Convert to RGB from HWB."""

# Normalize white and black
# w + b <= 1.0
if w + b > 1.0:
norm_factor = 1.0 / (w + b)
w *= norm_factor
b *= norm_factor

# Convert to HSV and then to RGB
s = 1.0 - (w / (1.0 - b))
v = 1.0 - b
r, g, b = hsv_to_rgb(h, s, v)
self.r = round_int(r * 255.0) & 0xFF
self.g = round_int(g * 255.0) & 0xFF
self.b = round_int(b * 255.0) & 0xFF

def colorize(self, deg):
"""Colorize the color with the given hue."""
Expand Down
2 changes: 1 addition & 1 deletion st3/mdpopups/st_code_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def set_view(self, src, lang):
def syntax_highlight(self, src, lang, hl_lines=[], inline=False):
"""Syntax Highlight."""

self.set_view(src, 'text' if lang is None else lang)
self.set_view(src, 'text' if not lang else lang)
self.inline = inline
self.hl_lines = hl_lines
self.setup()
Expand Down

0 comments on commit 83d9d80

Please sign in to comment.