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

Missing support for WARNING and NOTE formatting #364

Open
alichtman opened this issue Jun 19, 2022 · 4 comments
Open

Missing support for WARNING and NOTE formatting #364

alichtman opened this issue Jun 19, 2022 · 4 comments

Comments

@alichtman
Copy link

Demo'd here: community/community#16925 (comment)

@HorridModz
Copy link

HorridModz commented Jul 24, 2023

Yes, we NEED this! I spent hours integrating this into my workflow with a very robust batch script, only to find that it doesn't support WARNING, NOTE, and EXCLAMATION. Literally the only Github exclusive thing it supports is the color scheme, AFAICT.

I was under the impression that the whole point of this project was to enable us to view our markown files with Github's markdown flavor and rendering engine.

If the project is just meant to support the color scheme, it would be nice if it could at least say so at the top of the README.

@neilotoole
Copy link

@PathToLife
Copy link

Do we know if this is because of Github's MD rendering API not yet supporting [!NOTE] [!TIP] etc etc?

https://docs.github.com/en/rest/markdown?apiVersion=2022-11-28

For now I've found a workaround which uses the rendered html shown on the Github webpage.
https://gist.github.com/PathToLife/a9c55105484a223d108a4d42e54be4bd

@alichtman
Copy link
Author

alichtman commented Feb 27, 2024

Do we know if this is because of Github's MD rendering API not yet supporting [!NOTE] [!TIP] etc etc?

Yeah, I think this is the problem.

grip/grip/constants.py

Lines 22 to 23 in a3f0ab5

# The public GitHub API
DEFAULT_API_URL = 'https://api.github.com'

grip/grip/renderers.py

Lines 41 to 84 in a3f0ab5

class GitHubRenderer(ReadmeRenderer):
"""
Renders the specified Readme using the GitHub Markdown API.
"""
def __init__(self, user_content=None, context=None, api_url=None,
raw=None):
if api_url is None:
api_url = DEFAULT_API_URL
super(GitHubRenderer, self).__init__(user_content, context)
self.api_url = api_url
self.raw = raw
def render(self, text, auth=None):
"""
Renders the specified markdown content and embedded styles.
Raises TypeError if text is not a Unicode string.
Raises requests.HTTPError if the request fails.
"""
# Ensure text is Unicode
expected = str if sys.version_info[0] >= 3 else unicode # noqa
if not isinstance(text, expected):
raise TypeError(
'Expected a Unicode string, got {!r}.'.format(text))
if self.user_content:
url = '{0}/markdown'.format(self.api_url)
data = {'text': text, 'mode': 'gfm'}
if self.context:
data['context'] = self.context
data = json.dumps(data, ensure_ascii=False).encode('utf-8')
headers = {'content-type': 'application/json; charset=UTF-8'}
else:
url = '{0}/markdown/raw'.format(self.api_url)
data = text.encode('utf-8')
headers = {'content-type': 'text/x-markdown; charset=UTF-8'}
r = requests.post(url, headers=headers, data=data, auth=auth)
r.raise_for_status()
# FUTURE: Remove this once GitHub API properly handles Unicode markdown
r.encoding = 'utf-8'
return r.text if self.raw else patch(r.text)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants