def testRawXaml(self): data = ".. raw:: xaml\n\n foo" output = publish_xaml(data, flowdocument=False) node = get_root_sl() node.children.append(TextNode("foo")) self.assertEqual(output, node.to_string())
def testSilverlightWhitespaceHandling(self): xamlwriter.register_directive.flowdocument = False try: source = make_source('"foo foo"\n"foo foo"') expected = make_doc_sl('<Run Foreground="#BA2121">' '"foo  foo"</Run>' '<Run></Run><LineBreak />' '<Run Foreground="#BA2121">' '"foo  foo"</Run>' '<Run></Run><LineBreak />') self.assertEqual(publish_xaml(source, flowdocument=False), expected) finally: xamlwriter.register_directive.flowdocument = True
def read_and_write(input_path, output_path, i=-1): xamlwriter.register_directive.code_blocks = [] source = open(input_path).read().decode('utf-8') xaml = publish_xaml(source, flowdocument=False, xclass=False) handle = open(output_path, 'w') handle.write(xaml.encode('utf-8')) handle.close() code_blocks = xamlwriter.register_directive.code_blocks if code_blocks: output_folder = os.path.dirname(output_path) code_folder = os.path.join(output_folder, 'code%s' % (i + 1)) os.mkdir(code_folder) for j, code_list in enumerate(code_blocks): this_code = os.path.join(code_folder, 'example%s.txt' % j) handle = open(this_code, 'wb') handle.write('\n'.join(code_list).encode('utf-8')) handle.close()
def testXamlEscape(self): source = make_source('"&<\'>"') expected = make_doc('<Run Foreground="#BA2121">"&<'>"</Run><Run></Run>\n') self.assertEqual(publish_xaml(source), expected)
def testComment(self): # smoke test source = make_source('# comment') expected = make_doc('<Run Foreground="#408080" FontStyle="Italic"># comment</Run><Run></Run>\n') self.assertEqual(publish_xaml(source), expected)
#!/usr/bin/env python import sys # This installs the pygments directive import xamlwriter.register_directive from xamlwriter.writer import publish_xaml USAGE = "rst2xaml input_file output_file" if len(sys.argv) != 3: print USAGE sys.exit(1) input_data = open(sys.argv[1]).read().decode('utf-8') #print input_data output = publish_xaml(input_data) #print output handle = open(sys.argv[2], 'w') handle.write(output.encode('utf-8')) handle.close()
#!/usr/bin/env python import sys # This installs the pygments directive import xamlwriter.register_directive xamlwriter.register_directive.flowdocument = False from xamlwriter.writer import publish_xaml USAGE = "rst2xamlsl input_file output_file" if len(sys.argv) != 3: print USAGE sys.exit(1) input_data = open(sys.argv[1]).read().decode('utf-8') #print input_data output = publish_xaml(input_data, flowdocument=False) #print output handle = open(sys.argv[2], 'w') handle.write(output.encode('utf-8')) handle.close()