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

Python Markdown: Print lists #1119

Closed
michaelaye opened this issue Oct 10, 2017 · 5 comments
Closed

Python Markdown: Print lists #1119

michaelaye opened this issue Oct 10, 2017 · 5 comments

Comments

@michaelaye
Copy link

Thanks for this very useful extension!

I'm wondering if it's possible to make it work with lists as well, maybe automatically adding a new line for each element?

In code, I want to be able to:

l = [1,2,3]
# Markdown
Current list values: {{l}}

but also:

# Markdown
Beginning of list: {{l[:2]}}

Would that be possible? At least currently, it doesn't seem to work (mac/conda-forge up-to-date).

@jcb91
Copy link
Member

jcb91 commented Oct 10, 2017

Something like

# Markdown
Current list of values: 
 * {{ '\n * '.join(l) }}

or

#Markdown
Beginning of list: {{ [' * {}\n'.format(item) for item in l[:2]] }}

Should work, hopefully?

@michaelaye
Copy link
Author

michaelaye commented Oct 11, 2017

So, the general unpacking from list to string works, but the \n is being ignored?
The 2nd example also stops for me after item[0].

@jcb91
Copy link
Member

jcb91 commented Oct 11, 2017

Hmm, ok, something more complex must be going on. I'll try to have a more detailed look today...

@jcb91
Copy link
Member

jcb91 commented Oct 12, 2017

So, it's a fairly simple bug in that the js was expecting marked to wrap everything in <p> tags, but it doesn't wrap lists. I also fixed another bug to do with stripping tags / quotes from locations not at the start/end of the text. Unfortunately, I still have to print the output in order to avoid getting a python-style string, that is

 #### Markdown

Beginning of list: {{ [' - {}\n'.format(item) for item in list(range(10))[:5]] }}

Beginning of list: {{ print(''.join([' - {}\n'.format(i) for i in list(range(10))[:5]])) }}

ends up formatted as

Markdown

Beginning of list: - 0\n

Beginning of list:

  • 0
  • 1
  • 2
  • 3
  • 4

Anyway, I hope that helps a little 🤷‍♂️

@jcb91
Copy link
Member

jcb91 commented Oct 12, 2017

(see #1122 for fix)

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

2 participants