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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion frontend_tests/node_tests/echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ var bugdown_data = JSON.parse(fs.readFileSync(path.join(__dirname, '../../zerver
{input: 'This is an !avatar(cordelia@zulip.com) of Cordelia Lear',
expected: '<p>This is an <img alt="cordelia@zulip.com" class="message_body_gravatar" src="/avatar/cordelia@zulip.com?s=30" title="cordelia@zulip.com"> of Cordelia Lear</p>'},
{input: 'This is a !gravatar(cordelia@zulip.com) of Cordelia Lear',
expected: '<p>This is a <img alt="cordelia@zulip.com" class="message_body_gravatar" src="/avatar/cordelia@zulip.com?s=30" title="cordelia@zulip.com"> of Cordelia Lear</p>'}
expected: '<p>This is a <img alt="cordelia@zulip.com" class="message_body_gravatar" src="/avatar/cordelia@zulip.com?s=30" title="cordelia@zulip.com"> of Cordelia Lear</p>'},
{input: 'Test *italic*',
expected: '<p>Test <em>italic</em></p>'}
];

test_cases.forEach(function (test_case) {
Expand Down
10 changes: 8 additions & 2 deletions static/js/echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,17 @@ $(function () {
disable_markdown_regex(marked.Lexer.rules.tables, 'heading');
disable_markdown_regex(marked.Lexer.rules.tables, 'lheading');

// Disable __strong__, all <em>
// Disable __strong__
marked.InlineLexer.rules.zulip.strong = /^\*\*([\s\S]+?)\*\*(?!\*)/;
disable_markdown_regex(marked.InlineLexer.rules.zulip, 'em');

// Make sure <del> syntax matches the backend processor
marked.InlineLexer.rules.zulip.del = /^(?!<\~)\~\~([^~]+)\~\~(?!\~)/;

// Disable _emphasis_
// Text inside ** must start and end with a word character
// it need for things like "const char *x = (char *)y"
marked.InlineLexer.rules.zulip.em = /^\*(?!\s+)((?:\*\*|[\s\S])+?)((?:[\S]))\*(?!\*)/;

// Disable autolink as (a) it is not used in our backend and (b) it interferes with @mentions
disable_markdown_regex(marked.InlineLexer.rules.zulip, 'autolink');

Expand Down
2 changes: 1 addition & 1 deletion static/third/marked/lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ InlineLexer.prototype.output = function(src) {
// em
if (cap = this.rules.em.exec(src)) {
src = src.substring(cap[0].length);
out += this.renderer.em(this.output(cap[2] || cap[1]));
out += this.renderer.em(cap[1] + cap[2]);
continue;
}

Expand Down
16 changes: 14 additions & 2 deletions zerver/fixtures/bugdown-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,21 @@
"bugdown_matches_marked": true
},
{
"name": "star_disabled",
"name": "emphasis_text",
"input": "*foo*",
"expected_output": "<p>*foo*</p>",
"expected_output": "<p><em>foo</em></p>",
"bugdown_matches_marked": true
},
{
"name": "emphasis_code",
"input": "const char *x = (char *)y",
"expected_output": "<p>const char *x = (char *)y</p>",
"bugdown_matches_marked": true
},
{
"name": "emphasis_with_space",
"input": "*foo bar*",
"expected_output": "<p><em>foo bar</em></p>",
"bugdown_matches_marked": true
},
{
Expand Down
7 changes: 7 additions & 0 deletions zerver/lib/bugdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,13 @@ def extendMarkdown(self, md, md_globals):
markdown.inlinepatterns.SimpleTagPattern(r'(?<!~)(\~\~)([^~{0}\n]+?)\2(?!~)', 'del'),
'>strong')

# Text inside ** must start and end with a word character
# it need for things like "const char *x = (char *)y"
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?

'emphasis',
markdown.inlinepatterns.SimpleTagPattern(r'(\*)(?!\s+)([^\*^\n]+)(?<!\s)\*', 'em'),
'>strong')

for k in ('hashheader', 'setextheader', 'olist', 'ulist'):
del md.parser.blockprocessors[k]

Expand Down
1 change: 1 addition & 0 deletions zerver/tests/test_bugdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ def test_mit_rendering(self):
'<p><a href="https://lists.debian.org/debian-ctte/2014/02/msg00173.html" target="_blank" title="https://lists.debian.org/debian-ctte/2014/02/msg00173.html">https://lists.debian.org/debian-ctte/2014/02/msg00173.html</a></p>',
)


class BugdownApiTests(ZulipTestCase):
def test_render_message_api(self):
# type: () -> None
Expand Down