What's an example of some invalid markdown?

2019-02-12 07:57发布

问题:

I'm writing unit tests for a model with an attribute that's interpreted as markdown. I'd like to test that if the markdown is invalid, then the object is invalid - but it's such a forgiving syntax that everything I've tried so far turns out to be valid markdown! What's an example of some invalid markdown?

回答1:

I haven't used markdown extensively but i was under the impression that it is impossible to write "invalid" markdown only markdown that wont do what you want it to. As in instead of throwing an error when it doesn't know what to do it just treats it as plain text.

On a different path one could probably write a script to try and identify things that the user probably didn't intend, for example if someone entered **test* they probably intended *test* or **test**



回答2:

All strings are valid markdown.



回答3:

If all text is markdown and vice versa, then I suppose one example of invalid markdown would be invalid text in the encoding that you are using, i.e. invalid UTF-8, invalid ASCII or invalid ISO-8859-1.