def test_detect_newline(self): self.assertEqual(os.linesep, MarkdownDocument('### Spam').detect_newline()) self.assertEqual('\n', MarkdownDocument('### Spam\n').detect_newline()) self.assertEqual('\r\n', MarkdownDocument('### Spam\r\nEggs').detect_newline()) self.assertEqual('\r', MarkdownDocument('### Spam\rEggs').detect_newline())
def main(): """Run Markdown from the command line.""" # Parse options and adjust logging level if necessary options, logging_level = parse_options() if not options: sys.exit(2) logger.setLevel(logging_level) logger.addHandler(logging.StreamHandler()) term_edit = options.pop('term_edit') markdown_processor = markdown.Markdown(**options) markdown_document = MarkdownDocument(infile=options['input'], outfile=options['output'], md=markdown_processor) # Run if term_edit: from markdown_editor import terminal_edit terminal_edit.start(markdown_document, default_action=options['term_action']) else: from markdown_editor import web_edit web_edit.start(markdown_document, port=options['port'])
'autojson': False, 'myapp': { 'document': doc, 'in_actions': default_actions, 'out_actions': _as_objects(custom_actions, WebAction), 'html_head': html_head, 'ajax_handlers': ajax_handlers or {} } }, make_namespaces=True) #Find correct port automatically, to allow multiple sessions s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) while 1: try: s.bind(('0.0.0.0', port)) s.close() break except socket.error as e: if e.errno == 98: print("Port " + str(port) + " is already in use") port = port + 1 webbrowser.open('http://localhost:{}'.format(port)) run(app, host='localhost', port=port, debug=False, reloader=False) if __name__ == '__main__': start(MarkdownDocument())
def test_document_html(self): self.assertEqual('<h3>Spam</h3>', MarkdownDocument('### Spam').get_html())
def test_document_html_page_unicode(self): self.assertIn(u'<h3>Spam é</h3>', MarkdownDocument(u'### Spam é').get_html_page())
def test_document_html_page(self): self.assertIn('<h3>Spam</h3>', MarkdownDocument('### Spam').get_html_page())
from markdown_editor import web_edit from markdown_editor.editor import MarkdownDocument MY_HTML_HEAD = 'Editor title' def action_send(document): send_markdown_text(document.text) # or send_raw_html_code(document.getHtml()) # or send_html_with_styles(document.getHtmlPage()) return html_to_display_as_result, keep_running_local_server if __name__ == '__main__': doc = MarkdownDocument() web_edit.start(doc, custom_actions=[ ('Save', action_send), ], title=MY_HTML_HEAD)