After < , all the text is hidden


(Kasper Peulen) #1

I’m not sure if this is a bug, or that this meant to be like this. But everytime I write this symbol: <, all the text after it will hide. This doesn’t happen in the preview. But after I post and refresh, this happens. < checking if this text is hidden


(Sam Saffron) #2

Not really a bug, this is the way markdown works, we could possibly build a workaround, however this is the spec,

For example, this
<it>thinks it is a tag</it>

Renders as:

thinks it is a tag


(Kasper Peulen) #3

@sam Ah, I understand that now. But in this way it is not possible to use this symbol with the meaning '… less than … '. I use discourse as a mathforum, so this gives some problems. Maybe it could be handled the same way as stackoverflow does this ?


(David Celis) #4

Perhaps escaping the < with a backslash will work?

EDIT: hah, apparently not. But you should be able to freely use characters like that if you preformat the text:

I'm using some < characters alright.

Or outside of a block you can make a < with backticks


(Simon) #5

Wouldn’t it be possible to automatically escape those characters if they don’t form valid HTML/markdown? There has to be some whitelist of allowed HTML tags somewhere, so if the parser encounters an unknown/not whitelisted “tag” it could just encode it as plain text using HTML entities.

So the parser would turn <it>thinks it is a tag</it> into &lt;it&gt;thinks it is a tag&lt;/it&gt;, while <em>italic</em> would be left untouched (if <em> is whitelisted). So any unclosed tag or invalid syntax would just show as is instead of being removed.

(Before anyone asks, I am not a ruby/js programmer, so I can’t really help coding this)


(Sam Saffron) #6

It is technically possible, but gets complicated and is a violation of the markdown spec (not that it really matters)

@eviltrout


(Paolo G. Giarrusso) #7

That part would be a bug in the preview, wouldn’t it? But I can’t reproduce that.


(Paolo G. Giarrusso) #8

Well, that’s extremely ugly - and you’re supposed to use preformatted text only where it makes sense.
Luckily, you can use < for escaping. However, how are you supposed to discover that? I suspect we have a usability problem.


(egid) #9

I’m not sure that’s a correct statement - markdown should only be parsing as HTML if it sees a closing tag. Try out the markdown dingus to see what I mean. 5 > 3 or 3 < 5 should be interpreted by markdown as such, and shown as 5 > 3 or 3 < 5.

Where in the spec does it say that an open < should be treated as HTML?


(Paolo G. Giarrusso) #10

I suspect many target users know neither BBCode nor Markdown. Two options here would be:

  • allow plain text editing, which everybody can use safely.
  • allow WYSIWYG editing, where you can only format through interface buttons (or accelerators) and all the text you type is automatically escaped, if need be.
  • Of course, this only works if you manage to get it right, unlike most horribly buggy WYSIWYG forum editors. I hear even Wikipedia has its fair share of problems with MediaWiki’s beta visual editor.

(egid) #11

Maybe the solution is that users are prompted to choose their syntax at first or second post, and then that’s their default - from then on, that’s the content format that the input handles, and it’s a toggle-able thing.

I mean, I would imagine that having a hybrid BBcode+Markdown input field is problematic, but I haven’t dug around under the hood to see what Discourse is doing.


(Sam Saffron) #12

1 > 2 and 2 < 1 work fine. the issue is < followed directly with a letter


(Sam Saffron) #13

1 > 2 and 2 < 1 work fine. the issue is < followed directly with a letter.

@eviltrout the above definitely looks like a bug in prettytext , will have a look today


(Paolo G. Giarrusso) #14

That looked scary to me as well. Quite apparently, I can totally mix BBCode (this is BBCode bold) and Markdown (this is Markdown bold), yet I see no link to a syntax reference for this new hybrid or for either syntax. Do the two syntaxes work together without issues just so?

OTOH, the above quote uses BBCode and standard Markdown cannot represent all the information.


(Jeff Atwood) #15

Agreed, the only time you should see problems is if you have < and then > on the same line somehow. But trivially:

x > 1

should work

x < 1

should also work (but doesn’t, x < 1). So this is a bug, and will definitely hurt the maths.

edit: now it works!


(Kasper Peulen) #16

In my case, I was typing |x-a|<δ. In the preview this looks right. But after posting and refreshing the δ disappears.

I tested it out a little bit. And this also happesn with x < 1. This also looks good in the preview. With x<1, the 1 disappears both after refreshing and in the preview.


(Robin Ward) #17

I suspect it’s our ruby sanitizer if it only happens on save. Will look into it.


(Kasper Peulen) #18

In the preview it works almost as I would suspect, but also in the preview: < followed by a number gives issues, while I would suspect that this only happens when < is followed by a letter.

It would be even better if there are only issues if you have < and then > on the same line somehow. (as codinghorror says)


(Robin Ward) #19

I’ve confirmed that it’s a problem with the sanitize gem. I’ve opened an issue on Github with a failing example. Hopefully we can get it fixed:

https://github.com/rgrove/sanitize/issues/83


(Kasper Peulen) #20

According to the author of Sanitize: [quote=“Ryan Grove”]
The root of the issue is that “1 > 2 and 2 < 1” simply isn’t syntactically valid HTML.
[/quote]

Another solution may be to convert all the < to &lt; if the < isn’t followed by a letter, before the code is passed to Sanitize. In this way you would pass valid html to Sanitize, and Sanitize wouldn’t have to remove anything to make the html valid.