commit dd28efbae65ceb619829e34a8b1cba23fb9c00ec Author: Anton Vakhrushev Date: Sun Dec 6 19:12:58 2015 +0300 init diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap new file mode 100644 index 0000000..142c90f --- /dev/null +++ b/Default (Linux).sublime-keymap @@ -0,0 +1,3 @@ +[ + {"keys": ["ctrl+shift+t"], "command": "typograph_selection"} +] diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap new file mode 100644 index 0000000..142c90f --- /dev/null +++ b/Default (OSX).sublime-keymap @@ -0,0 +1,3 @@ +[ + {"keys": ["ctrl+shift+t"], "command": "typograph_selection"} +] diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap new file mode 100644 index 0000000..96bf0f5 --- /dev/null +++ b/Default (Windows).sublime-keymap @@ -0,0 +1,6 @@ +[ + { + "keys": ["ctrl+shift+t"], + "command": "typograph_selection" + } +] diff --git a/Default.sublime-commands b/Default.sublime-commands new file mode 100644 index 0000000..68d4e42 --- /dev/null +++ b/Default.sublime-commands @@ -0,0 +1,6 @@ +[ + { + "caption": "Typograph: typo selection", + "command": "typograph_selection" + } +] diff --git a/README.md b/README.md new file mode 100644 index 0000000..76b0c6b --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Typograph + +Плагин для Sublime Text 3, который позволяет типографировать html-текст. diff --git a/Typograph.py b/Typograph.py new file mode 100644 index 0000000..5874ef7 --- /dev/null +++ b/Typograph.py @@ -0,0 +1,77 @@ +import sublime +import sublime_plugin + +from .lib.artlebedev import RemoteTypograf + + +__author__ = 'Anton Vakhrushev' +__email__ = 'anwinged@ya.ru' + + +PLUGIN_NAME = 'Typograph' + +DEFAULT_SETTINGS = { + 'type': 'html', + 'breaks': False, + 'paragraphs': False, + 'max_no_break': 3, +} + + +class TypographSelectionCommand(sublime_plugin.TextCommand): + """ + Process selections of html text + """ + + def run(self, edit): + + settings = self.get_settings() + + typograf = RemoteTypograf() + typograf.htmlEntities() + typograf.br(settings['breaks']) + typograf.p(settings['paragraphs']) + typograf.nobr(settings['max_no_break']) + + for region in self.view.sel(): + processed = typograf.processText(self.view.substr(region)) + self.view.replace(edit, region, processed) + + + def get_settings(self): + """ + Load plugin settings + """ + settings = sublime.load_settings('{}.sublime-settings'.format(PLUGIN_NAME)) + project_settings = self.view.settings().get(PLUGIN_NAME, {}) + local_settings = DEFAULT_SETTINGS.copy() + + for key in DEFAULT_SETTINGS: + local_settings[key] = settings.get(key) + + for key in project_settings: + if key in DEFAULT_SETTINGS: + local_settings[key] = project_settings[key] + else: + print('{}: invalid key "{}" in project settings'.format(PLUGIN_NAME, key)) + + return local_settings + +# ----------------------------------------------------------------------------- + +# "Вы все еще кое-как верстаете в "Ворде"? - Тогда мы идем к вам!" + +""" + +
+
+
Как это работает?
+

Вы подключаете модемы к своим приборам учета, + и наши сервера производят сбор данных. Вам не надо покупать, устанавливать и настраивать + на своем компьютере сложное и дорогое программное обеспечение и оборудование. Получать данные + и просматривать отчеты можно из любой точки мира с помощью компьютера, планшета или смартфона. + Работайте быстро, гибко и дешево!

+
+
+ +""" diff --git a/Typograph.sublime-settings b/Typograph.sublime-settings new file mode 100644 index 0000000..ba3dca7 --- /dev/null +++ b/Typograph.sublime-settings @@ -0,0 +1,9 @@ +{ + "type": "html", + + "breaks": false, + + "paragraphs": false, + + "max_no_break": 3 +} diff --git a/lib/__init__.py b/lib/__init__.py new file mode 100644 index 0000000..bff965c --- /dev/null +++ b/lib/__init__.py @@ -0,0 +1 @@ +__author__ = 'Anton Vakhrushev' diff --git a/lib/artlebedev.py b/lib/artlebedev.py new file mode 100644 index 0000000..d2102dc --- /dev/null +++ b/lib/artlebedev.py @@ -0,0 +1,111 @@ +""" +remotetypograf.py +python-implementation of ArtLebedevStudio.RemoteTypograf class (web-service client) + +Copyright (c) Art. Lebedev Studio | http://www.artlebedev.ru/ + +Typograf homepage: http://typograf.artlebedev.ru/ +Web-service address: http://typograf.artlebedev.ru/webservices/typograf.asmx +WSDL-description: http://typograf.artlebedev.ru/webservices/typograf.asmx?WSDL + +Default charset: UTF-8 + +Python version +Author: Sergey Lavrinenko (s.lavrinenko@gmail.com) +Version: 1.0 (2007-05-18) based on script by Andrew Shitov (ash@design.ru) + +Example: + from RemoteTypograf import RemoteTypograf + rt = RemoteTypograf() + # rt = RemoteTypograf('windows-1251') + print rt.processText ('"Вы все еще кое-как верстаете в "Ворде"? - Тогда мы идем к вам!"'); +""" + + +import socket + + +class RemoteTypograf: + + _entityType = 4 + _useBr = 1 + _useP = 1 + _maxNobr = 3 + _encoding = 'UTF-8' + + def __init__(self, encoding='UTF-8'): + self._encoding = encoding + + def htmlEntities(self): + self._entityType = 1 + + def xmlEntities(self): + self._entityType = 2 + + def mixedEntities(self): + self._entityType = 4 + + def noEntities(self): + self._entityType = 3 + + def br(self, value): + self._useBr = 1 if value else 0 + + + def p(self, value): + self._useP = 1 if value else 0 + + def nobr(self, value): + self._maxNobr = int(value) if value else 0 + + def processText(self, text): + + text = text.replace('&', '&') + text = text.replace('<', '<') + text = text.replace ('>', '>') + + SOAPBody = '\n' + SOAPBody += '\n' + SOAPBody += '\r\n' + SOAPBody += ' \n' + SOAPBody += ' %s\n' % text + SOAPBody += ' %s\n' % self._entityType + SOAPBody += ' %s\n' % self._useBr + SOAPBody += ' %s\n' % self._useP + SOAPBody += ' %s\n' % self._maxNobr + SOAPBody += ' \n' + SOAPBody += ' \n' + SOAPBody += '\n' + + host = 'typograf.artlebedev.ru'; + SOAPRequest = 'POST /webservices/typograf.asmx HTTP/1.1\n' + SOAPRequest += 'Host: typograf.artlebedev.ru\n' + SOAPRequest += 'Content-Type: text/xml\n' + SOAPRequest += 'Content-Length: %d\n' % len(bytearray(SOAPBody, 'utf-8')) + SOAPRequest += 'SOAPAction: "http://typograf.artlebedev.ru/webservices/ProcessText"\n\n' + + SOAPRequest += SOAPBody + + remoteTypograf = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + remoteTypograf.connect((host, 80)) + remoteTypograf.sendall(bytearray(SOAPRequest, 'utf-8')) + + typografResponse = bytearray() + while 1: + buf = remoteTypograf.recv(8192) + if len(buf) == 0: break + typografResponse += buf + + remoteTypograf.close() + + typografResponse = typografResponse.decode(encoding='utf-8') + + startsAt = typografResponse.find('') + 19 + endsAt = typografResponse.find('') + typografResponse = typografResponse[startsAt:endsAt] + + typografResponse = typografResponse.replace('&', '&' ) + typografResponse = typografResponse.replace('<', '<') + typografResponse = typografResponse.replace ('>', '>') + + return typografResponse