MCPcopy Index your code
hub / github.com/ronreiter/interactive-tutorials / convertFile

Method convertFile

markdown/__init__.py:420–457  ·  view source on GitHub ↗

Converts a markdown file and returns the HTML as a unicode string. Decodes the file using the provided encoding (defaults to utf-8), passes the file content to markdown, and outputs the html to either the provided stream or the file with provided name, using the same

(self, input=None, output=None, encoding=None)

Source from the content-addressed store, hash-verified

418 return output.strip()
419
420 def convertFile(self, input=None, output=None, encoding=None):
421 """Converts a markdown file and returns the HTML as a unicode string.
422
423 Decodes the file using the provided encoding (defaults to utf-8),
424 passes the file content to markdown, and outputs the html to either
425 the provided stream or the file with provided name, using the same
426 encoding as the source file.
427
428 **Note:** This is the only place that decoding and encoding of unicode
429 takes place in Python-Markdown. (All other code is unicode-in /
430 unicode-out.)
431
432 Keyword arguments:
433
434 * input: Name of source text file.
435 * output: Name of output file. Writes to stdout if `None`.
436 * encoding: Encoding of input and output files. Defaults to utf-8.
437
438 """
439
440 encoding = encoding or "utf-8"
441
442 # Read the source
443 input_file = codecs.open(input, mode="r", encoding=encoding)
444 text = input_file.read()
445 input_file.close()
446 text = text.lstrip('\ufeff') # remove the byte-order mark
447
448 # Convert
449 html = self.convert(text)
450
451 # Write to file or stdout
452 if isinstance(output, str):
453 output_file = codecs.open(output, "w", encoding=encoding)
454 output_file.write(html)
455 output_file.close()
456 else:
457 output.write(html.encode(encoding))
458
459
460"""

Callers 1

markdownFromFileFunction · 0.95

Calls 3

convertMethod · 0.95
openMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected