Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

TigorC
Copy link
Contributor

@TigorC TigorC commented Oct 24, 2016

This closes #1103

Copy link
Sponsor Member

@timabbott timabbott left a 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'),
Copy link
Sponsor Member

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;
}

Copy link
Sponsor Member

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>")
Copy link
Sponsor Member

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(
Copy link
Sponsor Member

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?

disable_markdown_regex(marked.InlineLexer.rules.zulip, 'em');

// Disable _emphasis_
marked.InlineLexer.rules.zulip.em = /^\*((?:\*\*|[\w|\ |\t])+?)\*(?!\*)/;
Copy link
Sponsor Member

@timabbott timabbott Nov 7, 2016

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added comment

@timabbott
Copy link
Sponsor Member

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])+?)\*(?!\*)/;
Copy link
Sponsor Member

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@timabbott
Copy link
Sponsor Member

Merged (after squashing, since the first commit along fails the frontend tests), thanks @TigorC!

@timabbott timabbott closed this Nov 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for italics to bugdown
2 participants