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
Added support for italics to bugdown #2107
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks for working on this @TigorC! I posted several comments. See http://learnhtmlwithsong.com/blog/07-1-use-italics-use-emphasis/ for why <em>
is preferred over <i>
.
@@ -978,6 +978,11 @@ def extendMarkdown(self, md, md_globals): | |||
markdown.inlinepatterns.SimpleTagPattern(r'(\*\*)([^\n]+?)\2', 'strong'), | |||
'>not_strong') | |||
|
|||
md.inlinePatterns.add( | |||
'italic', | |||
markdown.inlinepatterns.SimpleTagPattern(r'(\*)([\w|\ |\t]+)\*', 'i'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment explaining the intended behavior and why this regular expression is correct?
out += this.renderer.italic(this.output(cap[1])); | ||
continue; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a check: Would using the em
logic in the next block work instead? I think technically in markdown it's supposed to do <em>
, so maybe we don't need to add this code but just should be adjusting the above.
converted = bugdown.convert(msg) | ||
self.assertEqual( | ||
converted, | ||
"<ul>\n<li>item1</li>\n<li>item2</li>\n</ul>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just put these tests in bugdown-data.json
so we can test with both markdown processors?
@@ -978,6 +978,11 @@ def extendMarkdown(self, md, md_globals): | |||
markdown.inlinepatterns.SimpleTagPattern(r'(\*\*)([^\n]+?)\2', 'strong'), | |||
'>not_strong') | |||
|
|||
md.inlinePatterns.add( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be called emphasis
instead?
efee6a8
to
16bc927
Compare
disable_markdown_regex(marked.InlineLexer.rules.zulip, 'em'); | ||
|
||
// Disable _emphasis_ | ||
marked.InlineLexer.rules.zulip.em = /^\*((?:\*\*|[\w|\ |\t])+?)\*(?!\*)/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain how this change works (maybe in an extended comment? I don't think it's at all clear from this why we're changing the regular expression in this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added comment
16bc927
to
08df703
Compare
Can you rebase? I just merged the strikethrough support. |
// Disable special characters for the emphasis syntax | ||
// Inside ** allowed only: word characters/spaces/tabulate | ||
// it need for things like "const char *x = (char *)y" | ||
marked.InlineLexer.rules.zulip.em = /^\*((?:\*\*|[\w|\ |\t])+?)\*(?!\*)/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this regular expression different from the one in bugdown/init.py? It seems like we want to use the same regular expressions in the two places.
Also, why are you limiting the characters inside in any way other than forbidding *
and \n
and controlling how we handle whitespace; what I had in mind was just require that the character after the first *
is a non-whitespace character and the character before the second star is a non-whitespace character. So *foo bar*
would be italics but * foo bar*
and similar things would not be; that covers the const char *x = (char *)y
issue fine (since the second *
has a space in it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
08df703
to
b88126e
Compare
Merged (after squashing, since the first commit along fails the frontend tests), thanks @TigorC! |
This closes #1103