theacodes / cmarkgfm

Python bindings for GitHub's cmark
MIT License
69 stars 26 forks source link

Where is the rendered `.html` output file located? #47

Closed yasirroni closed 2 years ago

yasirroni commented 2 years ago

Using

import cmarkgfm

current_path = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(current_path, 'FILE.md'), 'r') as f:
    text = f.readlines()
html = cmarkgfm.github_flavored_markdown_to_html(''.join(text))

produce nothing.

Adding

with open(os.path.join(current_path, 'FILE.html'), 'a') as f:
    f.write(html)

Create plain html format

mbarkhau commented 2 years ago

The function you are using has as its input a str and returns as its output a str.

In [3]: cmarkgfm.github_flavored_markdown_to_html("# Hello\nworld")
Out[3]: '<h1>Hello</h1>\n<p>world</p>\n'

Your question appears to be a more general question about python file handling or paths and I think you will have to debug this on your own. At least I don't see how I can help you with that from here. As a tip, I think you may find this tutorial on the pathlib module to be helpful.

Best of luck.

yasirroni commented 2 years ago

Nope, the problem is not in Python paths, but on the non existence of .css to create the GitHub flavored markdown style of html file.

It seems that this package did not support that part? Thus, it only convert markdown into plain html file?

mbarkhau commented 2 years ago

Correct, you must supply the css yourself. You must also supply any surrounding markup yourself.

TEMPLATE = """
<html lang="en">
<head>
<title>My Page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>{html_content}</body>
</html>
"""

html_content = cmarkgfm.github_flavored_markdown_to_html(text)
html = TEMPLATE.format(html_content=html_content)
yasirroni commented 2 years ago

Feature request: warp all that for user. :)

You can look other implementation on github.css in markdown-viewer that come with MIT License.

mbarkhau commented 2 years ago

Out of scope. Best of luck.