Comments (9)
Hello @cainianhua, thanks for your report.
I'm not sure I got your problem right. Can you describe it with some code examples please?
For me the following looks like the expected behavior:
> ReverseMarkdown.convert 'foo-bar' => "foo-bar\n\n"
> ReverseMarkdown.convert '<li>foo-bar</li>' => "- foo-bar\n"
Don't you agree?
from reverse_markdown.
Sorry for that, i lost a important condition, Hyphen(-) should be in the beginning, like that:
ReverseMarkdown.convert('-test') #=> -test\n
I expected the result should be \\-test\n
in this case, otherwise, it will show in page like this:
<ul>
<li>test</li>
</ul>
But I only want to show as original value, like that:
-test
Thanks for your helps.
from reverse_markdown.
@cainianhua That sounds more like a problem of the markdown implementation you're using. In Redcarpet (a very common ruby implementation) the following works quite like expected:
irb(main):004:0> Redcarpet::Markdown.new(Redcarpet::Render::HTML).render('-test')
=> "<p>-test</p>\n"
from reverse_markdown.
Maybe you misunderstood my meanings, the codes you showed is making markdown to html.
Actually, I just have a html fragment, like this:
<div><p>-test</p></div>
It displays the words of -test
in screen.
After called convert
to markdown:
ReverseMarkdown.convert('<div><p>-test</p></div>') #=> -test\n\n
It will display as list, like that:
<ul>
<li>test</li>
</ul>
Not the words of -test
, they are not equivalent, I only want to show this case, not sure is a problem/issue.
from reverse_markdown.
Hello @cainianhua
I understand your example, but I think you're jumping to the wrong conclusion.
Which markdown converter do you use to transform -test\n\n
back into HTML?
In Redcarpet (https://github.com/vmg/redcarpet) the result would be what you expected: <p>-test</p>\n
I think the markdown converter you're using has a bug and shouldn't create a list from the given string.
Do you agree with my analysis or am I missing something?
from reverse_markdown.
Test string should be <div><p>- test</p></div>
(with a space between -
& test
). This issue makes perfect sense to me.
from reverse_markdown.
Hi @sdhull,
please let me know what the expected result for the input you provided is.
You won't be able to get the exact HTML that you provided in a full round trip though. The <div>
will always be lost, because markdown has no representation for it.
So from my point of view this conversion looks OK:
ReverseMarkdown.convert "<div><p>- test</p></div>"
=> "- test\n\n"
If the HTML contains markdown formatted content, like in this example the list item, this content will inevitably be transformed at some point.
Even if we managed to spot those cases and escape them, markdown renderers would not care anyway:
md.render "\- foobar" # use redcarpet
=> "<ul>\n<li>foobar</li>\n</ul>\n"
from reverse_markdown.
Ohhh I see. Well in that case, I'd suggest closing this issue.
It might be worth adding a "Limitations" section to the readme pointing out that if the HTML you're converting to markdown has markdown-formatted text (text that would be interpreted by markdown parsers as lists, headers, hr's, etc), then a "roundtrip" (eg converting from html to markdown back to html) will inevitably produce a different result than what you started with.
On a somewhat related tangential note, I'd love to be able to turn off escaping of node text altogether (considering it only escapes *
& _
, it cannot be considered complete and as you point out -- redcarpet ignores escaping in some circumstances anyway). But that's another issue. I could submit a PR for it even.
from reverse_markdown.
@sdhull Sounds good, I'd be happy to merge any PR to improve documentation.
from reverse_markdown.
Related Issues (20)
- [Question] How to change \n by </br> ?
- Process footnotes
- HTML string containing underscores gets escaped and shown in output markdown HOT 11
- tag_border option is being ignored. HOT 3
- Blockquote not correctly closed HOT 1
- Improper space parsing within codeblock HOT 2
- Raise on character encoding errors HOT 2
- no new line char in code inside <pre> tag HOT 1
- Links to ids don't produce Markdown links HOT 3
- Github tables without a header row HOT 3
- Slack flavored Markdown HOT 6
- Too much blankspace gets stripped HOT 1
- Unwanted new line characters within lists with paragraphs HOT 1
- Consider changing the license to something listed on Open Source Initiative list of approved licenses HOT 2
- Doesn't handle <br><br> within <strong></strong> HOT 1
- Incorrect markdown from adjacent strong tags with non-strong text after
- Incorrect markdown with non-breaking space before </i>
- Add option to convert HTML entities such as to space or unicode non-breaking space HOT 1
- Untidy tags produce invalid Markdown HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reverse_markdown.