예제 #1
0
 def run(self, resource_path='docs/en/README.md'):
     try:
         w = self.window
         import mdpopups
         mdpopups.new_html_sheet(
             window=w,
             name='{}/{}'.format(PKG_NAME, resource_path),
             contents=mdpopups.format_frontmatter(FRONTMATTER) +
             sublime.load_resource('Packages/{}/{}'.format(
                 PKG_NAME, resource_path)),
             md=True,
             css='{}'.format(CSS))
     except Exception as e:
         print('{}: Exception: {}'.format(PKG_NAME, e))
    def run(self, edit):
        global preview_view, PREVIEW_VIEWS
        """ Description: If the file is saved exists on disk, we close it,
        - and reopen it in a new window. Otherwise, we copy the content,
        - erase it all (to close the file without a dialog)
        - and re-insert it into a new view into a new window """

        original_view = self.view
        original_window_id = original_view.window().id()
        file_name = original_view.file_name()

        syntax_file = original_view.settings().get("syntax")

        if file_name:
            original_view.close()
        else:
            # the file isn't saved, we need to restore the content manually
            total_region = sublime.Region(0, original_view.size())
            content = original_view.substr(total_region)
            original_view.erase(edit, total_region)
            original_view.close()
            # FIXME: save the document to a temporary file, so that if we crash,
            # - the user doesn't lose what he wrote

        sublime.run_command("new_window")
        preview_window = sublime.active_window()

        preview_window.run_command(
            "set_layout",
            {
                "cols": [0.0, 0.5, 1.0],
                "rows": [0.0, 1.0],
                "cells": [[0, 0, 1, 1], [1, 0, 2, 1]],
            },
        )

        preview_window.focus_group(1)
        preview_view = mdpopups.new_html_sheet(window=preview_window,
                                               name="Preview",
                                               contents="")

        preview_window.focus_group(0)
        if file_name:
            markdown_view = preview_window.open_file(file_name)
        else:
            markdown_view = preview_window.new_file()
            markdown_view.run_command("mdlp_insert", {
                "point": 0,
                "content": content
            })
            markdown_view.set_scratch(True)

        markdown_view.set_syntax_file(syntax_file)
        markdown_view.settings().set(
            MD_VIEW_INFO,
            {
                "original_window_id": original_window_id,
            },
        )
        PREVIEW_VIEWS[markdown_view.id()] = preview_view.id()
예제 #3
0
파일: tooling.py 프로젝트: evandrocoan/LSP
 def on_selected(self, selected_index: int, configs: List[ClientConfig],
                 active_view: Optional[sublime.View]) -> None:
     if selected_index == -1:
         return
     config = configs[selected_index]
     output_sheet = mdpopups.new_html_sheet(
         self.window, 'Server: {}'.format(config.name), '# Running server test...',
         css=css().sheets, wrapper_class=css().sheets_classname)
     sublime.set_timeout_async(lambda: self.test_run_server_async(config, self.window, active_view, output_sheet))
예제 #4
0
 def _handle_open_rule_description(self, session: Session,
                                   window: sublime.Window, args: List[str],
                                   done: Callable[[], None]) -> bool:
     view = window.active_view()
     file_name = view.file_name()
     language_id = "text"
     if file_name:
         uri = filename_to_uri(file_name)
         sb = session.get_session_buffer_for_uri_async(uri)
         if sb:
             language_id = sb.language_id
     parser = HTMLParser(language_id)
     parser.feed("<p><i>{}</i></p>{}".format(args[1], args[2]))
     mdpopups.new_html_sheet(window=window,
                             name=args[0],
                             contents=parser.result,
                             css=css().sheets,
                             wrapper_class=css().sheets_classname,
                             flags=sublime.ADD_TO_SELECTION_SEMI_TRANSIENT)
     done()
     return True
 def run(self, resource_path='README.md', resource_title='README'):
     try:
         w = self.window
         v = w.active_view()
         import mdpopups
         preview_sheet = mdpopups.new_html_sheet(
             window=w,
             # TODO: update for Py3.8 with f-strings
             name='{}: {}'.format(PKG_NAME, resource_title),
             contents=sublime.load_resource('Packages/{}/{}'.format(
                 PKG_NAME, resource_path)),
             md=True)
     except Exception as e:
         print('{}: Exception: {}'.format(PKG_NAME, e))
예제 #6
0
 def run(self, resource_path='docs/README.en.md'):
     try:
         w = self.window
         v = w.active_view()
         import mdpopups
         preview_sheet = mdpopups.new_html_sheet(
             window=w,
             name='{}/{}'.format(PKG_NAME, resource_path),
             contents=sublime.load_resource('Packages/{}/{}'.format(PKG_NAME, resource_path)),
             md=True
         )
     except Exception as e:
         # TODO: update for py3.8
         print('AutoDark: Error: ', e)
def run_doctor(session: Session, args: Any) -> None:
    if isinstance(args, list) and args:
        content = json.loads(args[0])
        messages = content.get('messages')
        targets = content.get('targets')
        markdown = ""
        markdown += "## {}  \n\n".format(content.get('headerText'))

        if messages:
            for message in messages:
                markdown += "### {} \n".format(message.get('title'))
                for recommendation in message.get('recommendations'):
                    markdown += '* {}\n'.format(recommendation)
                markdown += '\n\n'
        else:
            headers = [
                'Build Target', 'Scala Version', 'Diagnostics',
                'Goto Definition', 'Completions', 'Find References',
                'Recommendation'
            ]
            markdown += "## Build Targets\n"
            lines = []
            for target in targets:
                lines.append([
                    target.get('buildTarget'),
                    target.get('scalaVersion'),
                    target.get('diagnostics'),
                    target.get('gotoDefinition'),
                    target.get('completions'),
                    target.get('findReferences'),
                    target.get('recommendation')
                ])
            table = tabulate(lines, headers, "pretty")
            markdown += "```\n{}\n```\n\n".format(table)
        mdpopups.new_html_sheet(session.window, "Metals Doctor", markdown,
                                True)
예제 #8
0
 def run(self):
     try:
         w = self.window
         v = w.active_view()
         if not v.settings().get('syntax').startswith('Packages/Markdown/'):
             return
         import mdpopups
         preview_sheet = mdpopups.new_html_sheet(
             window=w,
             name='[print] mini-HTML Preview (read-only)',
             contents=v.substr(sublime.Region(0, v.size())),
             md=True
         )
         # w.run_command('new_pane')
     except Exception as e:
         # TODO: update for py3.8
         print('Print: Exception: {}'.format(e))