-
Notifications
You must be signed in to change notification settings - Fork 11
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
Break Line Inside Paragraph #167
Comments
Thanks for the heads up! I will try to take a look at this in a couple days after the holiday. Thanks for all the details. |
Okay, I have some clarifying question(s). Do you want the paragraph to maintain the exact text as-is? If so, you might try using a |
I'm aware of the raw element but it's not an option to my case. Suppose you are building a paragraph maybe from another text format. If so you want to keep modifying the paragraph as the same way you add a link or insert image and so on. The paragraph indeed it's not finished. In my opinion the break line should be an option for inline element. I don't understand also why the needs to use paragraph split that remove all the return carriage. Why should they being removed in paragraph construction if someone place them in text? |
The main problem is that markdown doesn't seem to be held to any sort of standard. In your example, you want there to be a break in the paragraph, but many tools are not going to respect it. For example, if you drop your exact text into a markdown document on GitHub, the markdown will be rendered without the break. To be fair, I am not opposed to adding a parameter to the Paragraph constructor to allow for respecting the input text as-is. However, in the spirit of Markdown, it's probably better to make use of the Raw block to get the text exactly as you would like it OR split the text into multiple paragraph blocks. For the record, I try to adhere to the same markdown implementation described here (i.e., John Gruber's), which does seem to support a line break feature that I didn't know existed (which is described here). I replicated it using that Python tool, and it produced the following HTML with the line break you are expecting: >>> text = """
... `This document describes the structures of RPC API.
... The API can be called by the endpoint / RPC.
...
... Each request Response must be compliant with the specification JSON-RPC.`
... """
>>> print(markdown.markdown(text))
<p>`This document describes the structures of RPC API.<br />
The API can be called by the endpoint / RPC.</p>
<p>Each request Response must be compliant with the specification JSON-RPC.`</p> I also replicated this in the GitHub markdown. Just need to add those extra two spaces to the end of the line. Now, this is tricky to include in the Paragraph directly, so I might entertain the idea of a line break element (kind of like the Inline element but special). That way, you could include it in the middle of your Paragraph as you're building it. On my end, I think it would be equivalent to
I might try toying with this idea over the next couple days, but I need to think about how best to implement it. It might be as easy as adding an additional parameter to Inline, but that element is already a bit of a mess. |
Okay, I did a bit of toying around. I'm thinking I might just hardcode the HTML element. After all, the Paragraph object is going to strip the newline anyway. I could potentially remove the stripping, but I worry about what effects that might have on existing codebases. |
Alright, let me know if this is the behavior you wanted: def test_paragraph_with_linebreak():
paragraph = Paragraph([
Inline("First Line", linebreak=True),
Inline("Second Line")
])
assert str(paragraph) == "First Line<br>Second Line" If so, I will update the version and push this out. All other tests still pass. |
I'm with you about that there is no a standard way to implement the break line.
Another option can be to follow the rule of double space plus return carriage. In this case when you render the Inline content you set a new placeholder that will be replaced after the join paragraph with split. Indeed in situation where markdown admit more than one possible way, in my opinion would be very useful a global option settings where the user decide which strategy to use for the final rendering. |
Okay, in the short term, I'm going to keep the html tag version for now. In the long term, I'll have to figure out a workaround/redesign. |
In terms of which tag to use, it seems hotly debated. I'll see it to whatever your preference is: https://stackoverflow.com/questions/1946426/html-5-is-it-br-br-or-br. My preference is for |
About the tag I think it's a good choice. Consider that allowing the final user with a feature like global options settings you could ignore all of this kind of doubts delegating any further customization. |
Yeah, I think that would be great! Something I can chip away at over time. |
I came across a problem in rendering a paragraph as I wanted because of line breaks.
I'm aware of this link but in my case it cannot solve the problem due to the not known a priori content.
In my case I know I encounter a line break but I don't know how to insert it into the building document that is creating a paragraph.
At the moment I'm unable to render correctly something like this:
The first two lines are part of the same paragraph and are rendered as explained before.
Unfortunately due to paragraph block item str method any return carriage is replaced by the split.
The result is something like this:
In my opinion should be added an inline elements that during the str method will add a special tag that will be replaced after the call
return " ".join(paragraph.split())
in elements.py
What do you think?
The text was updated successfully, but these errors were encountered: