Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The HTML I output doesn't have CSS. What's the reason? #39

Open
fanrongqitiancai opened this issue Feb 4, 2022 · 1 comment
Open

The HTML I output doesn't have CSS. What's the reason? #39

fanrongqitiancai opened this issue Feb 4, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@fanrongqitiancai
Copy link

Describe the bug

context
my code
from markdown_it import MarkdownIt
from mdit_py_plugins.front_matter import front_matter_plugin
from mdit_py_plugins.footnote import footnote_plugin
from mdit_py_plugins.texmath import texmath_plugin
md = (
MarkdownIt()
.use(front_matter_plugin)
.use(footnote_plugin)
.use(texmath_plugin)
.enable('image')
.enable('table')
)

all_the_text = open('markdown.md').read()
tokens = md.parse(all_the_text)
html_text = md.render(all_the_text)

expectation
The code is highlighted and the mathematical formula is displayed normally

I checked the output HTML, no head tag, no CSS, no JS file. Why? What do I need to do?

Reproduce the bug

1.code is like this:
from markdown_it import MarkdownIt
from mdit_py_plugins.front_matter import front_matter_plugin
from mdit_py_plugins.footnote import footnote_plugin
from mdit_py_plugins.texmath import texmath_plugin
md = (
MarkdownIt()
.use(front_matter_plugin)
.use(footnote_plugin)
.use(texmath_plugin)
.enable('image')
.enable('table')
)

all_the_text = open('markdown.txt').read()
tokens = md.parse(all_the_text)
html_text = md.render(all_the_text)

List your environment

No response

@fanrongqitiancai fanrongqitiancai added the bug Something isn't working label Feb 4, 2022
@zmoon
Copy link

zmoon commented Jun 21, 2022

I checked the output HTML, no head tag, no CSS, no JS file. Why? What do I need to do?

You have to add those things. Here is a little example:

import tempfile
import webbrowser

from markdown_it import MarkdownIt


md = MarkdownIt("gfm-like")

md_text = """\
# A heading

* some
* bullets

> A quote

`inline code`, **strong**, *emphasis*, ~~struck~~

```python
# Code block
print('Hi')
```

| A   | Table |
| --- | ----- |
| foo | bar   |
"""

html = f"""\
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
      href="https://rawcdn.githack.com/typora/typora-default-themes/fad2650fd956bab56254043a2fe1c1e80796022f/themes/github.css">
<link rel="stylesheet"
      href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.5.1/build/styles/default.min.css">
</head>
<body>

{md.render(md_text)}

<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.5.1/build/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</body>
</html>
"""

with tempfile.NamedTemporaryFile(suffix=".html", delete=False) as f:
    f.write(html.encode("utf-8"))
    webbrowser.open(f"file://{f.name}")

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants