Example #1
0
    def core_wrap_with_abbreviation(self, abbr):

        if not abbr:
            return None

        syntax = self.get_syntax()
        profile_name = self.get_profile_name()

        start_offset, end_offset = self.get_selection_range()
        content = self.get_content()

        if start_offset == end_offset:
            rng = html_matcher.match(content, start_offset, profile_name)
            if rng[0] is None:
                return None
            else:
                start_offset, end_offset = rng

        start_offset, end_offset = zen_actions.narrow_to_non_space(
            content, start_offset, end_offset)
        line_bounds = zen_actions.get_line_bounds(content, start_offset)
        padding = zen_actions.get_line_padding(
            content[line_bounds[0]:line_bounds[1]])

        new_content = content[start_offset:end_offset]
        return zen_core.wrap_with_abbreviation(
            abbr, zen_actions.unindent_text(new_content, padding), syntax,
            profile_name)
Example #2
0
def code():
    text = str(raw_input("Enter text"))

    print(text)

    p=zencoding.find_abbr_in_line(text,len(text))

    d=zencoding.expand_abbreviation(text,'html','xhtml')

    d=zencoding.wrap_with_abbreviation('body',d)

    print(d)
    print(p)
def wrap_with_abbreviation(editor, abbr, syntax, profile_name='xhtml'):
	"""
	Wraps content with abbreviation
	@param editor: Editor instance
	@type editor: ZenEditor
	@param syntax: Syntax type (html, css, etc.)
	@type syntax: str
	@param profile_name: Output profile name (html, xml, xhtml)
	@type profile_name: str
	"""
	start_offset, end_offset = editor.get_selection_range()
	content = editor.get_content()
	
	if not abbr: return None 
	
	if start_offset == end_offset:
		# no selection, find tag pair
		range = html_matcher.match(content, start_offset)
		
		if range[0] is None: # nothing to wrap
			return None
			
		start_offset = range[0]
		end_offset = range[1]
			
		# narrow down selection until first non-space character
		while start_offset < end_offset:
			if not content[start_offset].isspace(): break
			start_offset += 1
		
		while end_offset > start_offset:
			end_offset -= 1
			if not content[end_offset].isspace():
				end_offset += 1
				break
	
	new_content = content[start_offset:end_offset]
	result = zen.wrap_with_abbreviation(abbr, unindent(editor, new_content), syntax, profile_name)
	
	if result:
		editor.replace_content(result, start_offset, end_offset)
	def core_wrap_with_abbreviation(self, abbr):
	
		if not abbr:
			return None

		syntax = self.get_syntax()
		profile_name = self.get_profile_name()

		start_offset, end_offset = self.get_selection_range()
		content = self.get_content()

		if start_offset == end_offset:
			rng = html_matcher.match(content, start_offset, profile_name)
			if rng[0] is None:
				return None
			else:
				start_offset, end_offset = rng

		start_offset, end_offset = zen_actions.narrow_to_non_space(content, start_offset, end_offset)
		line_bounds = zen_actions.get_line_bounds(content, start_offset)
		padding = zen_actions.get_line_padding(content[line_bounds[0]:line_bounds[1]])

		new_content = content[start_offset:end_offset]
		return zen_core.wrap_with_abbreviation(abbr, zen_actions.unindent_text(new_content, padding), syntax, profile_name)
# 4th argument: profile name
if argl > 4: profile = sys.argv[4]

# Find starting white space
if (re.search('^(\s+)', abbr) != None):
  indent = re.search('^(\s+)', abbr).group(1)
# Capture any white space at end
if (re.search('(\s+)$', abbr) != None):
  endwhite = re.search('(\s+)$', abbr).group(1)
# Remove white space for processing, including any end white space
abbr = re.sub('(^\s+)|(\s+$)', '', abbr)

if abbr:
  if exp_type == 'exp':
    result = zen_core.expand_abbreviation(abbr, doc_type, profile)
  elif exp_type == 'wrap':
    try:   # Need to get selected text
      selFileDest = (os.path.expanduser("~")) # get home directory
      selFile = open(selFileDest+'/Library/Application Support/TextWrangler/Scripts/zencoding_1_1_1/zen_selected_temp', 'r')
      selected = selFile.read()
    except IOError:
      selected = ''  # empty selection
    result = zen_core.wrap_with_abbreviation(abbr, selected, doc_type, profile)
  if result:
    # Add indentation to result
    result = re.sub(re.compile('^(.)', re.M), indent+r'\1', result)
    # Remove for first line
    result = re.sub(re.compile('^'+indent), r'', result)
    sys.stdout.write(result+endWhite)
Example #6
0
# 4th argument: profile name
if argl > 4: profile = sys.argv[4]

# Find starting white space
if (re.search('^(\s+)', abbr) != None):
    indent = re.search('^(\s+)', abbr).group(1)
# Capture any white space at end
if (re.search('(\s+)$', abbr) != None):
    endwhite = re.search('(\s+)$', abbr).group(1)
# Remove white space for processing, including any end white space
abbr = re.sub('(^\s+)|(\s+$)', '', abbr)

if abbr:
    if exp_type == 'exp':
        result = zen_core.expand_abbreviation(abbr, doc_type, profile)
    elif exp_type == 'wrap':
        try:  # Need to get selected text
            selFileDest = (os.path.expanduser("~"))  # get home directory
            selFile = open(
                '~/Dropbox/Library/Application Support/BBEdit/Scripts/zencoding_BBEdit/zen_selected_temp',
                'r')
            selected = selFile.read()
        except IOError:
            selected = ''  # empty selection
        result = zen_core.wrap_with_abbreviation(abbr, selected, doc_type,
                                                 profile)
    if result:
        # Add indentation to result
        result = re.sub(re.compile('^(.)', re.M), indent + r'\1', result)
        sys.stdout.write(result + endWhite)