Skip to content
This repository has been archived by the owner on Jul 30, 2023. It is now read-only.

Emit names for task list checkboxes #12

Open
ddevault opened this issue Sep 6, 2018 · 6 comments
Open

Emit names for task list checkboxes #12

ddevault opened this issue Sep 6, 2018 · 6 comments

Comments

@ddevault
Copy link

ddevault commented Sep 6, 2018

So that, when ticked, we can easily update the text.

@zopieux
Copy link
Owner

zopieux commented Sep 8, 2018

I'm not sure I understand what you mean with "emit".

Checkboxes already have IDs to be used by JavaScripts side processing.

@ddevault
Copy link
Author

ddevault commented Sep 8, 2018

They do?

>>> import markdown
>>> from mdx_gfm import GithubFlavoredMarkdownExtension
>>> 
>>> source = """
... Hello, *world*! This is a ~~good~~marvelous day!
... Here is an auto link: https://example.org/
... 
... Le me introduce you to [task lists] (https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments):
... 
... - [ ] eggs
... - [x] milk
... 
... You can also have fenced code blocks:
... 
... ```
... import this
... ```
... """
>>> md = markdown.Markdown(extensions=[GithubFlavoredMarkdownExtension()])
>>> html = md.convert(source)
>>> html
'<p>Hello, <em>world</em>! This is a <del>good</del>marvelous day!<br />\nHere is an auto link: <a href="https://example.org/">https://example.org/</a></p>\n<p>Le me introduce you to <a href="https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments">task lists</a>:</p>\n<ul>\n<li><input disabled="disabled" type="checkbox" /> eggs</li>\n<li><input checked="checked" disabled="disabled" type="checkbox" /> milk</li>\n</ul>\n<p>You can also have fenced code blocks:</p>\n<div class="highlight"><pre><span></span>import this\n</pre></div>'

I would like to do server-side processing, rather than with JavaScript. To that end I'll put the generated Markdown in a form, and if the checkboxes have a name attribute which specifies the character position of the checkbox in the markdown source that generated that checkbox, I can easily run the update on the server.

@zopieux
Copy link
Owner

zopieux commented Sep 9, 2018

For some reason the readthedocs docs are somewhat broken, the list of links to extensions does not show. Please refer to the inline documentation on how to set checkbox_attrs with a function that emits your name. You could use a counter or a hash of the content to generate the name. I'll try to setup an example implementation some day.

@ddevault
Copy link
Author

ddevault commented Sep 9, 2018

That's not flexible enough, I'd still have to implement my own markdown parser to find the character index of the checkboxes to do the toggle. I just want something like <input type="check" name="check-245"> where 245 is the index of the [ ] in the markdown source.

@zopieux
Copy link
Owner

zopieux commented Sep 15, 2018

I understand your issue, indeed py-gfm does not expose the required API to cleanly toggle the checkbox by modifying the markdown input. It's quite far from the original purpose of a markdown renderer, but I'll try to address this in a new release. You could also come up with a PR that I'll happily review.

@ddevault
Copy link
Author

It's quite far from the original purpose of a markdown renderer

I have to disagree. This isn't a traditionally designed parser but it's quite common for a parser to prepare an annotated AST that the consumer can examine, including information about the line number and character index of each semantic object in the source. This is necessary, for example, to show syntax errors with a line and column number. I think it's well within the purview of a markdown implementation.

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

No branches or pull requests

2 participants