How can I change the default behavior in the markdown filter so that it transforms a newline to a br tag?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t think messing around with the newline syntax is a good idea …
I agree with Henrik’s comment. From the markdown docs:
Have you looked at the other Django markup options, textile and restructuredtext? Their syntax might suit you better.
but if you still want to …
A rough and ready method is to chain the markdown and linebreaksbr filters.
This runs the markdown filter, then the linebreaksbr filter, which replaces
\nwith<br />. You’ll probably end up with too many linebreaks, but that might be better for you than too few.If you a better solution than that, you could
Write a custom filter, as John suggests in his answer.
Dive into the the python-markdown library, which Django uses, and write an extension that implements your desired newline syntax. You would then use the extension with the filter
{{ value|markdown:"linebreakextension" }}