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

Support GitHub-Flavored Markdown and other extensions #2

Closed
simonw opened this issue Nov 30, 2019 · 6 comments
Closed

Support GitHub-Flavored Markdown and other extensions #2

simonw opened this issue Nov 30, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Nov 30, 2019

https://py-gfm.readthedocs.io/en/latest/

diff --git a/datasette_render_markdown/__init__.py b/datasette_render_markdown/__init__.py
index 018f433..826b9b5 100644
--- a/datasette_render_markdown/__init__.py
+++ b/datasette_render_markdown/__init__.py
@@ -3,6 +3,7 @@ import bleach
 import markdown
 from datasette import hookimpl
 import jinja2
+from mdx_gfm import GithubFlavoredMarkdownExtension
 
 
 @hookimpl()
@@ -19,7 +20,11 @@ def render_cell(value, column):
 def render_markdown(value):
     html = bleach.linkify(
         bleach.clean(
-            markdown.markdown(value, output_format="html5"),
+            markdown.markdown(
+                value,
+                output_format="html5",
+                extensions=[GithubFlavoredMarkdownExtension()],
+            ),
             tags=[
                 "a",
                 "abbr",
@simonw simonw added the enhancement New feature or request label Nov 30, 2019
@simonw
Copy link
Owner Author

simonw commented Nov 30, 2019

I'm torn on whether this should be the default behaviour. My use-cases for this plugin all revolve around data pulled from the GitHub API using github-to-sqlite.

@simonw
Copy link
Owner Author

simonw commented Nov 30, 2019

I could have columns ending in _gfm use this, while columns ending in _markdown or _md stick with regular markdown. Then I can add configuration in #1.

@simonw simonw changed the title Optionally support GitHub-Flavored Markdown Support GitHub-Flavored Markdown and other extensions Mar 22, 2020
@simonw
Copy link
Owner Author

simonw commented Mar 22, 2020

@simonw
Copy link
Owner Author

simonw commented Mar 22, 2020

Example from the docs:

markdown.markdown(some_text, extensions=[
    MyExtClass(),
    'myext',
    'path.to.my.ext:MyExtClass'
])

So supporting "extensions": ["myext"] in metadata configuration should work here.

For GFM I think that will be "mdx_gfm:GithubFlavoredMarkdownExtension".

@simonw
Copy link
Owner Author

simonw commented Mar 24, 2020

Fixed in #4.

@simonw simonw closed this as completed Mar 24, 2020
@simonw
Copy link
Owner Author

simonw commented Mar 24, 2020

Released in 1.1.

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

No branches or pull requests

1 participant